Skip to content

fix: normalize path before rate-limit bucket keying (#27273)#27444

Open
github-actions[bot] wants to merge 1 commit into
release/2.34from
backport/27273-to-2.34
Open

fix: normalize path before rate-limit bucket keying (#27273)#27444
github-actions[bot] wants to merge 1 commit into
release/2.34from
backport/27273-to-2.34

Conversation

@github-actions

Copy link
Copy Markdown

Backport of #27273

Original PR: #27273 — fix: normalize path before rate-limit bucket keying
Merge commit: de716f8
Requested by: @jdomeracki-coder

Coder's rate limiter keyed its bucket on the raw, un-normalized request
path (`httprate.KeyByEndpoint` reads `r.URL.Path` directly). The
router's `singleSlashMW` already collapses redundant slashes so a
request like `/api/v2/users//validate-password` reaches the same handler
as the canonical path, but it never touched `r.URL.Path`, so the rate
limiter saw a different key and let a client bypass a limit it had
already hit just by respelling the URL.

`keyByNormalizedEndpoint` replaces `KeyByEndpoint` and runs `path.Clean`
on `r.URL.Path` before using it as the key, so equivalent paths share
one bucket. Includes a unit test at the key-function level and an
integration test (`TestRateLimitPathNormalization`) that reproduces the
bypass against a real server.

Fixes CDM-02-003 (Cure53). Refs
https://github.com/coder/security-disclosures/issues/166.

(cherry picked from commit de716f8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants