Skip to content

Instantly share code, notes, and snippets.

@nihen
Created August 18, 2011 12:55
Show Gist options
  • Save nihen/1154007 to your computer and use it in GitHub Desktop.
Save nihen/1154007 to your computer and use it in GitHub Desktop.
<?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