fix(workapi): refuse YamlOnlyKey writes through the settings HTTP surface

bd config set already refuses a write to a YamlOnlyKey (startup flags
and the tracker secrets: github.token, linear.api_key, jira.api_token,
gitlab.token, ado.pat) via config.IsYamlOnlyKey at its own door. The
other door onto the same plane — the settings HTTP surface bd serve
and its dashboard expose, PUT /v0/beads/config/{key}, which reaches
ValidateSettingWrite through internal/storage/uow and
internal/workapi/storeworkspaceconfig — had no such rule. A secret PUT
through it landed as a plain row in the Dolt config table, which is
synced (bd dolt push/pull, DOLT_CLONE, DOLT_PULL replicate it), so the
secret reached every remote on the next push.

Add the same config.IsYamlOnlyKey check to ValidateSettingWrite,
following the precedent already set there for issue_prefix ("refused
here rather than at the front door because bd config set is not the
only door that reaches this plane"). The check is unconditional, not
narrowed to secrets: a non-secret YamlOnlyKey succeeding through this
door is the same GH#536 class of bug the map exists to prevent (a
write that reports success but that no reader ever consults).

The error only echoes the key, never the submitted value.

Fixes gastownhall/beads#7559

Verified: go build/vet clean; the new test fails against the unfixed
file (confirmed via git stash) and passes restored; the existing
internal/workapi suite (9 prior tests, including the two filters that
share this file) is unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VN2SgXAHW1eTB1izwWwmyr
This commit is contained in:
Rongjun GENG 2026-10-15 04:51:00 -07:00
commit 80f0220ae1
2 changed files with 47 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage/kvkeys"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
@ -42,6 +43,21 @@ func ValidateSettingWrite(key, value string) (string, error) {
if _, err := ValidateSettingKey(key); err != nil {
return "", err
}
// config.YamlOnlyKeys — startup settings and the tracker secrets
// (github.token, linear.api_key, jira.api_token, gitlab.token, ado.pat) —
// must live in the workspace's local config.yaml, never in this plane's
// row-per-key storage: that storage is the Dolt config table, which is a
// SYNCED table (bd dolt push/pull, DOLT_CLONE, DOLT_PULL all replicate
// it). `bd config set` already refuses these at its own door; this is
// the only other door onto this plane (the settings HTTP surface bd
// serve and its dashboard expose), and it had no such rule, so a secret
// PUT through it landed in the synced table and reached every remote on
// the next push (GH#7559).
if config.IsYamlOnlyKey(key) {
return "", fmt.Errorf("%w: %q must be set in the workspace's local config.yaml (bd config set %s <value>), not written here: "+
"this plane is the Dolt config table, which syncs to every remote on push/pull",
issueops.ErrValidation, key, key)
}
// The prefix is owned by bd init --prefix, bd bootstrap and bd
// rename-prefix. Refused HERE rather than at the front door because `bd
// config set` is not the only door that reaches this plane: before this

View file

@ -57,6 +57,37 @@ func TestValidateSettingWriteRefusesTheProtectedKeyInBothSpellings(t *testing.T)
}
}
// TestValidateSettingWriteRefusesYamlOnlyKeys pins GH#7559: `bd config set`
// already refuses a YamlOnlyKey write via config.IsYamlOnlyKey at its own
// door, but this plane's HTTP settings surface (bd serve and its dashboard,
// PUT /v0/beads/config/{key}) had no such rule, so a tracker secret
// (github.token, linear.api_key, jira.api_token, gitlab.token, ado.pat) sent
// through it landed as a plain row in the Dolt config table — a SYNCED
// table, replicated to every remote on the next bd dolt push/pull. The
// PoC's five secret keys, plus a non-secret YamlOnlyKey (the exact GH#536
// shape the map exists to prevent: a write that reports success but no
// reader ever consults), must all be refused here now.
func TestValidateSettingWriteRefusesYamlOnlyKeys(t *testing.T) {
for _, key := range []string{
// The PoC's five secrets.
"github.token", "linear.api_key", "jira.api_token", "gitlab.token", "ado.pat",
// A non-secret YamlOnlyKey: the rule is "this plane is the database,
// these settings are not database settings", not "secrets only".
"no-db",
} {
_, err := ValidateSettingWrite(key, "SECRET-OR-SETTING-VALUE")
if !errors.Is(err, issueops.ErrValidation) {
t.Fatalf("ValidateSettingWrite(%q) error = %v, want ErrValidation", key, err)
}
if strings.Contains(err.Error(), "SECRET-OR-SETTING-VALUE") {
t.Errorf("ValidateSettingWrite(%q) error echoes the value %v; a secret must never appear in an error message", key, err)
}
if !strings.Contains(err.Error(), "config.yaml") {
t.Errorf("ValidateSettingWrite(%q) message %q does not point the caller at config.yaml", key, err)
}
}
}
func TestValidateSettingWriteParsesTheCustomStatusValue(t *testing.T) {
for _, value := range []string{
"awaiting_review",