is $_SERVER['HTTP_REFERER'] safe?

后端 未结 3 1932
滥情空心
滥情空心 2020-12-03 21:19

I\'m using $_SERVER[\'HTTP_REFERER\'] to generate a dynamic back link.

\">Return to..blah         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-03 22:16

    It may be safe, but it is not reliable: due to the HTTP spec, HTTP_REFERER is optional (some clients don't send this header at all, and some "security" software strips this out from any HTTP request), and there are numerous ways to modify this header. Some browsers send the referring page, some send a blank string, some don't send this at all, some may send bogus data, some may send Aunt Matilda; and moreover, you can't tell whether you're getting valid data in this header or not.

    So, no, I would never trust that HTTP_REFERER contains the previous page, and neither should you.

提交回复
热议问题