Skip to content

feat(hub): add an isolated read-only public share reader - #438

Draft
weastler wants to merge 12 commits into
build/hub/newfrom
weastler-hub-public-sharing
Draft

weastler wants to merge 12 commits into
build/hub/newfrom
weastler-hub-public-sharing

Conversation

@weastler

@weastler weastler commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 15f8b27a1ac0c3d885a8254b5fce3d0ebfb8914e

Dimension Assessment Rationale
Change confidence 9/10 ↑ 85 focused tests cover per-request revocation, expiry and password checks, HEAD and 304, bounded reads and allowances, the host allowlist, password throttling and the 9 review-thread fixes; mutation probes confirmed the tests fail when those rules break.
↑ All 57 CI checks pass on this revision, including Hub lint, typecheck, unit tests and build on both Node versions.
↑ An independent review and the conventions gate passed on f889e81b; the only later commit adds tests and fixes the local-run example, which was run as written.
↓ Never run against real Azure Blob storage or a managed identity; that waits for PR 3's non-production installation.
↓ The password and unavailable pages, including the dark-mode contrast fix, were not checked in a browser.

Why

Public share links today depend on wildcard preview hosts that the Azure installation does not provision, so hosted Builds cannot be shared publicly. ADR 0003 records the accepted design: Hub copies a shared Build into a separate public export storage, and a separate read-only reader serves it. The reader never contacts Hub and holds no Hub data or secrets. This first PR adds that reader and the storage contract. Hub does not write exports yet, and nothing is deployed or enabled.

What changes

A viewer opens https://<public-hostname>/s/<shareId>. The reader checks the share's policy, asks for a password if the link has one, then sets a cookie for the Build's own mount path and redirects there. The Build loads unchanged, because it was already compiled for that path.

flowchart LR
  viewer["Link viewer"] -- "/s/shareId" --> reader["Public share reader"]
  reader -- "reads policy, manifest and files by exact name" --> exports[("Public export storage")]
  hub["Hub (later PR)"] -- "writes and revokes" --> exports
  reader -. "no route" .-> hub
Loading
  • Export contract. Each share is a self-contained copy: files named by SHA-256, an immutable manifest.json, and a policy.json written last to activate the share. Revoking means overwriting the policy. Schemas, storage keys, scrypt password hashing (at least 8 characters) and cookie proofs live in hub/server/domains/public-share-export/.
  • Every request is checked. Pages, assets, HEAD and revalidations all recheck revocation, expiry and the current password. The checks run again after slow reads. Revocation reaches every replica within 5 seconds.
  • Serving rules. Files are served only when the manifest lists them, with an SPA fallback for extensionless page navigations and a redirect that adds a directory's missing trailing slash. Storage is never listed. Reads are size-bounded and share memory allowances, and stalled downloads are dropped. Password attempts are limited to 5 per visitor and link in 10 minutes, per replica.
  • Strict responses. Responses send a strict content security policy, deny framing, send noindex and no-referrer (same-origin on the password page, so its form keeps its origin), and set only the reader's own share cookies.
  • Hostnames. The reader accepts its generated Container Apps origin and an optional custom-domain origin, so adding a custom domain later keeps existing links working.
  • Isolation. The reader accepts only its own settings and refuses to start beside any Hub, private storage, database or credential-named setting. A test checks that its import graph reaches no Hub code except Hub's dependency-free start-page rule.

Run it with npm run start:public-share-reader; the reader guide lists its settings. Existing share links are unchanged.

Hub export, share records and UI (PR 2) and Terraform and setup wizard support (PR 3) follow. The reader has not run against real Azure storage or a managed identity; PR 3's non-production installation covers that. It does not support byte-range requests, which Safari needs to play video.

weastler and others added 9 commits November 29, 2026 15:55
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add version 1 manifest and policy schemas, exact storage keys, scrypt
password hashing, cookie proofs, manifest-only file resolution, a cached
share state reader, and bounded Azure Blob and filesystem object readers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reader opens /s/<shareId>, checks expiry, revocation and the password
on every file and HEAD request, serves exact manifest files with an SPA
fallback, and never lists storage or contacts Hub. It refuses to start
with Hub settings and is not deployed or enabled.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Share one byte allowance across file, manifest and policy reads, keep a
file's reservation until its read and response end, and abort reads on
disconnect. Recheck expiry after the manifest loads, the password after
file reads and verification, start policy freshness at read time, check
the newest share cookies first, and throttle wrong passwords per caller.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refresh the policy after a slow manifest load, give policy and manifest
reads their own allowance so a large file cannot block its own checks,
reissue a reopened share's cookie so it becomes the newest, and return
503 when the post-read check cannot reach storage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Replace PUBLIC_SHARE_ORIGIN with a required PUBLIC_SHARE_GENERATED_ORIGIN
and an optional PUBLIC_SHARE_CUSTOM_ORIGIN, so adding a custom domain
keeps existing links working. Password forms must come from the host that
received them, and share passwords need at least 8 characters.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@weastler
weastler requested review from a team and nshki as code owners November 30, 2026 00:17
Copilot AI adaptive review requested due to automatic review settings November 30, 2026 00:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical issues break browser password submissions, permit Hub credentials in the reader, weaken password-attempt limits, and let stalled or disconnected requests exhaust reader capacity.

9 open issues
What changed in this PR

Adds an isolated, read-only service for exported public Build links, laying the foundation for sharing without wildcard preview hosts. Hub export writing and deployment remain follow-up work; existing share links are unchanged.

Changes:

  • Defines export schemas, storage keys, password hashing, and cookie proofs.
  • Adds file serving with policy checks, bounded reads, strict response headers, and filesystem/Azure storage adapters.
  • Adds startup commands, focused tests, and architecture and operating guides.
File Description
hub/​server/​scripts/​start-public-share-reader/​index.ts Starts and shuts down the standalone reader.
hub/​server/​scripts/​start-public-share-reader/​index.test.ts Checks the reader’s import isolation.
hub/​server/​routes/​public-share-reader/​index.ts Handles share entry, passwords, and file responses.
hub/​server/​routes/​public-share-reader/​index.test.ts Covers access checks, serving, and resource limits.
hub/​server/​integrations/​filesystem/​create-public-share-object-reader/​index.ts Reads bounded local export objects.
hub/​server/​integrations/​express/​send-public-share-page/​index.ts Renders password and unavailable pages.
hub/​server/​integrations/​azure-blob/​create-public-share-object-reader/​index.ts Reads Azure exports using managed identity.
hub/​server/​integrations/​azure-blob/​create-public-share-object-reader/​index.test.ts Covers blob errors and bounded reads.
hub/​server/​domains/​public-share-export/​verify-public-share-password/​index.ts Verifies passwords against stored scrypt hashes.
hub/​server/​domains/​public-share-export/​types.ts Defines export schemas, limits, and interfaces.
hub/​server/​domains/​public-share-export/​resolve-public-share-file/​index.ts Resolves manifest files and navigation fallbacks.
hub/​server/​domains/​public-share-export/​read-public-share-reader-settings/​index.ts Validates reader configuration and rejects forbidden settings.
hub/​server/​domains/​public-share-export/​read-public-share-reader-settings/​index.test.ts Covers configuration acceptance and refusals.
hub/​server/​domains/​public-share-export/​public-share-storage-key/​index.ts Constructs exact export object keys.
hub/​server/​domains/​public-share-export/​hash-public-share-password/​index.ts Creates salted password hashes.
hub/​server/​domains/​public-share-export/​hash-public-share-password/​index.test.ts Covers password length and Unicode handling.
hub/​server/​domains/​public-share-export/​create-public-share-state-reader/​index.ts Loads and caches policies and manifests.
hub/​server/​domains/​public-share-export/​create-public-share-state-reader/​index.test.ts Covers caching, state changes, and storage failures.
hub/​server/​domains/​public-share-export/​create-public-share-proof/​index.ts Creates password-bound cookie proofs.
hub/​server/​domains/​public-share-export/​create-public-share-byte-allowance/​index.ts Bounds concurrent storage-read reservations.
hub/​package.json Adds production and development reader commands.
hub/​docs/​README.md Links the reader guide.
hub/​docs/​public-share-reader.md Documents the export contract and runtime operation.
docs/​adr/​0003-public-sharing-export-reader.md Records the architecture, trade-offs, and follow-up scope.

Review effort: Max (adaptive)

@weastler
weastler marked this pull request as draft November 30, 2026 00:38
weastler and others added 3 commits November 29, 2026 16:43
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Allow only the reader's own settings, keep the password form's origin,
count password attempts before checking them with a 5-attempt cooldown
per visitor and replica, release reservations after early disconnects,
drop stalled downloads, accept Build-sized manifests and Hub-normalized
start pages, redirect slashless directories, and raise dark-mode alert
contrast.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ad room

Also show a working local run of the public share reader with env -i.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

2 participants