GHSA-vj59-8hwv-xxmv Astro: Authorization Bypass via Decode Iteration Limit and Rewrite Path Canonicalization Mismatch
Astro 6.4.7 Authorization Bypass via Decode Iteration Limit and Rewrite Path Canonicalization MismatchSummaryAstro 6.4.7 appears to reintroduce a middleware authorization bypass pattern when a request path is encoded more deeply than the newly introduced iterative URL decoder's maximum decoding depth.The issue occurs because Astro performs authorization decisions on a partially decoded pathname after reaching a decoding iteration cap, while later route matching logic performs an additional `decodeURI()` operation and resolves the request to a protected route.As a result, middleware and route matching may operate on different pathname representations, enabling authorization bypasses under specific application patterns.**Potential CWE:** CWE-647 – Use of Non-Canonical URL Paths for Authorization DecisionsVulnerable PatternMiddleware authorization sees:Later rewrite route matching sees:This discrepancy allows a request that bypasses middleware checks to subsequently resolve to a protected route.Root CauseIterative Decoding LogicPR #16967 introduced iterative URI decoding:The intent was to ensure middleware receives a fully decoded canonical pathname.However, once the iteration cap is reached, Astro returns the partially decoded value instead of rejecting the request.Rewrite Route MatchingLater, Astro performs another decode during route matching:Consequently:This creates a canonicalization mismatch between authorization logic and routing logic.Proof of ConceptMiddlewareThe critical pattern is:The middleware makes an authorization decision using a non-canonical path and then forwards the URL into Astro's rewrite machinery.ReproductionProtected RouteResponse:Bypass RequestResponse:This demonstrates:Encoding Depth AnalysisThe bypass occurs at encoding depth 11.Decoder TraceDepths 0–10 are fully decoded and blocked by middleware.Depth 11 is the first depth where Astro returns a partially decoded pathname due to the iteration limit.A later `decodeURI()` converts:into:allowing route matching to reach the protected endpoint.Exploit PreconditionsExploitation requires:1. Path-Based AuthorizationMiddleware performs authorization using:For example:2. Rewrite-Based RoutingThe request is subsequently passed into Astro routing via:or equivalent rewrite behavior that performs route matching after middleware execution.ImpactAn unauthenticated attacker may bypass middleware protections guarding routes such as:if the application:Relies on pathname-based authorization checks.Uses rewrite behavior that performs route matching after middleware execution.Affected applications may expose protected pages or APIs despite middleware restrictions.Security AnalysisThe issue belongs to the same vulnerability class as the previously disclosed Astro middleware encoding bypass.Previous advisories demonstrated bypasses using:to reach:The 6.4.7 fix attempted to ensure middleware receives a canonical pathname by repeatedly decoding URL-encoded paths.However, because decoding is capped at 10 iterations and partially decoded paths are returned, an attacker can simply increase encoding depth beyond the cap and recreate the authorization-routing mismatch.The existence of a decoding limit is not itself problematic.The vulnerability arises because Astro:Stops decoding.Returns a partially canonicalized pathname.Performs additional decoding later during route matching.Authorization and routing therefore operate on different pathname representations.Recommended FixDo not return partially decoded pathnames when the iteration limit is exceeded.Instead, reject the request whenever decoding has not stabilized before reaching the cap.Example FixAdditional HardeningAstro should centralize pathname canonicalization and ensure routing logic never performs an additional independent `decodeURI()` on values that have already been normalized.Authorization and route matching must operate on the exact same canonical pathname representation.ConclusionAstro 6.4.7 appears vulnerable to an authorization bypass caused by a pathname canonicalization mismatch introduced by the iterative decoding limit.When URL encoding depth exceeds the decoder's maximum iteration count, middleware receives a partially decoded pathname while later route matching performs additional decoding and resolves the request to a protected route.This can allow unauthorized access to routes protected by pathname-based middleware authorization and should be addressed by rejecting over-encoded paths or ensuring a single canonical pathname representation is used throughout request processing.
CVSS v3.1 score: 8.2