Fix path-traversal-adjacent bypass in static file containment check

The WEB_STATIC file server checked containment with a plain string
prefix (filePath.startsWith(WEB_DIST)), which a sibling directory
sharing that prefix passes without actually being inside WEB_DIST -
e.g. WEB_DIST "/app/web/dist" also accepts "/app/web/dist-backup/...".
Now requires an exact match or a path-separator boundary.

WEB_STATIC defaults to on, so this affects any self-hoster serving the
UI from the gateway with the stock config, not just this deployment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Sonnet 5 committed 2026-09-17 17:35:54 +00:00
1 parent 667012d710
commit 83afe6c2cd
1 file changed
+1 -1
+1 -1
View File
@@ -383,7 +383,7 @@ const requestHandler = (req: IncomingMessage, res: ServerResponse) => {
return;
}
let filePath = path.join(WEB_DIST, decodeURIComponent(requestUrl.pathname));
if (!filePath.startsWith(WEB_DIST)) {
if (filePath !== WEB_DIST && !filePath.startsWith(WEB_DIST + path.sep)) {
res.writeHead(403);
res.end();
return;