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

Request not closed with Unicode characters in headers #2833

Closed
kevin-mizu opened this issue Jan 8, 2024 · 1 comment
Closed

Request not closed with Unicode characters in headers #2833

kevin-mizu opened this issue Jan 8, 2024 · 1 comment
Labels

Comments

@kevin-mizu
Copy link

kevin-mizu commented Jan 8, 2024

When responding with a unicode characters in a header key / value, it results in a UnicodeEncodeError (already known with #742, #1286...), but in addition, it doesn't close the connection, leading to use the body as a new request.

For example:

from flask import Flask, Response
app = Flask(__name__)

@app.route("/")
def index():
    return """<script>
fetch("/bug", { method: "POST", body: "GET /mizu HTTP/1.1\\r\\n\\r\\n" })
</script>"""

@app.route("/bug", methods=["POST", "GET"])
def bug():
    return Response("a", headers={ "x": "x\uffffx" })

app.run("0.0.0.0", 5000)

This will results in:

poc.png

This comes from here > here > here. Because headers sending has already started when the error occurs, it will stop generating the response without reaching Connection: close and self.end_headers().

Environment:

  • Python version: 3.9
  • Werkzeug version: 3.0.1
@kevin-mizu kevin-mizu changed the title Request not close with unicode headers Request not closed with Unicode characters in headers Jan 9, 2024
@davidism davidism added the server label May 4, 2024
@davidism
Copy link
Member

davidism commented May 5, 2024

I can't reproduce this issue. Using your application, I only see the first two requests (/ and /bug, but not /mizu). We added stream exhaustion in #2620, perhaps you're not actually testing on 3.0.1 like you've written?

Note that the development server must never be used in production. It is not designed to be particularly secure or robust to invalid use. It is only intended for local development.

@davidism davidism closed this as completed May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants