Files
codeql/python/ql/test/experimental/query-tests/Security-new-dataflow/CWE-022/test.py
Rasmus Lerchedahl Petersen 022cf0b2cc Python: Add test from tracking issue
All tests pass, but there are spurious paths
due to configuration chaining.
2020-10-24 09:07:43 +02:00

50 lines
768 B
Python

import os.path
from flask import Flask, request
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) # NOT OK
@app.route("/path")
def normalization():
x = source()
y = normalize(x)
open(y) # NOT OK
@app.route("/path")
def check():
x = source()
if x.startswith("subfolder/"):
open(x) # NOT OK
@app.route("/path")
def normalize_then_check():
x = source()
y = normalize(x)
if y.startswith("subfolder/"):
open(y) # OK
@app.route("/path")
def check_then_normalize():
x = source()
if x.startswith("subfolder/"):
y = normalize(x)
open(y) # NOT OK