security: remediate exploitable vulnerabilities from 2026-07-18 audit#8
Merged
Conversation
Fixes findings documented in sec-findings.md: High - V-1 SSRF via upstream redirect (manual redirect mode + allowlist/same-origin) - V-2 JWT algorithm confusion (algorithm derived from key type, PEM rejection) - V-3/V-19 Sticky-session unbounded map + TTL refresh (maxSessions, LRU, unknownCookiePolicy) - V-4 Open redirect on HTTP→HTTPS redirect (require hostname or allowHosts) Medium - V-5/V-13 JWT without exp + missing aud/iss (hardened jwt-auth middleware) - V-6 excludePaths prefix bypass (boundary-aware matching) - V-7/V-16 Set-Cookie/Authorization logged in plaintext (redact in logger) - V-8/V-12 non-canonical/double encoding bypass (overlong encoding rejection) - V-9 Async route errors leaking stack/paths (await router.fetch + sanitized handler) - V-10 TLS minVersion/cipherSuites ignored (map to Bun secureOptions/ciphers) - V-11 Simple proxy sending Host: localhost (build upstream URL from route.target) - V-14 Health-check body read timeout (abort signal across bounded read) - V-17 Load-balancer connection double-decrement (idempotent flag) - V-18 trustCloudflare/trustXRealIP opt-in Also fixes route-level rateLimit.excludePaths to be boundary-aware. Adds src/security/jwt-auth.ts and comprehensive tests. Updates docs/SECURITY.md, docs/API_REFERENCE.md, docs/AUTHENTICATION.md, docs/TLS_CONFIGURATION.md, docs/LOAD_BALANCING.md, docs/QUICK_START.md, docs/EXAMPLES.md, AGENTS.md, README.md and examples/security-hardened.ts. Tests: 887 pass / 0 fail. Coverage: 99.22% lines / 94.78% funcs.
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
This PR remediates the exploitable vulnerabilities identified in the 2026-07-18 security audit (
sec-findings.md) and updates documentation and tests to match the new behavior. It also fixes a flaky E2E test that was failing on CI.Security fixes
High
redirectAllowlist/redirectSameOriginbefore following any redirect.maxSessionscap, TTL refresh, andunknownCookiePolicyto the sticky-session implementation.server.hostnameortls.redirectAllowedHostsbefore issuing a redirect.Medium
exp/ missingaud/iss— Newsrc/security/jwt-auth.tsrequiresexp, supportsaudience/issuer, and validatesexcludePathswith boundary-aware matching.excludePathsprefix bypass — Global and route-level rate-limit / authexcludePathsnow use boundary-aware matching.cookie,set-cookie, andauthorizationfrom request/response logs.minVersionandcipherSuitesare now mapped to Bun'ssecureOptions/ciphers.Host: localhost— UpstreamHostheader is built from the route target instead of the gateway's own host.AbortSignaland reads the response body with a bounded timeout.trustCloudflare/trustXRealIPare now opt-in and used for client-IP extraction and rate-limit keys.Documentation & examples
docs/SECURITY.md,docs/API_REFERENCE.md,docs/AUTHENTICATION.md,docs/TLS_CONFIGURATION.md,docs/LOAD_BALANCING.md,docs/QUICK_START.md,docs/EXAMPLES.md,docs/DOCUMENTATION.md.README.md,AGENTS.md, andexamples/security-hardened.tsto reflect new options and defaults.Tests & CI
excludePaths, sticky-session limits, logger redaction, TLS mapping, and the security findings suite.Hooks E2E Tests > should handle async fallback response generationby reusing the shared failing server instead of spawning a new one on CI.887 pass / 0 failwith coverage at99.22% lines / 94.78% funcs.testsworkflow is now passing on both the push and pull-request events.