Files
codeql/python/ql/test/query-tests/Security/CWE-022-PathInjection/test.py
Owen Mansel-Chan 5a97348e78 python: Inline expectation should have space after $
This was a regex-find-replace from `# \$(?! )` (using a negative lookahead) to `# $ `.
2026-03-04 12:45:05 +00:00

50 lines
792 B
Python

import os.path
from flask import Flask, request # $ Source
app = Flask(__name__)
def source():
return request.args.get("path", "")
def normalize(x):
return os.path.normpath(x)
@app.route("/path")
def simple():
x = source()
open(x) # $ Alert
@app.route("/path")
def normalization():
x = source()
y = normalize(x)
open(y) # $ Alert
@app.route("/path")
def check():
x = source()
if x.startswith("subfolder/"):
open(x) # $ Alert
@app.route("/path")
def normalize_then_check():
x = source()
y = normalize(x)
if y.startswith("subfolder/"):
open(y) # $ result=OK
@app.route("/path")
def check_then_normalize():
x = source()
if x.startswith("subfolder/"):
y = normalize(x)
open(y) # $ Alert