Information disclosure via filesystem existence oracle in web_main.py catch-all route

オープン 初心者向け
#1,112 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@0x5t4l1n がすでに取り組んでいます。

2026年10月5日 から。

  • #1133 @0x5t4l1n による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
flask, python
領域
backend, security

調査の方向性

application/web/web_main.py:747-753 から始めて catch-all のインデックスルートを調査し、その後、static ディレクトリ外の存在するパスと存在しないパスを使って、Flask のテストクライアントで異なるレスポンスを再現します。これらのケースをカバーする回帰テストを追加し、ファイルシステム上の存在を露出させることなく、どちらも意図したレスポンスに一貫して解決されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

@northdpole as discussed in #project-cre.

Summary

The catch-all route that serves the React app answers differently depending on whether a path exists on the server filesystem, so an unauthenticated caller can test for arbitrary paths outside the static directory. File contents do not leak; existence does.

Where

application/web/web_main.py:747-753 (on fbacf559):

@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def index(path: str) -> Any:
    if path != "" and os.path.exists(os.path.join(app.static_folder, path)):
        return send_from_directory(app.static_folder, path)
    else:
        return send_from_directory(app.static_folder, "index.html")

Why it happens

Two functions decide what is in bounds and they disagree.

os.path.join applies no containment check, and Flask's <path:path> converter passes .. through, so the guard resolves paths outside the static root and os.path.exists answers about them truthfully.

send_from_directory does check, through Werkzeug's safe_join, and refuses anything that escapes, raising 404.

The read is therefore blocked. But the two branches return different responses, and that difference is the leak: an existing path takes the first branch and 404s, a missing one falls through and serves index.html with 200.

Reproduction

Flask 3.1.3, Werkzeug 3.1.8, route copied verbatim into a test client:

GET /../../../../etc/passwd                 404   207 bytes   (exists)
GET /../../../../etc/definitely-not-here    200    16 bytes   (does not exist)
GET /../../../../etc/shadow                 404   207 bytes   (exists, unreadable)
GET /../../../../root                       404   207 bytes   (directory, exists)
GET /../../../../home/nonexistentuser       200    16 bytes   (does not exist)

404 means the path exists, 200 means it does not. It reports existence for files the process cannot read, and for directories.

Impact

Low. No file contents are disclosed and there is no read primitive; safe_join holds. What leaks is filesystem structure, to an unauthenticated remote caller: host fingerprinting, which packages are installed, whether particular users, config files or deployment paths exist. Roughly CWE-204, observable response discrepancy, reached through a path-traversal-shaped input.

Suggested fix

Have both branches use the same containment rule:

from werkzeug.security import safe_join

@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def index(path: str) -> Any:
    if path:
        full = safe_join(app.static_folder, path)
        if full is not None and os.path.exists(full):
            return send_from_directory(app.static_folder, path)
    return send_from_directory(app.static_folder, "index.html")

Happy to open a PR with this and a regression test if useful.

主要言語
Python
スター
210
フォーク
167
平均マージ
4日 12時間
マージ済み PR(30日)
28

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OWASP/OpenCRE のほかの issue

OWASP/OpenCRE の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。