ci: coverage skip part of server

This commit is contained in:
imccyu
2026-07-22 18:06:06 +08:00
parent 27fd75a314
commit 3c6a987057
3 changed files with 8 additions and 5 deletions
+5 -3
View File
@@ -6,7 +6,7 @@
*/
import type { ServerResponse } from 'node:http'
import { extname, join, normalize, resolve } from 'node:path'
import { extname, join, normalize, resolve, sep } from 'node:path'
import { readFile } from 'node:fs/promises'
const MIME: Record<string, string> = {
@@ -32,8 +32,10 @@ export async function serveStatic(
renderIndex?: () => Promise<string>,
): Promise<void> {
const target = resolve(normalize(join(distRoot, pathname)))
// Traversal rejection: the target must be distRoot itself (`/`) or stay under it.
if (target !== distRoot && !target.startsWith(distRoot + '/')) {
// Traversal rejection: the target must be distRoot itself (`/`) or stay under
// it. `sep`, not '/': resolve() emits backslash paths on Windows, where a '/'
// suffix would reject every legitimate subpath as traversal.
if (target !== distRoot && !target.startsWith(distRoot + sep)) {
res.writeHead(403)
res.end()
return