Harden path canonicalization, middleware consistency, and hot paths - #14
Merged
Merged
Conversation
Resolve remaining gaps from the v1.3.0 security pass: canonicalize dot-segments so routing and excludePaths agree, unify exact/boundary path matching, bound MemoryStore, and close CORS/logger leaks. Cut per-request URL allocations and cache custom JSON parsers. Co-authored-by: Rolando Santamaria Maso <jkyberneees@users.noreply.github.com>
Adversarial review of the first revision: FIFO maxKeys eviction could reset victim counters, and getRequestPath preferred a mutable req.path. New keys now 429 when the store is full; the router writes a one-time canonical-path symbol that security middleware consults instead. Co-authored-by: Rolando Santamaria Maso <jkyberneees@users.noreply.github.com>
Use the canonical path for Prometheus route labels, redact plain-object response headers, and cover sliding-window fail-closed admission. Co-authored-by: Rolando Santamaria Maso <jkyberneees@users.noreply.github.com>
jkyberneees
marked this pull request as ready for review
September 5, 2026 12:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adversarial re-review of the v1.3.0 hardening pass. That release fixed the 43 named findings, but several remediations were incomplete or inconsistent across modules. This PR closes those gaps, then a second adversarial pass (Bugbot + security review) challenged the first revision.
Security
%2e%2e/..are now resolved after URI decoding. Routing andexcludePathsshare one canonical path, so/admin/../healthcannot skip JWT while routing elsewhere.Symbol.for('0http.canonicalPath'). Security middleware never trusts mutablereq.path.excludePaths— exact or boundary match (same as JWT and rate-limit)./healthno longer skips/healthcheck.Vary: Originfor static string origins;Origin: nullis rejected for all non-wildcard configs; methods compared case-insensitively; origin validators receive(origin, req)as documented.Set-Cookie/Authorization/Cookie/X-Api-Keyare redacted on both request serializers and default response logs.req.ctx.authErroris a generic message, not the raw jose error.maxKeys(default 10,000) and amortized cleanup. When full, new keys fail closed (429) instead of FIFO-evicting live counters (the first revision's eviction was rejected on review).Performance
new URL()on every request.jsonTypesparsers are cached.Ergonomics
req.path,req.body,req.files, logger options,errorHandler(err, req),extended, andmaxKeys.ParsedFile.dataisUint8Array(matches the implementation).bun run lintinstead offormat. Bench script points atbench.ts.Adversarial review
maxKeyseviction and trustedreq.path. Both are fixed in the follow-up commit. LeftovertokenQueryremains a documented, warned opt-in (removing it would be breaking).Test plan
bun test— 525 pass / 0 failbun run lint— prettier check clean%2e%2erouting, excludePaths consistencyreq.pathdoes not skip JWTnullorigin