Skip to content

feat(org-fs): password-protected file/folder sharing - #4135

Merged
viktormarinho merged 4 commits into
mainfrom
viktormarinho/file-share-password
Jun 25, 2026
Merged

viktormarinho merged 4 commits into
mainfrom
viktormarinho/file-share-password

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #4125 (merged). A third share mode — password — on top of public sharing. The /read proxy serves an interstitial password form before content; one unlock (a signed, scoped cookie) covers the node the password sits on — a single file, or a whole folder + its assets — mirroring public. Most-specific published node governs.

How it works

  • Crypto (share-password.ts): scrypt hash/verify, a per-node share_secret, and HMAC unlock tokens signed with MESH_JWT_SECRET. Rotation + expiry + org/volume binding all fail closed.
  • Storage/service: shareMode (private/public/password) is derived in the DTO — the password hash never leaves the server. resolveGoverningShare finds the most-specific published node; resolveReadAccess returns private/public/password (+ govPath/secret).
  • Proxy: GET /read checks the unlock cookie → serves or returns the form. POST /unlock verifies the password (scrypt, rate-limited) and sets a scoped httpOnly; SameSite=Lax cookie. POST /public now takes { mode, password? } (back-compat: { public }). A non-member/anonymous gets the form; a member bypasses it (reads via ORG_FS_READ). Password content is never shared-cached.
  • UI: ShareControls becomes a 3-way control (Org only / Public / Password) with a set/update password field; the card badge gains a password (key) tier.
  • Tests: crypto unit (7) + integration (governing resolution, folder inheritance, most-specific override, password-change rotation).

Decisions made (open to push-back)

  1. Overlay on read_public, not a share_mode enum — reuses feat(org-fs): public file sharing via read_public flag #4125 whole.
  2. Gated on ORG_FS_WRITE (same as public). ORG_FS_PUBLISH deliberately not built here — kept as the governance/agent follow-up.
  3. Members bypass the password (it's for outside-the-org sharing).
  4. Rate limit = in-memory, per-instance, 10 / 5 min per (IP, path).
  5. Password change rotates the secret; most-specific node governs.

Migration

121-org-fs-share-password adds share_password_hash + share_secret (both nullable). Auto-runs on boot / bun run migrate.

🤖 Generated with Claude Code

viktormarinho and others added 2 commits June 24, 2026 17:09
…hare_secret)

First step of password-protected sharing (design:
.context/file-share-password-spec.md). Adds the two nullable columns the
gate needs — a scrypt hash (null = fully public, set = password-gated) and a
per-node secret rotated on password change to invalidate unlock cookies.
Layered on read_public (link-accessible); proxy gate + UI follow after
design sign-off.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds a third share mode on top of public sharing. The /read proxy serves an
interstitial password form before content; one unlock (a signed, scoped
cookie) covers the node the password sits on — a file, or a whole folder + its
assets — mirroring public. Most-specific published node governs.

- crypto (share-password.ts): scrypt hash/verify, per-node share_secret,
  HMAC unlock tokens (MESH_JWT_SECRET); rotation + expiry fail closed.
- storage: derive shareMode in the DTO (hash never leaves the server),
  setShareMode, resolveGoverningShare (most-specific public node).
- service: OrgFs.setShareMode (hash + rotate secret), resolveReadAccess
  (private/public/password + govPath/secret).
- route: read branch (cookie check → form), POST /unlock (scrypt verify,
  rate-limited, sets scoped cookie), /public now takes { mode, password? }.
  Members bypass the prompt; non-members/anonymous get the form. Password
  content is never shared-cached.
- middleware: carve-out so non-members can POST /unlock.
- UI: ShareControls 3-way control (Org only / Public / Password) + password
  field; card badge gains a password (key) tier.
- tests: crypto unit (7) + integration (governing resolution, inheritance,
  most-specific override, password-change rotation).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@viktormarinho
viktormarinho marked this pull request as ready for review June 24, 2026 20:46
@viktormarinho viktormarinho changed the title feat(org-fs): password-protected file/folder sharing [WIP] feat(org-fs): password-protected file/folder sharing Jun 24, 2026
viktormarinho and others added 2 commits June 24, 2026 18:31
Address review #1: a folder password is one credential for the whole subtree,
so keying the brute-force limiter on the requested file path let an attacker
multiply the lockout by guessing sibling sub-paths under the same share.
Resolve the governing share first, then key the limiter on access.govPath.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
#1 Inherited-public files now render a read-only "shared via a parent folder"
state instead of the editable 3-way control — clicking "Org only" used to toast
success while the published parent kept serving it (false confirmation).
Restores the guard the old 2-way switch had.

#2 Unlock rate limiter no longer trusts the spoofable leftmost X-Forwarded-For
alone: prefer cf-connecting-ip / x-real-ip, and add a per-share global cap
(50/5min, IP-independent) as a backstop so rotating XFF can't fully unthrottle
brute-force. Per-IP cap (10/5min) stays for the normal case.

#3 Password hashing/verification moved to async scrypt — scryptSync on the
public, unauthenticated /unlock route blocked the event loop and serialized
concurrent attempts. Callers + tests updated to await.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@viktormarinho
viktormarinho merged commit cfe17cf into main Jun 25, 2026
21 of 22 checks passed
@viktormarinho
viktormarinho deleted the viktormarinho/file-share-password branch June 25, 2026 00:38
decocms Bot pushed a commit that referenced this pull request Jun 25, 2026
PR: #4135 feat(org-fs): password-protected file/folder sharing
Bump type: minor

- decocms (apps/mesh/package.json): 3.55.0 -> 3.56.0

Deploy-Scope: both
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.

1 participant