Python: Move py/incomplete-hostname-regexp tests to own folder

This commit is contained in:
Rasmus Wriedt Larsen
2021-07-19 16:48:21 +02:00
parent 7939a1372e
commit da021feb8b
3 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1 @@
| hosttest.py:6:27:6:51 | Str | This regular expression has an unescaped '.' before 'example.com', so it might match more hosts than expected. |

View File

@@ -0,0 +1 @@
Security/CWE-020/IncompleteHostnameRegExp.ql

View File

@@ -0,0 +1,23 @@
from flask import Flask, request, redirect
import re
app = Flask(__name__)
UNSAFE_REGEX = re.compile("(www|beta).example.com/")
SAFE_REGEX = re.compile(r"(www|beta)\.example\.com/")
@app.route('/some/path/bad')
def unsafe(request):
target = request.args.get('target', '')
if UNSAFE_REGEX.match(target):
return redirect(target)
@app.route('/some/path/good')
def safe(request):
target = request.args.get('target', '')
if SAFE_REGEX.match(target):
return redirect(target)
# FP reported in https://github.com/github/codeql/issues/3712
# This does not define a regex (but could be used by other code to do so)
escaped = re.escape("https://www.humblebundle.com/home/library")