-
Notifications
You must be signed in to change notification settings - Fork 173
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
CompressionLayer: accept-encoding
header parsed incorrectly
#215
Comments
Thanks for the detailed breakdown! |
When I looked at the source code (to see if I can implement a fix), I found another case that is incorrect: Case 5 (fixed by #220)
|
There's another case: Case 6
|
I will work on a fix for this issue. |
* Fix parsing of Accept-Encoding request header * Add unit tests to content_encoding * Represent quality values (qvalues) by a separate type * Parse encodings case-insensitively * Parse qvalues as specified in RFC 7231 section 5.3.1 Refs: #215 * Do not use or-pattern syntax This syntax is not supported in rust 1.51 (the minimum toolchain version). * Add comments to QValue::parse * Remove redundant SupportedEncodingsAll::new function * Add unit tests for all content-encodings (gzip, deflate, br)
Sure. Cases 4 and 6 are currently unresolved. |
* Fix parsing of Accept-Encoding request header * Add unit tests to content_encoding * Represent quality values (qvalues) by a separate type * Parse encodings case-insensitively * Parse qvalues as specified in RFC 7231 section 5.3.1 Refs: #215 * Do not use or-pattern syntax This syntax is not supported in rust 1.51 (the minimum toolchain version). * Add comments to QValue::parse * Remove redundant SupportedEncodingsAll::new function * Add unit tests for all content-encodings (gzip, deflate, br)
* Release 0.2.4 - Added `CatchPanic` middleware which catches panics and converts them into `500 Internal Server` responses ([#214]) [#214]: #214 * Fix parsing of `Accept-Encoding` request header (#220) * Fix parsing of Accept-Encoding request header * Add unit tests to content_encoding * Represent quality values (qvalues) by a separate type * Parse encodings case-insensitively * Parse qvalues as specified in RFC 7231 section 5.3.1 Refs: #215 * Do not use or-pattern syntax This syntax is not supported in rust 1.51 (the minimum toolchain version). * Add comments to QValue::parse * Remove redundant SupportedEncodingsAll::new function * Add unit tests for all content-encodings (gzip, deflate, br) * Update changelog * add changelog groups Co-authored-by: Martin Dickopp <[email protected]>
Another related issue:
tower-http/tower-http/src/compression/predicate.rs Lines 220 to 233 in e8eb549
This means I need to either remove this predicate or not have compression for grpc-web requests |
Bug Report
Version
tower-http v0.2.1
Platform
Debian Linux 12 (“bookworm”)
Linux feynman 5.15.0-3-amd64 #1 SMP Debian 5.15.15-1 (2022-01-18) x86_64 GNU/Linux
rustc 1.58.1 (db9d1b20b 2022-01-20)
Description
When using
CompressionLayer
, theaccept-encoding
header sent by the client is not parsed correctly (i.e., according to RFC 7231, sections 5.3.1 and 5.3.4). The following program demonstrates the issues (using axum v0.4.5):Case 1: Uppercase encodings and qvalues are not parsed (fixed by #220)
Encodings and qvalues are case-insensitive, i.e. the server should understand them whether they are lowercase, uppercase, or a mixture of both.
curl -I -H 'accept-encoding: GZIP' http://127.0.0.1:3000/
curl -I -H 'accept-encoding: gZiP' http://127.0.0.1:3000/
curl -I -H 'accept-encoding: gzip;q=0.5, br;Q=0.8' http://127.0.0.1:3000/
Case 2: Spaces before and after semicolon are not parsed (fixed by #220)
Space and horizontal tab characters are allowed before and after the semicolon separating the encoding from the qvalue.
curl -I -H 'accept-encoding: gzip;q=0.5, br; q=0.8' http://127.0.0.1:3000/
curl -I -H 'accept-encoding: gzip;q=0.5, br ;q=0.8' http://127.0.0.1:3000/
curl -I -H 'accept-encoding: gzip;q=0.5, br ; q=0.8' http://127.0.0.1:3000/
Case 3: Invalid qvalues are accepted (fixed by #220)
Qvalues are expected to have exactly 1 digit before and not more than 3 digits after the decimal point.
curl -I -H 'accept-encoding: gzip;q=00.5' http://127.0.0.1:3000/
curl -I -H 'accept-encoding: gzip;q=0.5000' http://127.0.0.1:3000/
curl -I -H 'accept-encoding: gzip;q=.5' http://127.0.0.1:3000/
Case 4: Request not rejected if client rejects identity encoding
If the client explicitly rejects the identity encoding or the wildcard encoding
*
, and accepts no encodings supported by the server, the request should be rejected.curl -I -H 'accept-encoding: identity;q=0' http://127.0.0.1:3000/
curl -I -H 'accept-encoding: *;q=0' http://127.0.0.1:3000/
The text was updated successfully, but these errors were encountered: