Skip to content

Request not closed with Unicode characters in headers #2833

@kevin-mizu

Description

@kevin-mizu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions