Skip to content

Instantly share code, notes, and snippets.

@theMiddleBlue
Created July 24, 2021 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theMiddleBlue/bd06e56aac9885266fb916200514d534 to your computer and use it in GitHub Desktop.
Save theMiddleBlue/bd06e56aac9885266fb916200514d534 to your computer and use it in GitHub Desktop.
Python re.match() Input Validation Bypass
from flask import Flask
from flask import request
import re
app = Flask(__name__)
def is_valid_input(input):
m = re.match(r'.*(["\';=]|select|union|from|where).*', input, re.IGNORECASE)
if m is not None:
return False
return True
@app.route('/news', methods=['GET', 'POST'])
def news():
if request.method == 'POST':
if "id" in request.form:
if "category" in request.form:
if is_valid_input(request.form["id"]) and is_valid_input(request.form["category"]):
return f"OK: {request.form['category']}/{request.form['id']}"
else:
return f"Invalid value: {request.form['category']}/{request.form['id']}", 403
else:
return "No category parameter sent."
else:
return "No id parameter sent."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment