fix(api): close coverage edges in media-references route

This commit is contained in:
_Kerman
2026-09-07 16:20:10 +08:00
parent b685a9a6b0
commit f81c5072bd
2 changed files with 4 additions and 6 deletions
@@ -126,20 +126,16 @@ export async function serveMediaReference(
}
if (registry === undefined) return new Response('file serving is unavailable', { status: 403 })
let canonical: string
let info
try {
canonical = await realpath(path)
info = await stat(canonical)
} catch {
return new Response('not found', { status: 404 })
}
const insideWorkspace = registry.list().some(root =>
canonical === root.path || canonical.startsWith(root.path + sep))
if (!insideWorkspace) return new Response('outside workspace roots', { status: 403 })
let info
try {
info = await stat(canonical)
} catch {
return new Response('not found', { status: 404 })
}
if (!info.isFile()) return new Response('not a regular file', { status: 403 })
const mediaType = mediaTypeForPath(canonical)
if (mediaType === undefined) {