php security for location header injection via $_GET

后端 未结 4 1968
有刺的猬
有刺的猬 2021-01-20 15:24

I\'ve got this code on my page:

header(\"Location: $page\");

$page is passed to the script as a GET variable, do I need any security? (if so what)

<
4条回答
  •  生来不讨喜
    2021-01-20 15:49

    I could forward your users anywhere I like if I get them to click a link, which is definitely a big security flaw (Please login on www.yoursite.com?page=badsite.com). Now think of a scenario where badsite.com looks exactly like your site, except that it catches your user's credentials.

    You're better off defining a $urls array in your code and passing only the index to an entry in that array, for example:

    $urls = array(
        'pageName1' => '/link/to/page/number/1',
        'pageNumber2' => '/link/to/page/number/2',
        'fancyPageName3' => '/link/to/page/number/3',
    );
    # Now your URL can look like this:
    # www.yoursite.com?page=pageName1
    

提交回复
热议问题