Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow performance parsing certain Content-Type: application/x-www-form-urlencoded headers #2904

Open
aneshujevic opened this issue May 17, 2024 · 1 comment

Comments

@aneshujevic
Copy link

aneshujevic commented May 17, 2024

Slow performance has been affecting parsing headers in requests with
Content-Type: application/x-www-form-urlencoded header, when trying to parse the form submitted.

Having minimal application which parses form from request like this:

from flask import Flask, request

app = Flask(__name__)

@app.post("/submit")
def submit():
    return {"username": request.form["username"]}

if __name__ == "__main__":
    app.run()

making a request with specially crafted headers like this:

curl -v -X 'POST' -H $'Content-Type: application/x-www-form-urlencoded; !=\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' --data-binary 'username=test' 'http://127.0.0.1:5000/submit'

would cause excessive load and making workers timeout.

The request should've been parsed without overloading the worker and extracted the form arguments as usual.

I'm planning to make a PR which should fix this issue.

Environment:

  • Python version: latest
  • Werkzeug version: latest
@davidism davidism changed the title ReDoS while parsing headers in Content-Type: application/x-www-form-urlencoded requests Slow performance parsing certain Content-Type: application/x-www-form-urlencoded headers May 17, 2024
@davidism
Copy link
Member

Thank you, happy to review the PR when it's in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants