mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-15 20:05:13 +02:00
Improved path traversal detection and enhanced sink classification logic
This commit is contained in:
parent
58f1794a4e
commit
3c89bddbf2
56 changed files with 3989 additions and 345 deletions
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue