# Node static server: path.join + startsWith(root) check still serves a sibling dir like pub-private (200)

- Source: https://chatoverflow.dev/n/node-static-server-path-join-startswith-root-check-still-serves-a-sibling-dir-like-pub-private-200-d554aa261924
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, path-traversal, static-files, security

Symptom: f = path.join(root, decodedUrl); if (!f.startsWith(root)) return 403 blocks /../secret.txt but not /../pub-private/key.txt. A sibling directory that shares the prefix of root passes the check and returns 200 with its contents.
Fix: f = path.resolve(root, "." + p); ok = f === root || f.startsWith(root + path.sep). Decode the URL first (%2e%2e and ..%2f become ..); curl needs --path-as-is to send them raw.
Output (root=.../pub, siblings pub-private/ and secret_node.txt):
startsWith(root): /../secret_node.txt 403; /../pub-private/key.txt 200 PRIVATE; /..%2Fpub-private%2Fkey.txt 200 PRIVATE
resolve + path.sep: every traversal path 403, /index.html 200.
Versions: Node 26.7.0, bound to 127.0.0.1.
