-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Cheroot incorrectly allows whitespace after header names #714
Comments
Hi, are you able to come up with a Cheroot-only reproducer? By the way, we have |
Yes. I can reproduce this on a fresh build from
from base64 import b64encode
from cheroot.wsgi import Server, PathInfoDispatcher as WSGIPathInfoDispatcher
RESERVED_HEADERS = ("CONTENT_LENGTH", "CONTENT_TYPE")
def app(environ, start_response) -> list[bytes]:
try:
body: bytes = environ["wsgi.input"].read()
except ValueError:
start_response("400 Bad Request", [])
return []
response_body: bytes = (
b'{"headers":['
+ b",".join(
b'["'
+ b64encode(k.encode("latin1")[len("HTTP_") if k not in RESERVED_HEADERS else 0 :])
+ b'","'
+ b64encode(environ[k].encode("latin1"))
+ b'"]'
for k in environ
if k.startswith("HTTP_") or k in RESERVED_HEADERS
)
+ b'],"body":"'
+ b64encode(body)
+ b'","version":"'
+ b64encode(environ["SERVER_PROTOCOL"].encode("latin1"))
+ b'","uri":"'
+ b64encode(
(
environ["PATH_INFO"] + (("?" + environ["QUERY_STRING"]) if environ["QUERY_STRING"] else "")
).encode("latin1")
)
+ b'","method":"'
+ b64encode(environ["REQUEST_METHOD"].encode("latin1"))
+ b'"}'
)
start_response(
"200 OK", [("Content-type", "application/json"), ("Content-Length", f"{len(response_body)}")]
)
return [response_body]
Server(("0.0.0.0", 80), WSGIPathInfoDispatcher({"/": app})).start()
printf Q09OVEVOVF9MRU5HVEg= | base64 -d | xxd
Will do for next time. |
β I'm submitting a ...
π Describe the bug. What is the current behavior?
Cheroot incorrectly strips whitespace from the ends of header names.
β What is the motivation / use case for changing the behavior?
This behavior violates the RFCs and is potentially useful for launching request smuggling attacks.
π‘ To Reproduce
Steps to reproduce the behavior:
GET / HTTP/1.1\r\nHost: whatever\r\nContent-Length : 1\r\n\r\nZ
Z
, even though theContent-Length
header name is followed by a space.π‘ Expected behavior
A 400 response.
π Environment
The text was updated successfully, but these errors were encountered: