pathname.ts — astro Source File
Architecture documentation for pathname.ts, a typescript file in the astro codebase.
Entity Profile
Relationship Graph
Source Code
/**
* Validates that a pathname is not multi-level encoded.
* Detects if a pathname contains encoding that was encoded again (e.g., %2561dmin where %25 decodes to %).
* This prevents double/triple encoding bypasses of security checks.
*
* @param pathname - The pathname to validate
* @returns The decoded pathname if valid
* @throws Error if multi-level encoding is detected
*/
export function validateAndDecodePathname(pathname: string): string {
let decoded: string;
try {
decoded = decodeURI(pathname);
} catch (_e) {
throw new Error('Invalid URL encoding');
}
// Check if the decoded path is different from the original
// AND still contains URL-encoded sequences.
// This indicates the original had encoding that got partially decoded, suggesting double encoding.
// Example: /%2561dmin -> decodeURI -> /%61dmin (different AND still has %)
const hasDecoding = decoded !== pathname;
const decodedStillHasEncoding = /%[0-9a-fA-F]{2}/.test(decoded);
if (hasDecoding && decodedStillHasEncoding) {
throw new Error('Multi-level URL encoding is not allowed');
}
return decoded;
}
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does pathname.ts do?
pathname.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in pathname.ts?
pathname.ts defines 1 function(s): validateAndDecodePathname.
Where is pathname.ts in the architecture?
pathname.ts is located at packages/astro/src/core/util/pathname.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/util).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free