パス操作とリソース挿入
パス操作とリソース挿入
概要
パス操作は、利用者入力がファイルパスやリソース識別子を制御すると発生します。
影響
攻撃者は任意ファイルの読み取り、リソースの上書き、制限データへのアクセスを行う可能性があります。
対策
パスを正規化し、リソース名の許可リストを使い、トラバーサル文字列を拒否し、解決後のパスにアクセス制御を適用します。
例
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
String filepath = request.getParameter("filepath");
if (filepath == null)
return;
filepath= PathUtil.getHome() + "/web/board_attach/" + filepath;
DownloadUtil.download(response, filepath);
}
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
String filepath =request.getParameter("filepath");
if (filepath == null)
return;
filepath = filepath.replaceAll("/","");
filepath = filepath.replaceAll ("\\\\","");
filepath = filepath.replaceAll ("\\.","");
filepath = filepath.replaceAll ("&","");
filepath = PathUtil.getHome() + "/web/board_attach/" + filepath;
DownloadUtil.download(response, filepath);
}