← Back to Pull requests

Seal Sealed values in the browser (SL7) #3304

Closed
unknown closed this pull request without merging on Oct 24, 2026 02:35 UTC
View on GitHub
unknown unknown commented on Oct 23, 2026 16:57 UTC
Author

SL7 of Sealed variables level A.

Summary

While an Organization has sealed variables on, the dashboard seals each Sealed value in the browser before the write leaves the page. The Config Store receives ciphertext for the Service it lands in and stores it as it came. No daemon is involved. With the flag off, the dashboard sends trunk's legacy write byte for byte, and no real Organization has the flag, so nobody notices yet.

sequenceDiagram
    participant B as Browser
    participant C as Cloud
    participant S as Config Store
    B->>C: readSealingFn (fresh, no cache)
    C-->>B: off | no_server | ready{publicKey, organizationId}
    alt off
        B->>S: legacy write (as trunk)
    else no_server or read failed
        B-->>B: refuse, keep what was typed
    else ready
        B->>B: HPKE seal to that read's publicKey, AAD = org, env, service, key
        B->>S: {secret:{sealedFor, value:{sealed, scope:{service}, key}}}
    end

every Sealed submission (add form, row edit, Set value, raw editor, Sync, On merge)
  sealer = one fresh readSealingFn            // never the page's cached state
  off        -> legacy plaintext write
  no_server  -> "Add a server to set sealed values."
  error      -> "Couldn't save this sealed value, so nothing was saved. Try again."
  ready      -> seal with that read's key
a plain (Text) write makes no read at all

