Bad Bad Theme: Fail with file_get_contents()

This one is so dangerous it’s almost awesome.

header('Content-Type: text/xml'); 
$url = $_GET['url']; 
$data = file_get_contents($url); 
echo $data; 

The code is blindly accepting anything that is posted via the url query parameter, making it possible for someone to inject just about any code they wished by simply passing it in the URL.

Submitted by Stephanie Leary.

Advertisements

6 thoughts on “Bad Bad Theme: Fail with file_get_contents()

    • I am when I can. Sometimes it will be in the form of simply linking to a tutorial, sometimes it’s just an explanation of why it’s bad. I’m trying to not use this as a tutorial site.

      • I respect that. Another idea: crowd-sourcing “better code” – simply ask people to post their own versions, and then vote on better code (similar to best answers on stackexchange). Or not 🙂 Just a thought 🙂 In any case, thanks for posting those bad snippets, I’m sure everyone can learn something useful for themselves.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s