Skip to content

feat(data-sharing): portal settings UI, privacy policy and receiver guide (4/4) - #549

Merged
9thLevelSoftware merged 23 commits into
mainfrom
feat/data-sharing-ui
Nov 6, 2026
Merged

9thLevelSoftware merged 23 commits into
mainfrom
feat/data-sharing-ui

Conversation

@9thLevelSoftware

@9thLevelSoftware 9thLevelSoftware commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Do not merge yet. #546, #547 and #548 are merged, but Cloudflare deploys the SPA on merge with no gate. Merge this only after (1) migration 20261106120000 is applied in prod, (2) "Deploy Edge Functions" has succeeded, and (3) the privacy policy text below has been reviewed. Before then the Data Sharing card would fail to load in production.

What

PR 4 of 4 for user-configurable data sharing (outbound webhooks, FLAME+). Now based on main; the diff is this PR's 23 files only.

The portal side: Profile → Settings → Data Sharing, plus the privacy policy, a receiver guide and the operator runbook.

Changes

  • DataSharingSection between Export and the danger zone. Add, edit, pause, switch on, send a test, resend everything, replace the secret, delete, and a per-endpoint delivery log.
    • The card is on a route with no tier gate on purpose: a user whose plan lapsed can still see where their data was going and pause or delete it. Adding, editing and switching on need Flame (FEATURE_MIN_TIER.dataSharing), and the server enforces it.
    • A billing outage disables changes without telling a paying user to upgrade.
    • The signing secret is shown once and held only in component state.
  • Writes are one webhook-endpoints action each and send no user id. Reads use owner RLS on webhook_endpoints / webhook_deliveries.
  • Errors surface with the server's own message (URL not allowed, limit reached, failed test delivery). A 402 goes through isTierDenied.
  • Form schema mirrors the server for instant feedback but is no stricter than it; host and address checks stay server-only.
  • dataSharingScopes.ts is added to the reviewed SPA-reachable shared modules.
  • Docs: docs/data-sharing-webhooks.md (receiver guide with verification), a runbook section, and a dated addendum in the historical security audit that records no findings.

Needs your review: privacy policy

PrivacyPolicy.tsx gains user-directed sharing in three places: the legal bases (consent, withdrawn by pausing or deleting the endpoint), section 8 (what is sent, what never is, and that the recipient is chosen by the user and does not act on our behalf), and international transfers. The effective date changes from February 20, 2026 to November 6, 2026.

I wrote that text. It has not had legal review, and the effective date should be whatever day this actually ships.

Axioms (docs/axioms.md)

How it holds Test that fails if it breaks
FP-1 No request carries a user id for the server to trust. Create and pause request bodies asserted exactly.
FP-2 Route gates are UX only; the tier is enforced in webhook-endpoints. Below Flame, only Pause and Delete are enabled. Component and E2E tests for an EMBER user.
FP-5 The secret appears once and is gone from the page after the dialog closes. Nothing is sent to the user's endpoint from the browser (CSP connect-src forbids it). "creates an endpoint from the form and shows the secret once"; E2E asserts no whsec_ remains.
FP-8 A switched-off endpoint shows why. A refused save shows the server's reason and keeps the form open. Disabled-reason and refused-save tests.

