* 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)
| 250 | * @returns the decoded path, or `null` if it is unusable. |
| 251 | */ |
| 252 | function 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 |
no outgoing calls
no test coverage detected