fix(utils): refuse a bare jq/JS sentinel (null, undefined, empty) as an issue ID (#6215)
* fix(utils): refuse a bare jq/JS sentinel as an issue ID
`jq -r` prints the literal string "null" when a selector misses, and JS
tooling prints "undefined". Both are a valid partial-ID shape, so
ResolvePartialID accepted them and resolved them through its leading-prefix
abbreviation branch: any issue whose hash began with the token became the
target, and the write reported success naming an issue the caller never
mentioned.
Reproduced on stock beads at a07794015, embedded Dolt, scratch workspace,
no orchestrator:
bd init --prefix bd
bd create --id bd-null3t0 "decoy: must not be touched"
bd update null --status closed
✓ Updated issue: bd-null3t0 — decoy: must not be touched (exit 0)
HasPrefix), so this needs a hash that begins with the token — the same case
The guard sits in ResolvePartialID rather than in a command because
internal/utils/id_parser.go is the only ID-resolution entry point in the
repository: 52 non-test call sites across 29 files, plus 2 through the
ResolvePartialIDs wrapper, and the four cmd/bd/*_proxied_server.go twins
resolve through the same function. One guard covers the direct, embedded and
proxied-server paths uniformly.
The riskiest thing this does is add a refusal to the resolver every command
shares. An ID that merely contains a token (bd-null, null3t0,
undefined-behavior) is unaffected, abbreviation matching is otherwise
unchanged, and the empty string already failed — it now says why.
Case folding is deliberate: NULL is what SQL-shaped tooling prints.
Whitespace is trimmed for the comparison only, never for resolution.
The tests use a nil store so the ordering is observable: reaching the
"storage is nil" error proves the guard did not fire. Mutation-tested — with
the guard reverted all eight refused inputs fail and the seven accepted
inputs still pass.
Fixes #6214
Refs #5393
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Cherub Kumar
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SDrKFyrfKTKM5J9yFbW7uA
* fix(utils): refuse none/nil too, and list the new test in the Bazel srcs
Maintainer review fixes for #6215, review iteration 1. Both lanes and the
scorecard returned approve with no required changes; this commit takes the two
actionable minors, both of which land inside the PR's own change.
Taken:
- Behavioral Correctness (minor). `bd update None --status closed` still reached
the leading-prefix abbreviation branch: strings.ToLower("None") is "none" and
every character passes looksLikePartialIDHash, so it could silently write to
whichever issue's hash begins "none" and exit 0. `nil` is the same class. That
is the identical silent-wrong-write harm this PR exists to prevent, and the
remedy lands in the switch the PR just added, so "none" and "nil" join the
same case arm and the refused-inputs table.
The error text is generalized with them: "none" is Python and "nil" is
Go/Ruby, so the previous jq/JS-only wording would have mis-described the two
new tokens.
- Change Impact / Blast Radius (minor). The PR adds two TestX functions that
`go list` selects for internal/utils but that Bazel's utils_test target could
not compile or run -- exactly what tools/bazel/equivalence.py reports as
`missing`. Gazelle's verdict, not a hand-guess: `make bazel-sync` produced
exactly `+ "id_parser_sentinel_test.go",` for internal/utils/BUILD.bazel. It
also rewrote 13 other BUILD.bazel files (pre-existing base drift), which is out
of scope here, so that output was reverted and only this PR's row re-applied at
gazelle's chosen slot. utils_test is 10 entries, sorted, no duplicates, all on
disk.
Note the review predicted the regen would also add `+ "//internal/debug",` to
this file's go_library deps "once rebased on main". It did not at this base,
because the import that needs it is not present here -- that dep is
base-owned drift and is already tracked separately.
Over-refusal is guarded, not assumed: the pre-existing accepted-inputs test
(nullos, null3t0) and the whole ResolvePartialID suite -- cross-prefix,
allowed-prefixes, wisp, title-false-positive -- all still pass.
Validation: gofmt clean, go build ./... and CGO_ENABLED=1 go vet ./internal/utils/
clean; 42 PASS / 0 FAIL / 0 SKIP over -run "Sentinel|ResolvePartialID". The new
rows are mutation-proved: dropping "none" from the case arm reds
TestResolvePartialIDRefusesSentinelTokens, and restoring returns rc=0.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Cherub Kumar <5449665+ckumar1@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
This commit is contained in:
parent
fe5b9d1e0f
commit
ab88b20517
4 changed files with 76 additions and 0 deletions
14
CHANGELOG.md
14
CHANGELOG.md
|
|
@ -98,6 +98,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
and `bd config set storage-class.*` instead of being silently treated as "no
|
||||
custom types".
|
||||
|
||||
- **`bd` refuses a bare tooling sentinel (`null`, `undefined`, an empty string)
|
||||
as an issue ID** ([#6214](https://github.com/gastownhall/beads/issues/6214)).
|
||||
`jq -r` prints the literal `null` when a selector misses and JS tooling prints
|
||||
`undefined`, so `bd update "$(bd list --json | jq -r '.[0].id')" --status
|
||||
closed` arrived at ID resolution as a plain four-character token. Those tokens
|
||||
are a valid partial-ID shape, so they reached the leading-prefix abbreviation
|
||||
branch and resolved to whichever issue's hash began with them — closing an
|
||||
issue the caller never named and exiting 0 with a success line. `bd update
|
||||
null`, `bd comment null` and every other command that resolves an ID now fail
|
||||
before any lookup, because the guard sits in the shared resolver. An ID that
|
||||
merely contains a token (`bd-null`, `null3t0`, `undefined-behavior`) still
|
||||
resolves, and abbreviation matching is otherwise unchanged. The empty string
|
||||
already failed; it now says why.
|
||||
|
||||
- **`notion.token` is kept out of the Dolt database**
|
||||
([#6676](https://github.com/gastownhall/beads/issues/6676)). It was missing
|
||||
from the yaml-only key list that holds the other tracker secrets, so
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ go_test(
|
|||
name = "utils_test",
|
||||
srcs = [
|
||||
"id_parser_prefix_test.go",
|
||||
"id_parser_sentinel_test.go",
|
||||
"id_parser_test.go",
|
||||
"id_parser_unit_test.go",
|
||||
"issue_446_test.go",
|
||||
|
|
|
|||
|
|
@ -49,9 +49,19 @@ func parseIssueID(input string, prefix string) string {
|
|||
// - Hierarchical: "a3f8e9.1" → "bd-a3f8e9.1"
|
||||
//
|
||||
// Returns an error if:
|
||||
// - The input is a bare tooling sentinel ("", "null", "undefined", "none", "nil")
|
||||
// - No issue found matching the ID
|
||||
// - Multiple issues match (ambiguous prefix)
|
||||
func ResolvePartialID(ctx context.Context, store PartialIDResolverStore, input string) (string, error) {
|
||||
// Refuse before any lookup: these tokens are a valid partial-ID shape, so
|
||||
// they otherwise reach the leading-prefix abbreviation branch below.
|
||||
switch strings.ToLower(strings.TrimSpace(input)) {
|
||||
case "":
|
||||
return "", fmt.Errorf("refusing an empty string as an issue ID")
|
||||
case "null", "undefined", "none", "nil":
|
||||
return "", fmt.Errorf("refusing %q as an issue ID: that is what tooling prints for a missing value (jq/JS null and undefined, Python None, Go/Ruby nil), so the caller's selector matched nothing", input)
|
||||
}
|
||||
|
||||
if store == nil {
|
||||
return "", fmt.Errorf("cannot resolve issue ID %q: storage is nil", input)
|
||||
}
|
||||
|
|
|
|||
51
internal/utils/id_parser_sentinel_test.go
Normal file
51
internal/utils/id_parser_sentinel_test.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// A nil store makes the ordering observable: reaching the "storage is nil"
|
||||
// error proves the sentinel guard did NOT fire for that input.
|
||||
func TestResolvePartialIDRefusesSentinelTokens(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
refused := []string{
|
||||
"null", "NULL", "Null", " null ",
|
||||
"undefined", "UNDEFINED",
|
||||
"none", "NONE", "None", " none ",
|
||||
"nil", "NIL", "Nil",
|
||||
"", " ",
|
||||
}
|
||||
for _, input := range refused {
|
||||
got, err := ResolvePartialID(ctx, nil, input)
|
||||
if err == nil {
|
||||
t.Errorf("ResolvePartialID(%q) = %q, nil; want a refusal", input, got)
|
||||
continue
|
||||
}
|
||||
if strings.Contains(err.Error(), "storage is nil") {
|
||||
t.Errorf("ResolvePartialID(%q) reached the store; the sentinel guard did not fire: %v", input, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvePartialIDAcceptsIDsContainingSentinelTokens(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
accepted := []string{
|
||||
"bd-a3f8e9",
|
||||
"a3f8",
|
||||
"nullos",
|
||||
"null3t0",
|
||||
"bd-null",
|
||||
"bd-null.1",
|
||||
"undefined-behavior",
|
||||
}
|
||||
for _, input := range accepted {
|
||||
_, err := ResolvePartialID(ctx, nil, input)
|
||||
if err == nil || !strings.Contains(err.Error(), "storage is nil") {
|
||||
t.Errorf("ResolvePartialID(%q) = %v; want it to pass the sentinel guard and reach the store", input, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue