Skip to content

Security: decode path segments before the dotfile guard (#639) - #640

Merged
melvincarvalho merged 1 commit into
gh-pagesfrom
fix/639-dotfile-guard-decoded
Nov 4, 2026
Merged

melvincarvalho merged 1 commit into
gh-pagesfrom
fix/639-dotfile-guard-decoded

Conversation

@melvincarvalho

Copy link
Copy Markdown
Contributor

Fixes #639.

The bug

The dotfile guard in src/server.js split the raw request.url and looked for segments starting with .. The storage lookup in src/utils/url.js percent-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 on gh-pages at 600d0ae by running the new test file against it: a .git/config, .env and .htpasswd placed 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

  • One policy, two call sites. src/utils/dotfiles.js holds the allow-list (.well-known, .acl, .meta, .pods, .notifications, .account) and decodeSegments(), 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.
  • The guard decodes before it checks. 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 (%2Eacl is 403; .acl and .%61cl are allowed). The existing bypasses (git smart-HTTP, pay routes, tunnel, WebRTC, terminal, app plugins at a dot prefix) are untouched.
  • The lookup refuses the same inputs. urlToPath() and urlToPathWithPod() now share normalizeUrlPath(): 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.
  • The one behaviour change beyond dotfiles: %2F in 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):

  • A pod with a real .git/config, .env and public/.htpasswd on disk. Literal paths stay 403. %2Egit/config, %2egit/config, %2Egit/%63onfig, %2Eenv, %2Ehtpasswd, %2E%68tpasswd are 403 and never contain the file body. All of HEAD, PUT, DELETE, PATCH and POST on %2Egit/config are 403 with the file on disk untouched.
  • Double-encoded %252Egit/config is 404 (decoded once it is %2Egit, which is not on disk), never the body.
  • %E0%A4%A, %2Egit%2Fconfig and public%2F%2Ehtpasswd are 400.
  • .acl and /.well-known/openid-configuration are not 403; %2Eacl is.
  • a%20b.txt round-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, .%61cl still resolve; %2E%2E traversal and ....// still stripped.

Running the same file against unpatched gh-pages: 8 of 13 fail, including the .git/config leak.

Full suite on the branch: 1116 tests, 1116 pass, 0 fail.

Docs

docs/security.md gains a Dotfiles section describing the rule.

Follow-up (not in this PR)

jspod pins javascript-solid-server to >=0.0.219 <0.0.222; it needs a release with a raised range to pick up the fix.

… 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 %2F and %5C are 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%2Egit can’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

@melvincarvalho
melvincarvalho merged commit 81f36f3 into gh-pages Nov 4, 2026
2 checks passed
@melvincarvalho
melvincarvalho deleted the fix/639-dotfile-guard-decoded branch November 4, 2026 11:45
melvincarvalho added a commit that referenced this pull request Nov 4, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: dotfile guard checks the path before it is decoded

2 participants