Skip to content

Instantly share code, notes, and snippets.

@ts0818
Last active November 5, 2015 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ts0818/539e254a0206feeaed92 to your computer and use it in GitHub Desktop.
Save ts0818/539e254a0206feeaed92 to your computer and use it in GitHub Desktop.
パーフェクトPHP ディレクトリトラバーサル対応方法 ホワイトリスト方式
<?php
if (isset($_GET['file']) === true && $_GET['file'] !== '') {
// 指定されたファイルがfile1かfile2でなければ処理終了
if (! in_array($_GET['file'], array('file1', 'file2'))) {
exit();
}
// GET変数で指定されたファイルが /var/www/html に存在すれば内容を出力
$file = '/var/www/html/' . $_GET['file'];
if (file_exists($file) === true) {
readfile($file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment