Does PHP's $_REQUEST method have a security problem?

后端 未结 7 1584
醉酒成梦
醉酒成梦 2020-12-03 07:51

The textbook I read says that $_REQUEST has security problem so we better use $_POST.

Is this OK?

相关标签:
7条回答
  • 2020-12-03 08:12

    I would say that it is dangerous to characterise $_POST as more secure than $_REQUEST.

    If the data is not being validated and sanitized before being used, you have a possible vector of attack.

    In short: It doesn't matter where the data comes from if it is not being handled in a secure manner.

    0 讨论(0)
  • 2020-12-03 08:12

    There's no real security difference between using $_POST and $_REQUEST, you should sanitise the data with equal scrutiny.

    The biggest problem with $_REQUEST is you may be trying to get data from a POST'd form, but might have a GET parameter with the same name. Where will the data come from? It's best to explicitly request the data from where you expect it, $_POST in that example

    There are slight security benefits - it's easier to perform XSS (more specifically XSRF) attacks on GET parameters, which is possible if you use $_REQUEST, when you really just want POST data..

    There's very few situations when you need data either from POST, GET or cookie.. If you want to get POST data, use $_POST, if you want to get data from from GET parameters, use $_GET, if you want cookie data, use $_COOKIE

    0 讨论(0)
  • 2020-12-03 08:18

    Well, the reason that $_REQUEST has issues is that it picks up values from $_GET, $_POST, and $_COOKIE, which means that if you code things certain ways and make certain invalid trusting-the-client assumptions, a malicious user could take advantage of that by supplying a value in a different place than you expected and overriding the one you were trying to pass.

    This also means that you may have given your henchman incorrect instructions, because it may have been a GET or COOKIE value that he was picking up from $_REQUEST. You would need to use whatever place the value you're looking for actually shows up, not necessarily $_POST.

    0 讨论(0)
  • 2020-12-03 08:21

    @Christian:

    When talking about some of them being more dangerous than others I would indeed separate $_GET and $_REQUEST (as it includes $_GET) out from $_POST, as it is slightly harder to generate, i.e. manipulate, a POST request than a GET request. The emphasis here is slightly, but using POST for sensitive operations at least removes another layer of low hanging fruits to exploit.

    Bzzt. Sorry, but this just ain't true.

    Anybody who understands the difference between GET and POST or how unsanitized inputs might be exploitable, won't hesitate for a second to fire up Tamper Data.

    Some people have it right here: there is NO security lost or gained by using $_REQUEST in a well-designed system.

    0 讨论(0)
  • 2020-12-03 08:23

    It's certainly okay to tell people to use $_POST instead of $_REQUEST. It is always better to be more sure about where your getting your data.

    0 讨论(0)
  • 2020-12-03 08:26

    The most secure way is to verify and validate the data. I usually generate a random unique id for a form and store it in the user's session, but this is easily bypassed by a determined attacker. Much better is to clean up all incoming data. Check out htmlspecialchars() and its related function. I also use a third party utility for cross-site, like HTML Purfier

    On some practical notes, always use intval() what is supposed to be numeric, escape all incoming strings, use regex for phone numbers, emails or anything that is going to be part of a SQL query.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题