Verification

  • npm run verify passes: lint, typecheck (no new errors), 2,525 Vitest tests, production build, no sourcemaps, bundle budget.
  • 29 new Vitest tests: client wrapper 11, form schema 7, section 11.
  • npm run test:e2e: 101 passed, 1 skipped, including two new specs (a Flame user's full flow; a user below Flame).

Release order

This must merge after the migration is applied and both Edge Functions are deployed, because Cloudflare deploys the SPA on merge with no gate.

🤖 Generated with Claude Code

9thLevelSoftware and others added 6 commits November 6, 2026 12:07
…utbound webhooks

Database half of user-configurable data sharing (FLAME+): a user registers
HTTPS endpoints and the portal pushes their own data there as signed events.
Inert on its own: with no endpoint row every capture trigger returns at once
and the delivery cron job is created inactive.

- webhook_endpoints (owner SELECT, server-written), webhook_endpoint_secrets
  (service-only ciphertext) and webhook_deliveries (outbox + log). A composite
  FK ties every delivery to its endpoint's owner (FP-1).
- Statement-level capture triggers on every shared table, driven by
  private.webhook_entity_sources, so both LWW paths, the push transaction,
  portal writes and RPCs are covered by one mechanism. A capture error is a
  WARNING, never an aborted sync write (FP-3).
- Service-role RPCs: create/rotate/set-header, a FOR UPDATE SKIP LOCKED claim
  that pauses endpoints whose owner dropped below FLAME (FP-2), completion with
  backoff and auto-disable (FP-8), and a backfill.
- Not shared: raw telemetry, INFERNO-gated biomechanics, Strava-sourced
  activities, community rows, billing and sync bookkeeping. Every manifest
  table is classified in _shared/dataSharingScopes.ts and a test fails when a
  new one is not.
- Registered in the user-data manifest (secrets EXCLUDED), the RLS isolation
  suite and generated types; pgTAP floor raised.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…on race

- pgTAP: with the outbox made to reject the row, the user's write must still
  succeed (FP-3). Verified to fail when the trigger's exception handler is
  removed.
- complete_webhook_delivery: a pending row committed between the superseded
  check and the reschedule no longer surfaces as a unique violation; the
  attempt is closed as superseded.
- Raise PGTAP_TEST_FLOOR to the suite's actual count.
- Operator note on trigger lock contention.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…nd signing

The one write path for a user's outbound webhook endpoints (FLAME+):
create, update, rotate_secret, test, resend_all, delete.

- _shared/webhookTarget.ts: the only code that may fetch a user-chosen URL.
  https only, public addresses only (literal and every resolved address,
  checked on save and before each send, failing closed), own hosts refused,
  redirects never followed, response body never read. DNS rebinding is
  documented there as a residual risk and bounded, not claimed solved.
- _shared/webhookSigning.ts: Standard Webhooks headers; the HMAC key is the
  base64-decoded secret, pinned by the specification's reference vector.
- _shared/webhookSend.ts: one signed POST and a fixed outcome code. The request
  carries no Supabase credential (asserted) and nothing of the response but
  its status is kept.
- webhook-endpoints: user id from the verified JWT only; every query scoped by
  it, so another user's endpoint is a 404 for every action (FP-1). delete and a
  pause run before the FLAME gate so a lapsed user can always stop sharing
  (FP-2). The signing secret is returned once and never logged (FP-5).
  Requests to a user-chosen host have their own tight rate-limit key.
  Responses go through an explicit column allowlist.

Verified by mutation: removing the owner filter or the tier gate turns the
isolation tests red.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The delivery half of outbound webhooks. pg_cron calls deliver-webhooks every
minute (job created inactive by 20261106120000); one pass claims due rows,
builds each payload from the current data, signs it, POSTs it and records the
outcome.

- _shared/webhookPayload.ts: the only code that reads user data for a
  webhook. The root row is read with its id AND the delivery owner's user id,
  so an entity that is not the owner's is "not found"; children are read under
  ids from that read. Fields are the GDPR manifest's columns minus the owner
  id and an explicit omit list. A missing or soft-deleted row is
  `<entity>.deleted` with the id only. Loads are per cable as stored (KD-8).
- deliver-webhooks: x-cron-secret or service-role bearer, else 401. Small
  batches so a pass never holds work it cannot finish; the endpoint, its
  secrets and the entity are each read with the user id from the claimed row.
  A scope removed after capture, an inactive endpoint or a non-shareable row
  is skipped, never sent. Retries, backoff, the FLAME check and auto-disable
  stay in SQL.
- Real-SQL integration test: two users' routines reach only their own
  receivers, a lapsed owner's endpoint is paused instead, and a hard delete
  arrives as a deleted event.

Verified by mutation: without the owner filter in the payload builder the
isolation tests fail.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…uide

Profile > Settings > Data Sharing: add, edit, pause, test, resend, replace the
secret of and delete outbound webhook endpoints.

- The card sits on a route with no tier gate so a lapsed user can still see
  where their data went and pause or delete it. Adding, editing and switching
  on need Flame (FEATURE_MIN_TIER.dataSharing); the server enforces it. A
  billing outage disables changes without telling a paying user to upgrade.
- Every write is one webhook-endpoints action and sends no user id. Reads use
  owner RLS on webhook_endpoints / webhook_deliveries. The signing secret is
  shown once and held only in component state.
- Server refusals surface with the server's own message (URL not allowed,
  limit reached, failed test delivery); 402 goes through isTierDenied.
- Form checks mirror the server for instant feedback but stay no stricter
  than it; the host and address checks remain server-only.
- Privacy policy: user-directed sharing added to the legal bases, section 8
  and international transfers, with a new effective date.
- docs/data-sharing-webhooks.md (receiver guide with verification), operator
  runbook section, dataSharingScopes.ts reviewed into the SPA-reachable list.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…new functions

The audit report is historical and never covered webhook-endpoints or
deliver-webhooks. The addendum says so and points to where their security
model and the SSRF residual risk are stated; it records no findings.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 17:51
@gitguardian

