Improved path traversal detection and enhanced sink classification logic

This commit is contained in:
Eli Peter 2026-05-02 03:36:14 -04:00 committed by GitHub
parent 58f1794a4e
commit 3c89bddbf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
56 changed files with 3989 additions and 345 deletions

View file

@ -0,0 +1,19 @@
# py-safe-canonicalise-rooted: os.path.realpath + .startswith with a
# non-literal root variable (an opaque prefix-lock). Combined with
# realpath's dotdot=No proof, is_path_traversal_safe should suppress the
# FILE_IO sink even though the canonicalised path is absolute.
import os
from flask import Flask, request
UPLOAD_ROOT = "/srv/uploads"
app = Flask(__name__)
@app.route("/file")
def file():
name = request.args.get("name", "")
target = os.path.realpath(os.path.join(UPLOAD_ROOT, name))
if not target.startswith(UPLOAD_ROOT):
return "forbidden", 403
with open(target) as f:
return f.read()