-
-
Save theMiddleBlue/bd06e56aac9885266fb916200514d534 to your computer and use it in GitHub Desktop.
Python re.match() Input Validation Bypass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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