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

Function resolveStaticAsset

src/ui-server/security.ts:225–238  ·  view source on GitHub ↗
(rootDir: string, urlPath: string)

Source from the content-addressed store, hash-verified

223 * `..%2f` is caught by the same guard as a literal `../`.
224 */
225export function resolveStaticAsset(rootDir: string, urlPath: string): string | null {
226 const decoded = decodePath(urlPath);
227 if (decoded === null) return null;
228
229 const relative = decoded.replace(/^\/+/, '');
230 const absolute = validatePathWithinRoot(rootDir, relative);
231 if (!absolute) return null;
232
233 try {
234 return fs.statSync(absolute).isFile() ? absolute : null;
235 } catch {
236 return null;
237 }
238}
239
240/**
241 * Percent-decode a URL path and reject the encodings that only ever show up in

Callers 2

handleRequestFunction · 0.90
ui-server.test.tsFile · 0.90

Calls 2

validatePathWithinRootFunction · 0.90
decodePathFunction · 0.85

Tested by

no test coverage detected