note 124618 added to reserved.variables.get
| From: | php at securetech dot com dot au | Date: | Thu, 16 Jan 2020 00:22:39 +0000 |
| Subject: | note 124618 added to reserved.variables.get | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213886@lists.php.net to get a copy of this message | ||
When using $_GET, please consider the security implications of this, as an attacker can post
whatever they want, which gets included into your code, unless you are careful and sanitize it and
check for VALID values, don't just use whatever is returned.
Instead of using this, i would recommend a function, which will return a sanitized version of the
$_GET['variable']
I personally have a function _GET($par, $parType = '')
this means i can swap this into the code for $_GET['variable'] such as
_GET('variable')
the function then checks if the second (optional) parameter has been checked:
if($parType == '')
{
$parType = gettype($par);
}
next, we need to sanitize the string, to ensure no really bad stuff can happen. Check the type to
ensure we filter correct type of data, for example if type is 'email' then:
$return = filter_input(INPUT_GET, $par, FILTER_SANITIZE_EMAIL)
or
case 'int':
$return = filter_input(INPUT_GET, $par, FILTER_SANITIZE_NUMBER_INT);
you can read some good security information on OWASP, but it isn't targetted to PHP.
----
Server IP: 45.112.84.4
Probable Submitter: 38.142.137.34 (proxied: 103.118.122.10)
----
Manual Page -- http://php.net/manual/en/reserved.variables.get.php
Edit -- https://master.php.net/note/edit/124618
Del: integrated -- https://master.php.net/note/delete/124618/integrated
Del: useless -- https://master.php.net/note/delete/124618/useless
Del: bad code -- https://master.php.net/note/delete/124618/bad+code
Del: spam -- https://master.php.net/note/delete/124618/spam
Del: non-english -- https://master.php.net/note/delete/124618/non-english
Del: in docs -- https://master.php.net/note/delete/124618/in+docs
Del: other reasons-- https://master.php.net/note/delete/124618
Reject -- https://master.php.net/note/reject/124618
Search -- https://master.php.net/manage/user-notes.php