What ships.

  • Seal. modules/variables/seal-value.ts (not .client., which TanStack Start keeps out of the server build): RFC 9180 base mode, DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20-Poly1305, info ployz-sealed-v1, wire enc ‖ ct in base64. AAD binds Organization id, Environment, Service and key. @hpke/core, @hpke/chacha20poly1305 and @hpke/dhkem-x25519 join dashboard/package.json.

  • Writes. store-write gains a lazy prepare, so a mutation seals at submit time and its optimistic cache only ever holds a redacted change. useSealing binds the sealer to the key from the same fresh read.

  • Surfaces.

  • - The add form, the row's Set value and the edit seal.
    - In the raw editor, a line ticked Sealed goes Sealed, as a create or an update, even when another tab made its key plain while the editor was open. A Sealed variable it omits is never a delete.
    - Sync and On merge seal for the receiving Service, read afresh at the moment of each send. In a Sync, a Service that is new there arrives as Not set, with "Set this value after syncing." An On merge Edit for such a Service is refused with "Set this value after merging." and reopens on what was typed.
    - Any refused Sealed write keeps what was typed: the add form, the row edit, the raw editor and On merge reopen on it.
  • Agent. An agent write that carries a browser-sealed value, or a secret's value as text, is refused before any approval or Store call.

  • Rust. core/crates/ployzd/src/sealing_key.rs gains a test that opens a vector sealed by seal-value with the daemon's opener. This is the only change outside dashboard/ and docs/user/.

  • Docs. docs/user/services/variables.md, environments/environments.md and environments/preview-environments.md each gain a line that holds whether sealing is on or off. None of them promise sealing.
  • The first commit, 686f82827 ("Read whether an Organization seals on the client, and to which key"), is SL8's shared reader, and it matches SL8's byte for byte. Whichever PR merges second drops it.

    Bets

  • 7, Cloud drives, never owns. The choice it changed: Cloud stores the ciphertext the browser sends and holds no key that opens it. readSealingFn returns only a public key and an Organization id.

  • 10, Client-first, daemon when forced. The choice it changed: the browser seals with the Cluster's public key, so a write makes no daemon call. Only the Machine that runs the Service opens the value.
  • Rulings carried

  • Off at submit sends trunk's legacy write. Only the operator turns an Organization off, and off means level A isn't promised. If the flag is off at the moment of submit, a Sealed save is plaintext, exactly as trunk.

  • Fresh key. Every sealed submission seals with the public key from that same fresh read, never from the page's cached ready state, so a rotated or re-founded key is never used stale.

  • Raw editor omission. Leaving a Sealed placeholder line out of a raw-editor save never reads as a delete, downstream included. Covered by tests.

  • Support. Support holds the admin set and can write variables on trunk, so it reads the sealing state like a member does. Its Sealed writes seal, or go legacy when the flag is off, as a member's would.
  • Known gaps

  • Flag-flip race (moves to SL10). If the operator turns an Organization off between the fresh read and the Store write, the Store takes the legacy plaintext. SL10 closes this: once Cloud's opening path is gone, the Store refuses every plaintext secret. SL7 builds no Store precondition.

  • Fetch join. fetchQuery({staleTime: 0}) can join a read already in flight that began just before submit. The window is one request's round trip. It is the same class of race as the one above.

  • On merge retry. set_merge_value carries no id, so a retried On merge seals again instead of reusing the first ciphertext.

  • Sync retry keeps its id. Every try reads sealing afresh. A retry after a lost response resends what it sent only while that read returns the key it sealed to (or off, if it went legacy). Otherwise it prepares again under the same Sync id. The Store answers a repeated id from its record and ignores the body (branch/sync.rs request.id == found.last_sync). So a Sync that landed is answered, not run twice, and one that didn't runs once with the new body. A legacy Sync that landed stays legacy: sealing was off when it was sent. A refused Sync rolls back, so its next try seals afresh.

  • Trunk leak fixed here. The raw editor's JSON error used to show JSON.parse's message, which quotes the text ("{"E":rvw1234}" is not valid JSON), and session replay recorded it. Plain values leaked this way on trunk too. The error is now "Invalid JSON.", with the line and column only from V8's closing (line L column C), never from the quoted text, so plain and sealed values are both covered. The .env path already named only the line.

  • Trunk copy carried to SL10. The Sync dialog's "Secret" badge and the long Seal Variable confirm stay as on trunk.

  • Unpaired surrogates. A plain value, or a {secret} the Store seals, keeps U+FFFD in its place: the Store takes abc\uD800def and saves abc\uFFFDdef (probe through writeStoreAsMember and the native SDK, read back from config_environment.working). A browser-sealed value refuses it with "A value can't hold an unpaired surrogate.", since the browser's UTF-8 would seal U+FFFD in place of what was typed. Trunk's plain behaviour is unchanged.
  • Evidence

    At 3181726e2, rebased on main 67025ee3e (#3098). The 31 commits keep their patch-ids. One commit on top gives the cluster-sealing test's key report AppConfig, which recording a Sealing Key reads since #3098; the reader is unchanged. The postgres tests for cluster sealing, store variables, the agent runner and organization ownership pass (30). pnpm typecheck and oxlint on the changed files are clean. Vitest passes for -components/sync, src/modules/variables, store-variables, the raw editor and data-boundaries.static.test.ts. pnpm build exits 0.

    Unit, at e341d3a5a.

  • tsc --noEmit and pnpm lint are clean.

  • Focused vitest: 16 files, 203 tests. That covers store-variables (and its parity file), store-write, src/modules/variables, Sync and On merge, the raw editor and src/components/variables.

  • The plan's unit commands also pass:

  • - --project unit on seal-value.test.ts plus src/modules/agent: 191 tests.
    - --project postgres on store-variables.postgres.test.ts plus src/modules/sealing: 4 tests.
  • Rust: ployzd sealing_key::tests::a_value_the_browser_sealed_opens_only_for_the_variable_it_was_sealed_as opens the vector seal-value sealed. ployzd doesn't build on macOS (inotify needs kcmp), so this test runs only in CI rust-tests, where it passes (daemon shard, e341d3a5a). real-wait-lint, run locally as rust-lint runs it, exits 0.

  • GitGuardian flags RECIPIENT_PRIVATE_KEY in seal-value.test.ts. That key is a test vector shared with the Rust test and seals nothing real. It needs to be marked a false positive in GitGuardian, and it isn't a required check.
  • Parity: the Store's checks on a plain value, and where a browser-sealed value meets each. The Store can't read ciphertext, so sealedValueProblem (seal-value.ts) runs before sealing.

    | Store check on a plain value | Browser-sealed value |
    | --- | --- |
    | Key: at most 128 characters, letters, digits and _, not starting with a digit, uppercased (VariableKey::parse) | Moot: the key stays cleartext, and the Store parses it on every path |
    | Reserved names (refuse_reserved) | Moot: the Store, every path |
    | PORT | Refused in the browser, and by the Store (client_sealed::accept, refuse_port) |
    | Null character (validate_text) | Refused in the browser |
    | 128 KiB including the name (too_long) | Refused in the browser, and by the Store from the ciphertext's length |
    | Empty secret ({"secret": ""} refused) | Refused in the browser. Add waits for a value rather than calling an empty field a problem |
    | Unpaired surrogate | The plain path saves U+FFFD (see Known gaps). Refused in the browser |
    | ${{ references, unterminated or unresolved | Plain only. A sealed value is stored as typed, so the browser refuses ${{ |
    | Multiline rows under 6 characters | Refused in the browser, and by the Server at deploy (sealed_env.rs) |
    | Typed address hints | Advisory, not a refusal. None for ciphertext |
    | Environment, Service and key binding, Shared scope, flag on | The Store (client_sealed::accept) |

    Regression tests for the swarm findings at e341d3a5a. Each was seen failing before its fix.

  • Raw editor, Sealed follows the line. Another tab makes the ticked key plain while the editor is open, with another value and with the same value. The line still goes Sealed as an update, and neither the changes nor prepare's output carries the plaintext.

  • Sync retry after a lost legacy send. Sealing is off on the first try, its response is lost, and sealing turns on. The retry reads afresh, sends the value sealed for production's api, and keeps the Sync id.

  • Parity. sealedValueProblem refuses a null character, an empty value and an unpaired surrogate, and takes a surrogate pair.

  • Agent gate. agent-gate.test.ts drives runGated with a gated Store write carrying a browser-sealed value, a secret's value as text, and a sealed value in a Sync. Each is refused invalid_argument and the Store is never opened. With the refusal nulled, all three reach the Store. No compiled gated tool writes a secret today, so only a direct drive reaches this seam.

  • Raw editor JSON error. variable-raw-editor.test.ts gives {"E":rvw1234}, the text line 7 column 8, a missing comma and a raw newline in a string, and asserts each exact message. With the fix reverted, the first receives the value in its text. With the position matched anywhere in the message, line 7 column 8 shows the user's digits as the position.

  • Trunk pins compare shown views in any order. The writer lists the views a write shows newest first by the millisecond each was last answered, so on a busy run the On merge Reset's branch and on_merge swapped and its pin failed (2 of 8 parallel runs). anyOrderShows sorts shows on both sides of the On merge and Sync pins. Every other byte stays pinned. 16 of 16 pass under the same load.

  • Static data boundaries. On merge joins COMMAND_FILES: "an On merge Edit shows at once; the row watches its answer only to reopen a refused Edit on what was typed".
  • Regression tests for the interrogate findings.

  • Raw editor. A key ticked Sealed while the cached state is ready still goes through the write's fresh read if the cache turns off or no_server before submit. The box stays ticked and the edit never shows the plaintext. This test was seen failing on the old code first.

  • On merge. The cached state is off, the fresh read is ready, and the Service is new in the Destination. The write is refused with "Set this value after merging.", nothing is sent, and Edit reopens on the typed value. Save is disabled while a secret is empty.

  • Sync. After a refusal it seals afresh. After a lost response it resends the same bytes while a fresh read returns the same key.

  • receivingValues. The key comes from the RowId (lineage:variables.KEY). A non-variable row throws. The value is dropped or refused when its Service is missing.
  • Live, verify-dashboard.

  • The head session ran with sealedVariables set only for the lane-created test Organization ada (009b6cda-0d8a-4965-ae7a-7ab6ea6b94b8) in the throwaway verify Postgres ployz-verify-eb0fe4baf7, with a locally generated test key.

  • Screens: no-server.png, seal-dialog.png, staged-sealed.png.

  • The head write body carries sealedFor ciphertext and no plaintext. Trunk sends {secret: value} as before.

  • Lanes that need real Machines (deploy, servers offline, Branch Sync deploy) could not run on this Mac (setsid, strip, inotify). They are left to the swarm's Linux lanes.
  • Perf.

  • Method: 20 interleaved sealed adds per side on the Variables tab, with both pages visible.

  • Click Add to row shown: trunk median 302 ms, head median 324 ms. That is +22 ms against a rule that fails above +100 ms. Pass.

  • The seal call alone: median 0.7 ms against a 50 ms rule. Pass.

  • Click to the write's answer: 545 ms on trunk and 712 ms on head (+167 ms). The difference is the fresh sealing read before the write.

  • An earlier head run read about 1 s, but the head tab was hidden and its timers throttled, so that run was discarded.
  • Media

    Recorded at 3e0f1ce20 by the swarm's media lane, in /tmp/swarm-3304/media/ (WebM flow, PNG end state).

    1. flow1-add-sealed.webm / .png: add a sealed variable.
    2. flow2-set-value.webm / .png: set a value on a Not set row.
    3. flow3-seal-from-menu.webm / .png: seal a plain variable from the row menu.
    4. flow4-raw-editor.webm / .png: the raw editor, and its JSON error with a position and no typed text.
    5. flow5-branch-sync.webm / .png: a Branch Sync, with one value arriving Not set.
    6. flow6-no-server.webm / .png, flow6-no-server-seal-menu.png: with no Server, the add dialog greyed out and the menu seal's toast.

    Merge Danger

    Door: two-way

    The legacy path is unchanged. The only new behaviour runs while an Organization has sealedVariables, and no real Organization does. Reverting the PR leaves stored ciphertext the Store already accepts from SL2's CLI path.

    Blast Radius: variables

    Every variable write now goes through prepare. A bug there would block saves, not corrupt them, because a refused seal keeps what was typed and never falls back to plaintext while the flag is on.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: nick-potts Review duration: 577m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3304"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository