Repository navigation
Security: decode path segments before the dotfile guard (#639) - #640
Conversation
… in the lookup (#639) The guard in server.js inspected the raw request URL while urlToPath percent-decoded it, so /pod/%2Egit/config passed the guard and read .git/config from disk. - src/utils/dotfiles.js holds the allow-list and the decoding rule, shared by the guard and the path lookup so they cannot disagree. - The guard decodes each segment before checking it and answers 400 to a path it cannot decode or that hides a separator behind %2F. - urlToPath / urlToPathWithPod decode segment by segment and throw 403 for a segment that only becomes a dotfile by decoding. A dot has to be literal in the request, even for the allowed Solid names. Internal callers pass dotfile names literally and are unaffected. - test/dotfile-guard.test.js: a real .git/config, .env and .htpasswd in a pod are not served for encoded, mixed-case, double-encoded or malformed forms on any method; the lookup refuses the same inputs; traversal stripping and ordinary encoded names behave as before. - docs/security.md: Dotfiles section.
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🔵 Needs a closer look
The change affects security-sensitive URL/path normalization semantics (including traversal and dotfile edge cases and Windows vs POSIX expectations), so it warrants human validation beyond what unit tests can fully assure before approval.
No open issues 🎉
What changed in this PR
This pull request fixes a security vulnerability where percent-encoded dot-prefixed path segments (e.g. %2Egit/config) could bypass the dotfile guard and be resolved to sensitive dotfiles on disk due to inconsistent URL decoding between the request guard and filesystem path lookup. The fix centralizes segment-by-segment decoding and dotfile policy, applies it consistently at both guard and lookup points, adds regression tests, and documents the rule.
Changes:
- Centralize dotfile allow-list + per-segment percent-decoding (fail-closed on malformed encoding and encoded separators) in
src/utils/dotfiles.js. - Update the request-time dotfile guard to decode segments before checking and to refuse undecodable/invalid segment encodings.
- Refactor URL→filesystem path normalization to share the same decoding/refusal rules (
normalizeUrlPath()), preventing guard/lookup mismatches. - Add a comprehensive regression test suite for encoded dotfiles across methods, malformed encodings, encoded separators, and lookup behavior; document the policy in
docs/security.md.
Key review notes from the final comments to address:
- Documentation/comments should reflect that both
%2Fand%5Care rejected as encoded separators. - Consider rejecting raw backslashes in decoded segments consistently (not only when introduced via decoding) to avoid platform-dependent interpretation.
- Consider aligning
normalizeUrlPath()’s “dot introduced by decoding” check so edge cases like%2E%2Egitcan’t be handled differently than the request guard. - Minor terminology consistency (“sanitize” vs “sanitise”).
| File | Summary |
|---|---|
test/dotfile-guard.test.js |
Adds regression coverage for encoded-dotfile bypasses, malformed encodings, encoded separators, and guard/lookup alignment. |
src/utils/url.js |
Introduces shared normalizeUrlPath() and applies per-segment decoding + refusal rules to urlToPath*; includes a noted edge-case alignment consideration for “dot introduced by decoding”. |
src/utils/dotfiles.js |
New shared dotfile policy (allow-list + decodeSegments() + forbidden detection); comments/behavior should be aligned regarding %5C, and consider rejecting raw \\ consistently. |
src/server.js |
Updates the dotfile guard to decode segments before checking and to fail-closed on invalid/undecodable paths. |
docs/security.md |
Documents the dotfile policy and refusal behavior; should mention %5C alongside %2F as rejected encoded separators. |
Review effort: Balanced
Changes since 0.0.224: - Security: the dotfile guard decodes path segments before checking them, and the storage lookup refuses a segment that only becomes a dotfile by decoding, so `%2Egit/config` can no longer reach `.git/config`. Malformed percent-encoding and an encoded path separator (`%2F`) are refused with 400. New src/utils/dotfiles.js holds the shared rule. (#639, PR #640) - Conditional writes are atomic: PUT and DELETE join PATCH under the per-resource queue and cross-process lock file, so If-Match and If-None-Match are checked and acted on as one step. Two clients racing with the same ETag get one 2xx and one 412. The lock holder heartbeats so a slow write is never mistaken for a dead one; a stale lock is broken by rename and inode check, never a blind unlink; a request that cannot take the lock within 30 s gets 503 with Retry-After: 1. (#600, PR #638) - WAC-exempt app subtrees: a path under an app prefix that the app did not register answers 404 instead of falling through to pod storage with WAC skipped. OPTIONS under an app path is a bare 204. (#611, PR #637) - docs/security.md: Dotfiles and Conditional writes sections.
Fixes #639.
The bug
The dotfile guard in
src/server.jssplit the rawrequest.urland looked for segments starting with.. The storage lookup insrc/utils/url.jspercent-decoded the path before resolving it to a file. The two disagreed on what a path meant, so a request whose dot was encoded (%2E) passed the guard and resolved to the dotfile on disk. Confirmed ongh-pagesat600d0aeby running the new test file against it: a.git/config,.envand.htpasswdplaced inside a pod were served to an unauthenticated client. Encoded..was also decoded after the guard, and a malformed percent sequence surfaced as an error from the lookup rather than a refusal.The fix
src/utils/dotfiles.jsholds the allow-list (.well-known,.acl,.meta,.pods,.notifications,.account) anddecodeSegments(), which splits the path on/and percent-decodes each segment. Malformed encoding and an encoded separator (%2F,%5C) throw a 400 error, so a path that cannot be read as segments is refused rather than passed on.findForbiddenDotfile()runs on the decoded segments. A dot has to be literal in the request: a segment that only starts with a dot after decoding is refused even for the allowed names (%2Eaclis 403;.acland.%61clare allowed). The existing bypasses (git smart-HTTP, pay routes, tunnel, WebRTC, terminal, app plugins at a dot prefix) are untouched.urlToPath()andurlToPathWithPod()now sharenormalizeUrlPath(): strip leading slashes, decode segment by segment, strip..from each segment, and throw 403 for a segment that only became a dotfile by decoding. Internal callers (.acl,.meta,.quota.json, lock files,.idp,.private) pass dotfile names literally, so their raw and decoded forms agree and nothing changes for them.%2Fin a path segment used to decode into a separator and now gets a 400. No test or client in the repo relied on it.Tests
test/dotfile-guard.test.js(13 tests):.git/config,.envandpublic/.htpasswdon disk. Literal paths stay 403.%2Egit/config,%2egit/config,%2Egit/%63onfig,%2Eenv,%2Ehtpasswd,%2E%68tpasswdare 403 and never contain the file body. All of HEAD, PUT, DELETE, PATCH and POST on%2Egit/configare 403 with the file on disk untouched.%252Egit/configis 404 (decoded once it is%2Egit, which is not on disk), never the body.%E0%A4%A,%2Egit%2Fconfigandpublic%2F%2Ehtpasswdare 400..acland/.well-known/openid-configurationare not 403;%2Eaclis.a%20b.txtround-trips through PUT and GET; a trailing encoded dot is not refused.urlToPath/urlToPathWithPod: 403 for%2Egit,%2eenv,%2Eacl,%2E%2E%2Egit; 400 for malformed,%2F,%5C; literal.git/config,.quota.json,.%61clstill resolve;%2E%2Etraversal and....//still stripped.Running the same file against unpatched
gh-pages: 8 of 13 fail, including the.git/configleak.Full suite on the branch: 1116 tests, 1116 pass, 0 fail.
Docs
docs/security.mdgains a Dotfiles section describing the rule.Follow-up (not in this PR)
jspodpinsjavascript-solid-serverto>=0.0.219 <0.0.222; it needs a release with a raised range to pick up the fix.