Skip to content

fix(config): make the merge shape check agree with the reader - #1278

Merged
tieubao merged 6 commits into
masterfrom
fix/merge-shape-differential
Dec 6, 2026
Merged

tieubao merged 6 commits into
masterfrom
fix/merge-shape-differential

Conversation

@tieubao

@tieubao tieubao commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator

What

A push security review flagged a parser differential in lib/config/merge-command.sh: the shape check (_kit_mc_shape) and the reader (_kit_toml_get) did not agree on which lines form the merge table. It is real. Valid TOML that names the merge command, such as [dev] + merge.command = "...", dev = { merge = { ... } } or ["dev".merge], passed the check while the reader returned empty. Empty means unset, so wrap merge, wrap land, mega-merge and stack-merge fell back to the plain squash and skipped the project's own merge guard. The dev.merge forms came in with #1277. The quoted legacy ["merge"] header and the header-comment forms predate it.

The check now scans each line left to right the way TOML does (strings, escapes, multi-line strings, comments, array depth). It accepts a [ line only as a plain header, judges keys by full path, refuses an array of tables on a parent, and runs with the reader under LC_ALL=C. Every form the reader would misplace now refuses (exit 2), as the contract already said.

before:  [dev] / merge.command = "guard.sh"
         check: ok   reader: ""   tomllib: "guard.sh"   -> plain squash, guard skipped
after:   check: refuse (exit 2)   -> nothing merges, the message names the file

Risk scope: the key is read from the default branch, so a PR cannot use this on its own merge. It is a fail-open on a config edit that looks like a no-op to anyone reading TOML: every later merge would silently skip the guard.

Demo

Command: bash tests/run-all.sh --only test-merge-command   (new tests on origin/master)
test-merge-command: 147 passed, 36 FAILED of 183

Command: bash tests/run-all.sh --only test-merge-command   (this branch)
run-all: all 1 suites passed, 0 skipped for missing tooling

Command: bash tests/run-all.sh --time   (diff-scoped)
run-all: all 25 suites passed, 0 skipped for missing tooling

Proof

docs/verification/merge-shape-differential.md: the differential table, the red run, the green runs, the negative controls, four rounds of independent review, the guard-settings check and the rollback.

  • Independent review. A fresh-context security reviewer ran three rounds, and every finding became a test row. A second fresh reviewer then fuzzed about 69,000 generated TOML files against tomllib. The final corpus shows zero disagreements in both sections under macOS awk, gawk and mawk. The same harness flags failures on origin/master, so the zero means something.
  • Negative controls. 38 real kit.toml / .kit.toml files from the local workspace (plus the operator file) give the same check result before and after. Plain [dev.merge], unrelated dev keys, regex lists, multi-line strings and nested arrays outside the merge table, and Vietnamese comments all still read.
  • Guard settings. [dev.gate] has one reader and no separate check, so the check and the reader cannot disagree. An unreadable form falls back to the operator or default value, so it cannot switch a gate off.

Bookkeeping

no-board-row: security fix from a push review, scoped to one function and its tests

The shape check and the TOML reader in merge-command.sh named table headers differently and judged keys outside the merge table by their own text. Valid TOML such as [dev] + merge.command, a quoted header, or dev = { merge = ... } passed the check and read as unset, so the kit merged plain and skipped the project merge guard. The check now finds headers exactly as the reader does and judges keys by full path; each such form refuses (exit 2). Proof: docs/verification/merge-shape-differential.md.
An independent review found more valid TOML that passed the shape check and read as unset: nested-array lines, multi-line strings, escaped keys and headers, a two-line dev inline table, form-feed blanks. The check now accepts a line opening with [ only as a plain header, refuses multi-line strings, odd blanks and a backslash in a key, and refuses any value on a parent of the merge table.
A second review found a nested array element alone on its line still read as a header, and that refusing every triple quote or nested array blocked plain configs. The check now tracks multi-line arrays and strings and refuses a stray [ line only where the reader would leave or enter the merge table. Check and reader run under LC_ALL=C so a locale cannot change what counts as a blank.
A third review showed quote counting cannot follow TOML strings: a triple quote inside a one-line string, mixed delimiters, a backslash ending a literal string or a double quote inside one still hid a key or a header from the check. One left-to-right scan per line now tracks basic, literal and both multi-line string kinds, comments, and array depth.
A fresh fuzzing review found no fail-open in about 69,000 generated files. It found one low-impact case ([[dev]] before [dev.merge]) and a new over-refusal: array element lines with = or a backslash were judged as keys. Both fixed, with test rows.
@tieubao
tieubao merged commit adcf791 into master Dec 6, 2026
9 checks passed
@tieubao
tieubao deleted the fix/merge-shape-differential branch December 6, 2026 02:11
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.

1 participant