king.oslo Posted December 1, 2009 Share Posted December 1, 2009 Is this code dangerous? Can the user inject dagerous code in the $_GET variable or anything else? <?php header( 'Location: http://www.example.com/' . $_GET['filename'] ); ?> Thank you for your time, Marius Quote Link to comment https://forums.phpfreaks.com/topic/183586-is-this-code-a-security-issue/ Share on other sites More sharing options...
premiso Posted December 1, 2009 Share Posted December 1, 2009 They can inject code, as far as it being something dangerous it depends on example.com. If their website does not have their get-data filtered. Sure they can inject code and now it looks like your site is trying to exploit the example.com, so they basically get a free probe using your site. I would still filter the GET data just for that reason above, and really it is not too much of an extra step to run strip_tags or use regex to replace certain items. But think about what type of data is going to be in that get getting passed through and filter it to only allow that type (IE if it should be all letters or numbers make sure it is). Quote Link to comment https://forums.phpfreaks.com/topic/183586-is-this-code-a-security-issue/#findComment-969005 Share on other sites More sharing options...
king.oslo Posted December 1, 2009 Author Share Posted December 1, 2009 Thanks, If I strip all non-word characters from $_GET['filename'], would that make it harmless? Thanks, Marius Quote Link to comment https://forums.phpfreaks.com/topic/183586-is-this-code-a-security-issue/#findComment-969139 Share on other sites More sharing options...
mrMarcus Posted December 1, 2009 Share Posted December 1, 2009 if you can strip out all special characters, html tags, etc., then yes, it should be fine. Quote Link to comment https://forums.phpfreaks.com/topic/183586-is-this-code-a-security-issue/#findComment-969191 Share on other sites More sharing options...
king.oslo Posted December 1, 2009 Author Share Posted December 1, 2009 So this should be fine? <?php $filename = $_GET['filename']; $filename = preg_replace('~[^0-9a-zA-Z-_]~', '', $filename); header( 'Location: http://www.example.com/' . $filename ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/183586-is-this-code-a-security-issue/#findComment-969225 Share on other sites More sharing options...
mrMarcus Posted December 1, 2009 Share Posted December 1, 2009 ya, that looks pretty good. Quote Link to comment https://forums.phpfreaks.com/topic/183586-is-this-code-a-security-issue/#findComment-969235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.