Jump to content

Recommended Posts

Hey all. I have a question or two about securing pages that use $_GET method.  $_POST I have a good grasp on but $_GET has some different issues.

 

If I have a switch that calls on the url to display a proper page, do I need to sanitize that variable before passing it to the switch?

 

Example:

 

URL = www.example.com/index.php?page=calendar

 

// see comments

$url = $_GET['page'];

// Is this $url variable safe in my script or is there needed sanitation?
switch ($url)
{
case "calendar":
	include "views/calendar.php";
	break;
default:
	include "views/main.php";
}

 

I was reading about XSS and I had some questions. Can someone just pass a function to the url like mail() and start sending mail from my web page in the above example or steal cookies or anything else? I'm referring to my example above.

 

Is there any good reading around on the topic of $_GET and security?

 

Cheers all!

 

Link to comment
https://forums.phpfreaks.com/topic/218481-_get-method-security/
Share on other sites

All external data, $_GET, $_POST, $_COOKIE, $_FILES, and some $_SERVER variables, can contain ANYTHING and must be validated.

 

By using a SWITCH/CASE statement, you are validating that the value is only one of the choices you have listed in the CASE statements.

 

IF you were putting the value into a string to form a file name/file path to use in the include statement and the value has not been validated, someone can cause your code to include any file on your server and if the php.ini settings that permit URL's to be used in the include statement are ON, remote code can be included and executed on your server. Since the code you posted is NOT doing this, that code is safe and will only include the file that you have listed in the code.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.