gitguardian Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 8 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
39754956 Triggered Stripe Webhook Secret 32ad07e supabase/functions/webhook-endpoints/index.test.ts View secret
39754956 Triggered Stripe Webhook Secret 32ad07e supabase/functions/_shared/webhookSigning.test.ts View secret
39754956 Triggered Stripe Webhook Secret 32ad07e supabase/functions/_shared/webhookSend.test.ts View secret
39754955 Triggered Generic High Entropy Secret 32ad07e supabase/functions/webhook-endpoints/index.test.ts View secret
39754955 Triggered Generic High Entropy Secret 32ad07e supabase/functions/_shared/webhookSend.test.ts View secret
39754955 Triggered Generic High Entropy Secret 9f6c1a4 supabase/functions/deliver-webhooks/index.test.ts View secret
39754956 Triggered Stripe Webhook Secret 9f6c1a4 supabase/functions/deliver-webhooks/index.test.ts View secret
39754956 Triggered Stripe Webhook Secret 0361508 src/app/components/tests/DataSharingSection.test.tsx View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

9thLevelSoftware and others added 5 commits November 6, 2026 12:54
GitGuardian flagged the whsec_ literals in the new test files as webhook
secrets. They were not credentials: one is the Standard Webhooks
specification's published example key, the other a second documentation
example used as a fixture. A scanner cannot tell that, and a scanner that
cries wolf gets ignored, so no secret-shaped literal is committed any more.

- Fixtures come from _shared/testing/webhookSecrets.ts (whsec_ + base64 of 32
  identical bytes, built at runtime).
- The reference vector is kept, because it is what proves interoperability;
  its public key is assembled from parts with a comment saying why.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Same change as on the webhook-endpoints branch, for the deliver-webhooks
test: no secret-shaped literal is committed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The component test and the E2E mock used whsec_ strings long enough to look
like a real webhook secret to a scanner. Nothing verifies them, so they are
now plainly fake.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
phoenix-portal b0aa56a Commit Preview URL

Branch Preview URL
Nov 06 2026, 07:14 PM

9thLevelSoftware and others added 10 commits November 6, 2026 13:03
- The registry and the capture triggers could drift: a trigger's arguments
  are frozen when it is created. Trigger creation is now
  private.sync_webhook_capture_triggers(), which a later migration calls
  after editing private.webhook_entity_sources and which also removes capture
  triggers from tables that are no longer a source. pgTAP fails when a
  trigger's arguments differ from its row (verified by editing a row without
  rebuilding). The header no longer claims they cannot drift.
- The "does any active endpoint share this scope" probe ran on every write to
  a shared table with no index to use. Added a partial GIN index on scopes and
  switched the probe to @> so it can use it.
- sets and rep_summaries are payload children with no capture trigger. That is
  sound today (no browser role can write them, and every server writer
  rewrites exercises in the same call) but was neither stated nor tested. It
  is now documented, marked capturedThrough in dataSharingScopes.ts, checked
  in both directions by the parity test, and guarded by a pgTAP assertion on
  the grants.
- The profile omit list (stripe_customer_id and two internal columns) is now
  asserted, not only checked for existence.
- set_webhook_endpoint_header's two header arguments DEFAULT NULL, matching
  how they are used and the generated types.

Not changed: the pgTAP floor finding (the suite count is what the CI job
measured), and the endpoint-limit finding (endpoints are deleted through the
webhook-endpoints function in the next PR).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- A previous signing secret that cannot be decrypted no longer stops every
  delivery: it only smooths a rotation, so deliveries go out signed with the
  current secret alone.
- DNS resolution has its own 5 s deadline. The request timeout only starts
  with the fetch, so a resolver that hung could hold a delivery and the
  worker pass it belongs to.
- The Supabase test double returned deleted rows whether or not the caller
  asked for them. It now matches PostgREST, so dropping `.select()` from a
  delete (a 404 on success in production) would fail the suite.
- Tests: webhookCredentials gets its own file (rotation overlap, unreadable
  secrets, owner scoping); the tier gate is covered for rotate, test and
  resend as well as create and update.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…-worker

# Conflicts:
#	CLAUDE.md
#	supabase/config.toml
Base automatically changed from feat/deliver-webhooks-worker to main November 6, 2026 19:11
@kilo-code-bot

kilo-code-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

This review did not run. Your provider API key hit its rate limit, so the
request was rejected before the review started. Kilo does not retry
automatically, because the quota is your provider's; push a new commit once it
resets. Any inline comments below are from an earlier review.

@9thLevelSoftware
9thLevelSoftware merged commit f253cfb into main Nov 6, 2026
16 of 27 checks passed
@9thLevelSoftware
9thLevelSoftware deleted the feat/data-sharing-ui branch November 6, 2026 22:58
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