-
Notifications
You must be signed in to change notification settings - Fork 424
Respond with useful error codes when Content-Length header/s are invalid
#19212
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
Changes from 5 commits
40d60c8
1e8eaa1
27b5918
c3be074
26a2c8f
5cf7b96
85d84f5
9c4536b
5f4a097
21b114c
426b676
296ed42
7e86d3d
e8d8a3b
36973e0
3f9af8d
536bf2d
8c594c9
9e2b2a1
e4f2194
c647a0a
d1b0429
7648b3b
72c3ab3
c2b8d2c
5ab4736
7b0b9b2
b2c219e
2a2cd4b
485283c
b095437
b5b4643
e7fe25f
bea38d4
e07fd8b
93f58e6
070356d
525bdbd
adb4359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add HTTP 413 response when incoming request is too large. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,3 +143,37 @@ def test_content_type_multipart(self) -> None: | |
|
|
||
| # we should get a 415 | ||
| self.assertRegex(transport.value().decode(), r"^HTTP/1\.1 415 ") | ||
|
|
||
| def test_content_length_too_large(self) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also have a test for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the best way to write a test for this is.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (test hasn't been added yet)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Perhaps some request with a basic JSON body that will be cut-off and we expect
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After more testing, it seems that Synapse doesn't care if a I can make that change here (to add the assertion).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright - there is a test for this now. I added it in |
||
| """HTTP requests with Content-Length exceeding max size should be rejected with 413""" | ||
| self.hs.start_listening() | ||
|
|
||
| # find the HTTP server which is configured to listen on port 0 | ||
| (port, factory, _backlog, interface) = self.reactor.tcpServers[0] | ||
| self.assertEqual(interface, "::") | ||
| self.assertEqual(port, 0) | ||
|
|
||
| # complete the connection and wire it up to a fake transport | ||
| client_address = IPv6Address("TCP", "::1", 2345) | ||
| protocol = factory.buildProtocol(client_address) | ||
| transport = StringTransport() | ||
| protocol.makeConnection(transport) | ||
|
|
||
| # Send a request with Content-Length header that exceeds the limit. | ||
| # Default max is 50MB (from media max_upload_size), so send something larger. | ||
| oversized_length = 60 * 1024 * 1024 | ||
devonh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| protocol.dataReceived( | ||
| b"POST / HTTP/1.1\r\n" | ||
| b"Connection: close\r\n" | ||
| b"Content-Length: " + str(oversized_length).encode() + b"\r\n" | ||
| b"\r\n" | ||
| ) | ||
| protocol.dataReceived(b"x" * oversized_length) | ||
|
|
||
| # Advance the reactor to process the request | ||
| while not transport.disconnecting: | ||
| self.reactor.advance(1) | ||
|
|
||
| # we should get a 413 Payload Too Large | ||
devonh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| response = transport.value().decode() | ||
| self.assertRegex(response, r"^HTTP/1\.1 413 ") | ||
Uh oh!
There was an error while loading. Please reload this page.