Created
August 18, 2011 12:55
-
-
Save nihen/1154007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# 安全なウェブアプリケーションの作り方 P156のリファラチェックには若干の脆弱性あり | |
$http_referer ='http://example.jp/45/45-002ch.php'; | |
# もちろんこれはOK | |
if ( preg_match('#\Ahttp://example.jp/45/45-002ch.php#', $http_referer) ) { | |
echo "ok\n"; | |
} | |
else { | |
echo "ng\n"; | |
} | |
$http_referer ='http://examplesjp/45/45-002ch.php'; | |
# これはNGになってほしいが、OKになってしまう | |
if ( preg_match('#\Ahttp://example.jp/45/45-002ch.php#', $http_referer) ) { | |
echo "ok\n"; | |
} | |
else { | |
echo "ng\n"; | |
} | |
# \Q\EでかこってあげるとNGになる | |
if ( preg_match('#\A\Qhttp://example.jp/45/45-002ch.php\E#', $http_referer) ) { | |
echo "ok\n"; | |
} | |
else { | |
echo "ng\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment