console: the shared config writer validates its own input
writeConfig now takes the wire input and runs checkConfigEnvironment and checkConfigSets itself, so only checked, field-built vars reach the seal check and the store. Direct writer tests cover plaintext on a secret, a malformed envelope, an envelope on an env var and a wrong-key secret at want nil and at version, asserting no bundle or generation write. The default-bundle-only guard also rejects ApplyAtVersion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/configwrite.go+21 −4internal/console/configwrite_test.go+81 −13internal/console/teamcreds_test.go+5 −4
Intent
<task-notification> <task-id>a30f707594acd3b8b</task-id> <tool-use-id>toolu_01LcKmfPbhWaRP89xb8MvkPd</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/a30f707594acd3b8b.output</output-file> <status>completed</status> <summary>Agent "Implement Task 6 browser sealing" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: all three Astra P1s are fixed and committed in 2d60722d (only my files: configseal.js, configseal_test.go, configseal_run.mjs and the new configseal_browser.mjs). - **P1-1 and P1-2:** each submit is now one frozen transaction. Values are copied before the first await and exactly those are validated and sealed. The form is inert while sealing, any change cancels it with a new "changed" message, and it won't submit while a selected secret still has named plaintext. - **P1-3:** every resubmit waits until the original submit event finishes and keeps the button pressed, so Remove and Discard post on the first click. - **Tests:** the new regressions are mid-seal tick, mid-seal edit to a forbidden value, a double click while sealing, and a headless Chromium run (Remove, Discard, Save each post exactly once; Save posts only envelopes, which open in Go). Each fails against the old code or a targeted mutation. - **Result:** `go test ./internal/console -run 'ConfigSeal|ConfigValue|BrowserSeal|OnlySealKey' -count=1` passes (22.3s); vet and gofmt are clean. - **Concerns:** the "changed" message is new copy for the Task 9 pass. The other implementer's uncommitted console files broke the package build for a while; the final run built on their current tree. Fix report appended to .superpowers/sdd/2026-11-08-console-secrets/task-6-report.md</result> <usage><subagent_tokens>136899</subagent_tokens><tool_uses>23</tool_uses><duration_ms>1071332</duration_ms></usage> </task-notification>
<task-notification> <task-id>bb4wt42fn</task-id> <tool-use-id>toolu_01GKuXFDuZdTJSdEptpKghRE</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/bb4wt42fn.output</output-file> <status>completed</status> <summary>Background command "until [ -f .superpowers/sdd/2026-11-08-console-secrets/astra-t2t4.done ]; do sleep 30; done; tail -2 .superpowers/sdd/2026-11-08-console-secrets/astra-t2t4-findings.md" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bqmvssl8w</task-id> <tool-use-id>toolu_01MXnZXEEpoh9bMnsfaLGGpm</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/abe35d56-e4c2-40df-9005-6e66b76b1f50/tasks/bqmvssl8w.output</output-file> <status>completed</status> <summary>Background command "until [ -f .superpowers/sdd/2026-11-08-console-secrets/astra-t6-r2.done ]; do sleep 30; done; tail -2 .superpowers/sdd/2026-11-08-console-secrets/astra-t6-r2-findings.md" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 4.42 g CO₂e (549,310 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-console-secrets, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/configwrite.go b/internal/console/configwrite.go| index e2dedb887..a2d9a12c4 100644 |
| --- a/internal/console/configwrite.go |
| +++ b/internal/console/configwrite.go |
| @@ -175,14 +175,28 @@ func checkConfigSets(in map[string]configVarIn) ([]string, map[string]appconfig. |
| return keys, sets, nil |
| } |
| -// writeConfig writes one bundle's sets and unsets: the account lock when a |
| +// writeConfig writes one bundle's sets and unsets: the environment and var |
| +// checks (checkConfigEnvironment, checkConfigSets), the account lock when a |
| // secret is set, the seal check under it, the store write (Apply or |
| // ApplyEnvironment when want is nil, ApplyAtVersion at want otherwise), and |
| -// the unlock after it. keys and sets are checkConfigSets' answer. Audit and |
| -// bumpSerial are the door's: each names itself in the trail. |
| +// the unlock after it. Audit and bumpSerial are the door's: each names |
| +// itself in the trail. |
| +// |
| +// It takes the wire input, not built vars, and validates it itself: only |
| +// checkConfigSets' keys and vars ever reach the seal check and the store, so |
| +// no caller can skip validation, the sealed_to check or the field-by-field |
| +// construction by handing in vars of its own. A door that also checks early |
| +// (the JSON door, for its refusal order) passes the same map. |
| // |
| // A write with nothing to set or unset writes nothing and is not refused. |
| -func (s *Server) writeConfig(ctx context.Context, acct *Account, app, envName string, want *appconfig.BundleVersion, keys []string, sets map[string]appconfig.Var, unset []string) (removed int, ref *configRefusal) { |
| +func (s *Server) writeConfig(ctx context.Context, acct *Account, app, envName string, want *appconfig.BundleVersion, in map[string]configVarIn, unset []string) (removed int, ref *configRefusal) { |
| + if ref := checkConfigEnvironment(envName); ref != nil { |
| + return 0, ref |
| + } |
| + keys, sets, ref := checkConfigSets(in) |
| + if ref != nil { |
| + return 0, ref |
| + } |
| unlock, ref := s.configWriteBegin(ctx, acct, app, keys, sets, false) |
| defer unlock() |
| if ref != nil { |
| @@ -196,6 +210,9 @@ func (s *Server) writeConfig(ctx context.Context, acct *Account, app, envName st |
| // configWriteBundle is configWriteStore over the bundle's own write: Apply |
| // or ApplyEnvironment when want is nil, ApplyAtVersion at want otherwise. |
| +// sets must be checkConfigSets' answer and the caller must hold |
| +// configWriteBegin's lock: writeConfig, and the JSON door after its own |
| +// checkConfigSets call, are its only callers. |
| func (s *Server) configWriteBundle(ctx context.Context, unlock func(), acct *Account, app, envName string, want *appconfig.BundleVersion, sets map[string]appconfig.Var, unset []string) (int, *configRefusal) { |
| return s.configWriteStore(ctx, unlock, acct, app, envName, func(ctx context.Context) (int, error) { |
| switch { |
diff --git a/internal/console/configwrite_test.go b/internal/console/configwrite_test.go| index 7788760f6..f05c48c58 100644 |
| --- a/internal/console/configwrite_test.go |
| +++ b/internal/console/configwrite_test.go |
| @@ -147,13 +147,9 @@ func TestWriteConfigNeverEchoesContent(t *testing.T) { |
| t.Fatalf("account: %v %v", acct, err) |
| } |
| ctx := context.Background() |
| - write := func(app, envName string, want *appconfig.BundleVersion, sets map[string]appconfig.Var, unset []string) *configRefusal { |
| + write := func(app, envName string, want *appconfig.BundleVersion, in map[string]configVarIn, unset []string) *configRefusal { |
| t.Helper() |
| - keys := make([]string, 0, len(sets)) |
| - for n := range sets { |
| - keys = append(keys, n) |
| - } |
| - _, ref := fx.srv.writeConfig(ctx, acct, app, envName, want, keys, sets, unset) |
| + _, ref := fx.srv.writeConfig(ctx, acct, app, envName, want, in, unset) |
| if n := acctLockHolders(fx.srv, acct.Sqid); n != 0 { |
| t.Fatalf("account lock held by %d after writeConfig", n) |
| } |
| @@ -163,16 +159,14 @@ func TestWriteConfigNeverEchoesContent(t *testing.T) { |
| v1 := skSeal(t, fx, k.pub, false) |
| depPub, depFP := mustTestSecretsKey() |
| wrong := skSeal(t, fx, depPub, true) |
| - secret := func(env, fp string) map[string]appconfig.Var { |
| - return map[string]appconfig.Var{"API_KEY": {Kind: "secret", Envelope: env, SealedTo: fp}} |
| - } |
| + secret := cwSecret |
| got = append(got, |
| outcome{"sealed unchecked", write("shop", "", nil, secret(v2, ""), nil), configRefusalSealedUnchecked, []string{v2}}, |
| outcome{"sealed wrong key (fleet)", write("shop", "", nil, secret(wrong, depFP), nil), configRefusalSealedWrongKey, []string{wrong}}, |
| outcome{"sealed old", write("shop", "", nil, secret(v1, k.fp), nil), configRefusalSealedOld, []string{v1}}, |
| outcome{"not found", write("ghost", "", nil, secret(v2, k.fp), nil), configRefusalNotFound, []string{v2}}, |
| outcome{"seal key", func() *configRefusal { |
| - _, ref := fx.srv.writeConfig(ctx, &Account{Sqid: "zzzz"}, "shop", "", nil, []string{"API_KEY"}, secret(v2, k.fp), nil) |
| + _, ref := fx.srv.writeConfig(ctx, &Account{Sqid: "zzzz"}, "shop", "", nil, secret(v2, k.fp), nil) |
| return ref |
| }(), configRefusalSealKey, []string{v2}}, |
| outcome{"nothing to remove", write("shop", "", nil, nil, []string{"GONE"}), configRefusalNothingToRemove, nil}, |
| @@ -186,7 +180,7 @@ func TestWriteConfigNeverEchoesContent(t *testing.T) { |
| t.Fatal(err) |
| } |
| stale := appconfig.BundleVersion{} |
| - plain := map[string]appconfig.Var{"PORT": {Kind: "env", Value: cwMarker}} |
| + plain := map[string]configVarIn{"PORT": {Kind: "env", Value: cwMarker}} |
| got = append(got, outcome{"conflict", write("shop", "", &stale, plain, nil), configRefusalConflict, []string{cwMarker}}) |
| if ref := write("shop", "", &ver, plain, nil); ref != nil { |
| t.Fatalf("write at the current version refused: %+v", ref) |
| @@ -208,9 +202,9 @@ func TestWriteConfigNeverEchoesContent(t *testing.T) { |
| t.Fatal(err) |
| } |
| wrong2 := skSeal(t, fx2, skNewKey(t).pub, true) |
| - _, ref := fx2.srv.writeConfig(ctx, acct2, "shop", "", nil, []string{"API_KEY"}, secret(wrong2, depFP), nil) |
| + _, ref := fx2.srv.writeConfig(ctx, acct2, "shop", "", nil, secret(wrong2, depFP), nil) |
| got = append(got, outcome{"keyless fleet", ref, configRefusalKeylessFleet, []string{wrong2}}) |
| - _, ref = fx2.srv.writeConfig(ctx, acct2, "plat", "", nil, []string{"API_KEY"}, secret(wrong2, "not-the-deployment-key"), nil) |
| + _, ref = fx2.srv.writeConfig(ctx, acct2, "plat", "", nil, secret(wrong2, "not-the-deployment-key"), nil) |
| got = append(got, outcome{"sealed wrong key (platform)", ref, configRefusalSealedWrongKey, []string{wrong2}}) |
| seen := map[configRefusalCode]bool{} |
| @@ -244,3 +238,77 @@ func TestWriteConfigNeverEchoesContent(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// cwSecret is one sealed var, API_KEY, in the wire shape. |
| +func cwSecret(env, fp string) map[string]configVarIn { |
| + return map[string]configVarIn{"API_KEY": {Kind: "secret", Envelope: env, SealedTo: fp}} |
| +} |
| + |
| +// TestWriteConfigValidatesItsInput: the shared writer runs the checks |
| +// itself, so a caller that never called checkConfigSets still cannot store |
| +// plaintext on a secret, a malformed envelope, an envelope on an ordinary |
| +// var, or a secret sealed to the wrong key. Each refusal leaves the bundle |
| +// and the generation object exactly as they were, at want nil and at the |
| +// bundle's current version. |
| +func TestWriteConfigValidatesItsInput(t *testing.T) { |
| + fx, _, k := skFleetShop(t, "code-cw-validates", true) |
| + acct, err := fx.st.AccountBySqid(fx.sqid) |
| + if err != nil || acct == nil { |
| + t.Fatalf("account: %v %v", acct, err) |
| + } |
| + ctx := context.Background() |
| + good := skSeal(t, fx, k.pub, true) |
| + if _, ref := fx.srv.writeConfig(ctx, acct, "shop", "", nil, cwSecret(good, k.fp), nil); ref != nil { |
| + t.Fatalf("seed write refused: %+v", ref) |
| + } |
| + depPub, depFP := mustTestSecretsKey() |
| + wrong := skSeal(t, fx, depPub, true) |
| + etags := func() (bundle, gen string) { |
| + t.Helper() |
| + _, ver, err := appconfig.GetBundle(ctx, fx.rel, fx.sqid, "shop", "") |
| + if err != nil || !ver.Found { |
| + t.Fatalf("bundle: %+v %v", ver, err) |
| + } |
| + _, gen, err = fx.rel.Get(ctx, appconfig.GenKey(fx.sqid, "shop")) |
| + if err != nil { |
| + t.Fatalf("generation: %v", err) |
| + } |
| + return ver.ETag, gen |
| + } |
| + cases := []struct { |
| + name string |
| + in map[string]configVarIn |
| + code configRefusalCode |
| + }{ |
| + {"plaintext on a secret", map[string]configVarIn{"API_KEY": {Kind: "secret", Envelope: good, SealedTo: k.fp, Value: "hunter2"}}, configRefusalSecretPlaintext}, |
| + {"malformed envelope", cwSecret("not base64 at all!!", k.fp), configRefusalSecretEnvelope}, |
| + {"envelope on an ordinary var", map[string]configVarIn{"PORT": {Kind: "env", Value: "8080", Envelope: good}}, configRefusalEnvEnvelope}, |
| + {"secret sealed to the wrong key", cwSecret(wrong, depFP), configRefusalSealedWrongKey}, |
| + } |
| + for _, c := range cases { |
| + for _, atVersion := range []bool{false, true} { |
| + bundle0, gen0 := etags() |
| + var want *appconfig.BundleVersion |
| + if atVersion { |
| + want = &appconfig.BundleVersion{Found: true, ETag: bundle0} |
| + } |
| + _, ref := fx.srv.writeConfig(ctx, acct, "shop", "", want, c.in, nil) |
| + if ref == nil || ref.Code != c.code { |
| + t.Fatalf("%s (at version %v): refusal = %+v, want %s", c.name, atVersion, ref, c.code) |
| + } |
| + if bundle, gen := etags(); bundle != bundle0 || gen != gen0 { |
| + t.Fatalf("%s (at version %v): bundle %s -> %s, generation %s -> %s; a refusal wrote", c.name, atVersion, bundle0, bundle, gen0, gen) |
| + } |
| + } |
| + } |
| + m := skStored(t, fx) |
| + if len(m.Vars) != 1 || m.Vars["API_KEY"] != (appconfig.Var{Kind: "secret", Envelope: good, SealedTo: k.fp}) { |
| + t.Fatalf("stored = %+v, want only the seed", m.Vars) |
| + } |
| + // A valid write at the version just read lands: the refusals above are |
| + // the checks, not a writer that never writes. |
| + bundle0, _ := etags() |
| + if _, ref := fx.srv.writeConfig(ctx, acct, "shop", "", &appconfig.BundleVersion{Found: true, ETag: bundle0}, map[string]configVarIn{"PORT": {Kind: "env", Value: "8080"}}, nil); ref != nil { |
| + t.Fatalf("valid write at version refused: %+v", ref) |
| + } |
| +} |
diff --git a/internal/console/teamcreds_test.go b/internal/console/teamcreds_test.go| index ec7b6a13f..8c65f24df 100644 |
| --- a/internal/console/teamcreds_test.go |
| +++ b/internal/console/teamcreds_test.go |
| @@ -433,11 +433,12 @@ func TestApplyCallersAreTheKnownWalks(t *testing.T) { |
| if strings.Join(consoleGot, "\n") != strings.Join(consoleWant, "\n") { |
| t.Errorf("console callers of appconfig writers =\n%s\nwant\n%s", strings.Join(consoleGot, "\n"), strings.Join(consoleWant, "\n")) |
| } |
| - // The two default-bundle-only callers write through Apply and never |
| - // ApplyEnvironment: the scan secret and the mail-events key are not |
| - // delivered to an owned environment. |
| + // The default-bundle-only callers write through Apply and never |
| + // ApplyEnvironment, ApplyEnvironmentOwned or ApplyAtVersion (which |
| + // takes an environment): the scan secret and the mail-events key are |
| + // not delivered to an owned environment. |
| for _, file := range []string{"internal/console/apimail.go", "internal/console/scankeysync.go", "internal/console/apiscan.go"} { |
| - if callers[file]["ApplyEnvironment"] || callers[file]["ApplyEnvironmentOwned"] { |
| + if callers[file]["ApplyEnvironment"] || callers[file]["ApplyEnvironmentOwned"] || callers[file]["ApplyAtVersion"] { |
| t.Errorf("%s writes a named environment; §3a delivers its value to the default bundle only", file) |
| } |
| } |