Skip to content

support raw UTF8 paths #146

Closed
Closed

Description

@lovasoa

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 ?

Activity

  1. seanmonstar commented on Aug 30, 2023

    @seanmonstar
    Owner

    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?)

  2. lovasoa commented on Aug 30, 2023

    @lovasoa
    Author

    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 ?

  3. seanmonstar commented on Aug 30, 2023

    @seanmonstar
    Owner

    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.

  4. JakeChampion commented on Oct 27, 2023

    @JakeChampion

    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 characters
    
       path-abempty  = *( "/" segment )
       path-absolute = "/" [ segment-nz *( "/" segment ) ]
       path-noscheme = segment-nz-nc *( "/" segment )
       path-rootless = segment-nz *( "/" segment )
       path-empty    = 0<pchar>
    
       segment       = *pchar
       segment-nz    = 1*pchar
       segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
                     ; non-zero-length segment without any colon ":"
    
       pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
    
    
       pct-encoded   = "%" HEXDIG HEXDIG
    
       unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
       sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                     / "*" / "+" / "," / ";" / "="

    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?

  5. lovasoa commented on Oct 27, 2023

    @lovasoa
    Author

    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.

  6. banchen19 commented on Mar 11, 2024

    @banchen19

    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

  7. seanmonstar commented on Sep 12, 2024

    @seanmonstar
    Owner

    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

  8. JakeChampion commented on Sep 13, 2024

    @JakeChampion

    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

    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 👍

  9. nox commented on Sep 13, 2024

    @nox
    Contributor

    @seanmonstar We are already running a httparse fork for some products to support raw UTF-8 paths.

  10. joelwurtz commented on Sep 16, 2024

    @joelwurtz
    Contributor

    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

  11. added a commit that references this issue on Dec 27, 2024
    f1cbffc
  12. tomkris commented on Feb 7, 2025

    @tomkris

    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.

  13. lovasoa commented on Feb 7, 2025

    @lovasoa
    Author

    I disagree. The previous behavior was a bug.

  14. tomkris commented on Feb 7, 2025

    @tomkris

    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.

  15. lovasoa commented on Feb 8, 2025

    @lovasoa
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions