You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello !
I discovered recently that many user agents send raw UTF8 bytes in HTTP paths, and proxies forward them without issues. See actix/actix-web#3102
However, it looks like this library fails to parse such HTTP requests, preventing web servers from handling them.
Would it be possible to handle such requests in this library ?
But if actual user agents, including safari, do send requests with utf8 paths, shouldn't we support them in server-side libraries, even if there is an RFC saying they are invalid ?
The general answer to that question is not always easy. There's sometimes good reasons to prevent them.
In this case, it could be fine to make the parser more relaxed. I was trying to remember what said to make it strict originally, so I could read if they included any comments as to why.
I believe this is coming from rfc3986 section 3.3 and the definition for a path segment not allowing non-us-ascii characters
In particular it's the pchar definition, where characters outside the allowed set need to be percent encoded.
path=path-abempty; begins with "/" or is empty/path-absolute; begins with "/" but not "//"/path-noscheme; begins with a non-colon segment/path-rootless; begins with a segment/path-empty; zero characterspath-abempty=*( "/"segment )
path-absolute="/" [ segment-nz*( "/"segment ) ]
path-noscheme=segment-nz-nc*( "/"segment )
path-rootless=segment-nz*( "/"segment )
path-empty= 0<pchar>segment=*pcharsegment-nz=1*pcharsegment-nz-nc=1*( unreserved/pct-encoded/sub-delims/"@" )
; non-zero-length segment without any colon ":"pchar=unreserved/pct-encoded/sub-delims/":"/"@"pct-encoded="%"HEXDIGHEXDIGunreserved=ALPHA/DIGIT/"-"/"."/"_"/"~"sub-delims="!"/"$"/"&"/"'"/"("/")"/"*"/"+"/","/";"/"="
right now applications which use httparse can be sure that it returns a valid uri according to rfc3986
perhaps a feature flag could be added to allow utf8 (rfc3986-non-compliant) path support, so that applications can choose whether they want httparse to be strict or relaxed?
But if there is a flag, is it realistic to think people will care enough to activate it ? I only learned about this after getting bitten by it, and httparse is probably a sub-sub-dependency for most people who just want to handle http requests made by web browsers. I think it would be great if httparse were able to parse web requests made by Safari by default, and if the update just silently fixed this issue that is currently present by transitivity almost everywhere in the rust server framework ecosystem.
use Websocket for ws://127.0.0.1:2000/api/pe/ws?server_name=阿
this use chinese path
ERROR [actix_http::h1::dispatcher] stream error: request parse error: invalid Header provided
I know change is already merged and released, but I want to point out that these kind of changes should be considered a breaking change: input which originally was leading to error now leads to success.
This library has hundreds of millions of installation and at this scale there are workloads which do depend on pre-existing behavior (https://www.hyrumslaw.com/) and this change did break them.
This change should have been hidden behind a feature flag (or runtime flag) which is disabled by default, or introduced with a major version bump.
It's not about whether it was a bug or not, it's about the fact that it's a breaking change which happened under the users of this library with huge installation base, without a major version change.
Even if it was bug, there are workloads which depend on specific behavior, whatever it is. While in our specific case it caused a rather mild impact, there may be other workloads, which, for example, expected that UTF8 requests always get rejected by httparse (which was the case and it was an observable behavior), and enabling them lead to passing UTF8 strings somewhere where they cannot be properly handled, leading to availability or even security problems.
I want to clarify, I'm not opposed to enabling UTF8 support, I am concerned about the strategy in which it was rolled out.
All bug fixes are changes in behavior, and they all break applications that initially relied on the bug being there. But that shouldn't prevent maintainers of popular libraries from fixing bugs in minor releases. More availability and security issues were resolved than were introduced by this change.
As a reminder, the previous versions of this library had the potential to crash entire web servers when receiving valid http requests sent by popular browsers. Fixing this in a minor version was the right thing to do.
Activity
seanmonstar commentedon Aug 30, 2023
I feel like the bytes that httparse initially allowed were from an RFC, but I no longer remember which one it was (7230? URIs? WHATWG Fetch?)
lovasoa commentedon Aug 30, 2023
But if actual user agents, including safari, do send requests with utf8 paths, shouldn't we support them in server-side libraries, even if there is an RFC saying they are invalid ?
seanmonstar commentedon Aug 30, 2023
The general answer to that question is not always easy. There's sometimes good reasons to prevent them.
In this case, it could be fine to make the parser more relaxed. I was trying to remember what said to make it strict originally, so I could read if they included any comments as to why.
JakeChampion commentedon Oct 27, 2023
I believe this is coming from rfc3986 section 3.3 and the definition for a path segment not allowing non-us-ascii characters
In particular it's the pchar definition, where characters outside the allowed set need to be percent encoded.
The whole abnf can be view at either https://abnf-uri.edgecompute.app/ or https://www.rfc-editor.org/rfc/rfc3986.html#appendix-A
right now applications which use httparse can be sure that it returns a valid uri according to rfc3986
perhaps a feature flag could be added to allow utf8 (rfc3986-non-compliant) path support, so that applications can choose whether they want httparse to be strict or relaxed?
lovasoa commentedon Oct 27, 2023
But if there is a flag, is it realistic to think people will care enough to activate it ? I only learned about this after getting bitten by it, and httparse is probably a sub-sub-dependency for most people who just want to handle http requests made by web browsers. I think it would be great if httparse were able to parse web requests made by Safari by default, and if the update just silently fixed this issue that is currently present by transitivity almost everywhere in the rust server framework ecosystem.
banchen19 commentedon Mar 11, 2024
use Websocket for ws://127.0.0.1:2000/api/pe/ws?server_name=阿
this use chinese path
ERROR [actix_http::h1::dispatcher] stream error: request parse error: invalid Header provided
seanmonstar commentedon Sep 12, 2024
I'd prefer to check with a few places that proxy serious Internet traffic if this is something they see, or have reasons to not want it.
cc @Noah-Kennedy @nox @acfoltzer
JakeChampion commentedon Sep 13, 2024
When I worked at Fastly we did see this from some customers traffic, which is why I ended up reading the RFC and commenting above on this issue 👍
nox commentedon Sep 13, 2024
@seanmonstar We are already running a httparse fork for some products to support raw UTF-8 paths.
joelwurtz commentedon Sep 16, 2024
We are also observing this for some of customers where they hit this error because of utf8 char in path, we also use a fork to support this
feat(path): allow utf8 chars in path (seanmonstar#178)
tomkris commentedon Feb 7, 2025
I know change is already merged and released, but I want to point out that these kind of changes should be considered a breaking change: input which originally was leading to error now leads to success.
This library has hundreds of millions of installation and at this scale there are workloads which do depend on pre-existing behavior (https://www.hyrumslaw.com/) and this change did break them.
This change should have been hidden behind a feature flag (or runtime flag) which is disabled by default, or introduced with a major version bump.
lovasoa commentedon Feb 7, 2025
I disagree. The previous behavior was a bug.
tomkris commentedon Feb 7, 2025
It's not about whether it was a bug or not, it's about the fact that it's a breaking change which happened under the users of this library with huge installation base, without a major version change.
Even if it was bug, there are workloads which depend on specific behavior, whatever it is. While in our specific case it caused a rather mild impact, there may be other workloads, which, for example, expected that UTF8 requests always get rejected by httparse (which was the case and it was an observable behavior), and enabling them lead to passing UTF8 strings somewhere where they cannot be properly handled, leading to availability or even security problems.
I want to clarify, I'm not opposed to enabling UTF8 support, I am concerned about the strategy in which it was rolled out.
lovasoa commentedon Feb 8, 2025
All bug fixes are changes in behavior, and they all break applications that initially relied on the bug being there. But that shouldn't prevent maintainers of popular libraries from fixing bugs in minor releases. More availability and security issues were resolved than were introduced by this change.
As a reminder, the previous versions of this library had the potential to crash entire web servers when receiving valid http requests sent by popular browsers. Fixing this in a minor version was the right thing to do.