MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / decodePath

Function decodePath

src/ui-server/security.ts:252–262  ·  view source on GitHub ↗

* Percent-decode a URL path and reject the encodings that only ever show up in * an attack: NUL (truncates a path in some syscalls), other C0 control bytes, * and backslashes (a separator on Windows, a legal filename character on POSIX * — treating it as a separator everywhere is the safe directi

(urlPath: string)

Source from the content-addressed store, hash-verified

250 * @returns the decoded path, or `null` if it is unusable.
251 */
252function decodePath(urlPath: string): string | null {
253 let decoded: string;
254 try {
255 decoded = decodeURIComponent(urlPath);
256 } catch {
257 return null; // malformed percent-encoding
258 }
259 // eslint-disable-next-line no-control-regex -- rejecting raw control bytes IS the point
260 if (/[\x00-\x1f\x7f\\]/.test(decoded)) return null;
261 return decoded;
262}
263
264/**
265 * Whether a project-relative source path is one we would read at all: no raw

Callers 2

isSafeRequestPathFunction · 0.85
resolveStaticAssetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected