Skip to content

Introduce ability to decode and/or canonicalize URIs in a RewriteRule #13190

Description

@joakime

Jetty version(s)
12.0.x

Enhancement Description
When running under a UriCompliance mode that allows for ambiguous path behaviors, the path still cannot reach ee10 (Servlet 6) endpoints due to the Servlet 6 rules against ambiguous paths.

There exists a feature on WebAppContext.getServletHandler().setDecodeAmbiguousURIs(true) to decode the path once it reaches that specific WebAppContext.

What is needed is a more general rule for decoding, one that can be applied during Jetty RewriteHandler, so that it can be applied before other rewrite rules, and for cross context dispatching, and even to use it in conjunction with the existing CompactPathRule.

So I propose we create a new DecodeAmbiguousPathCharactersRule that will simply decode any pct-encoded sequence in the path provided, being careful to not decode pct-encoded characters that change the parsing rules for things like query section and path parameters: %3F (?) and %3B (;).

Another approach would be a DecodedCanonicalizedPathRule which just performs the URIUtil.decodePath() and URIUtil.canonicalizedPath() behaviors against the path provided. (have to be careful of the name on this alternate approach, as the definition of canonicalized vs normalized paths has changed in 12.0/12.1)

Activity

  1. added
    SponsoredThis issue affects a user with a commercial support agreement
    on May 30, 2025
  2. added theissue type on May 30, 2025
  3. joakime commented on May 30, 2025

    @joakime
    ContributorAuthor

    @gregw what are your thoughts on this?

  4. joakime commented on May 30, 2025

    @joakime
    ContributorAuthor

    I wonder how this kind of rule would alter context path matching?

    Now: the path /foo/..%2fbar/index.html would match the context /foo and send the request there.

    With this new rule, the resulting path would be /bar/index.html, matching the context /bar instead.

  5. joakime commented on May 30, 2025

    @joakime
    ContributorAuthor

    Also, we have seen custom rules in the wild to match against various known vulnerability scanning behaviors from rogue clients, and reject those request.
    These kinds of rules have been verbose and tricky to write, but if they existed after this new proposed rule, many of the variants of rule matching would be much simpler to match against, probably even eliminating many variants of regex / patterns used.

  6. gregw commented on Jun 2, 2025

    @gregw
    Contributor

    @joakime I'm wondering if just a rule would be good enough. A rule would just correct forever. If it was put in a handler, then it could have more nuanced handling. Ideally you'd want to have a mechanism to wean bad clients off those bad URI's. So at some stage it needs to reject them with a 400 bad request message, perhaps with some instructions on how to request and exemption that can be put into their session and/or user data.

  7. added 2 commits that reference this issue on Jun 4, 2025
  8. joakime commented on Jun 4, 2025

    @joakime
    ContributorAuthor

    Decided to go a different route in PR

    Added few features to CompactPathRule instead.

    • setDecoding(boolean) - false by default, true to run decodePath
    • setCanonicalizing(boolean) - false by default, true to run canonicalizePath
    • addListener(Listener) - optional listener to get notified when a compactPath rule changed the path.
      This is where a user can add their own audit logging to record where bad clients are coming from, and approach those bad clients to get them to change their behaviors in the future.
  9. moved this to 🏗 In progress in Jetty 12.0.23 - FROZENon Jun 23, 2025
  10. changed the title [-]Introduce `DecodeAmbiguousPathCharactersRule`[/-] [+]Introduce ability to decode and/or canonicalize URIs in a RewriteRule[/+] on Jun 25, 2025
  11. self-assigned this
    on Jun 25, 2025
  12. added a commit that references this issue on Jun 26, 2025
  13. moved this from 🏗 In progress to ✅ Done in Jetty 12.0.23 - FROZENon Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

EnhancementSponsoredThis issue affects a user with a commercial support agreement

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions