Startup secret check: compare the salt and every secret pair in normalised form #69

Closed
opened 2026-11-15 10:11:07 +00:00 by svc-agent-writer · 4 comments

The startup secret check compares the tombstone salt with the store key only in raw form. A salt file that holds the key in upper case, with a space before it, or with two newlines after it passes check, sync and forget. Only an exact copy is refused. Found by the correctness and the security review of PR #67; split out of #68 at triage, because it is the most important item there.

What the code does now (main at 99a849c)

  • read_key_file (src/messages_mind_mcp/store.py:136-143) strips whitespace and folds hex to lower case.

  • read_secret_file (src/messages_mind_mcp/kit/secrets.py:18-42) returns raw bytes. It removes one trailing newline only. The salt and every token go through it.

  • startup.py:127-136 compares every pair in raw form. A second loop compares each token's strip().lower() form with the key. The salt has no such comparison, and no pair other than token and key is compared in normalised form.

  • A reproduction with synthetic files and the shipped readers and first_equal:

    Salt file content Refused
    the key, exact yes
    the key in upper case no
    the key with a leading space no
    the key and two newlines no
  • README.md:401 and SECURITY.md:66 say that tokens-equal compares "the value of every secret". The documents claim more than the code does.

Decisions

  • Already decided (#54 ruling Q3): compare every pair, "the store key (and its strip().lower() form) and the tombstone salt, including the salt against the key".
  • Normalisation scope (operator, #68 triage): compare every pair of secrets that the verb reads in normalised form, not only the salt against the key. The normalised form of a value is its bytes with ASCII whitespace removed at both ends and ASCII letters folded to lower case. A pair equal in raw form is also equal in normalised form.
  • Comparison only. The salt reaches HMAC as raw bytes (tombstones.py:44-50). Do not change the salt that Secrets holds or that the Tombstone functions receive: a change of the HMAC input changes every existing Tombstone hash and the salt check.

Acceptance criteria

  • check, sync and forget refuse with secret=error code=tokens-equal at=store.key_file,store.tombstone_salt_file when the salt file holds the key in upper case, the key with whitespace before or after it, or the key and an extra newline.
  • A salt equal to a token in normalised form is refused. The error names that pair of locations.
  • Two tokens that differ only in case or in outer whitespace are refused. The error names that pair of locations.
  • Secrets.salt equals the bytes that read_secret_file returns for the salt file. A test asserts this.
  • The cases above extend test_a_token_equal_to_another_secret_is_refused (tests/test_config_cli.py) or sit beside it.
  • No secret value appears in an error, a log line or a test assertion message. Codes and locations only.
  • README.md and SECURITY.md say that tokens-equal compares every pair in normalised form, and say what the normalised form is.
  • make check passes. Synthetic data only.

Primary files

  • src/messages_mind_mcp/startup.py
  • src/messages_mind_mcp/kit/scopes.py
  • tests/test_config_cli.py
  • README.md
  • SECURITY.md

Human act

ruling: the operator approves dispatch with svd:go and names T4 for the merge of this secret-check change (CONV-40)

Blocked by

Sequencing

#56 is at its gate with spec base 99a849c and writes tests/test_config_cli.py, README.md and SECURITY.md. This issue goes after #56 merges and before #65, which also writes startup.py.


Filed under: operator word "accept" sha256:c125d0397b60

The startup secret check compares the tombstone salt with the store key only in raw form. A salt file that holds the key in upper case, with a space before it, or with two newlines after it passes `check`, `sync` and `forget`. Only an exact copy is refused. Found by the correctness and the security review of PR #67; split out of #68 at triage, because it is the most important item there. ## What the code does now (`main` at `99a849c`) - `read_key_file` (`src/messages_mind_mcp/store.py:136-143`) strips whitespace and folds hex to lower case. - `read_secret_file` (`src/messages_mind_mcp/kit/secrets.py:18-42`) returns raw bytes. It removes one trailing newline only. The salt and every token go through it. - `startup.py:127-136` compares every pair in raw form. A second loop compares each token's `strip().lower()` form with the key. The salt has no such comparison, and no pair other than token and key is compared in normalised form. - A reproduction with synthetic files and the shipped readers and `first_equal`: | Salt file content | Refused | |---|---| | the key, exact | yes | | the key in upper case | no | | the key with a leading space | no | | the key and two newlines | no | - `README.md:401` and `SECURITY.md:66` say that `tokens-equal` compares "the value of every secret". The documents claim more than the code does. ## Decisions - **Already decided** (#54 ruling Q3): compare every pair, "the store key (and its `strip().lower()` form) and the tombstone salt, including the salt against the key". - **Normalisation scope** (operator, #68 triage): compare every pair of secrets that the verb reads in normalised form, not only the salt against the key. The normalised form of a value is its bytes with ASCII whitespace removed at both ends and ASCII letters folded to lower case. A pair equal in raw form is also equal in normalised form. - **Comparison only.** The salt reaches HMAC as raw bytes (`tombstones.py:44-50`). Do not change the salt that `Secrets` holds or that the Tombstone functions receive: a change of the HMAC input changes every existing Tombstone hash and the salt check. ## Acceptance criteria - `check`, `sync` and `forget` refuse with `secret=error code=tokens-equal at=store.key_file,store.tombstone_salt_file` when the salt file holds the key in upper case, the key with whitespace before or after it, or the key and an extra newline. - A salt equal to a token in normalised form is refused. The error names that pair of locations. - Two tokens that differ only in case or in outer whitespace are refused. The error names that pair of locations. - `Secrets.salt` equals the bytes that `read_secret_file` returns for the salt file. A test asserts this. - The cases above extend `test_a_token_equal_to_another_secret_is_refused` (`tests/test_config_cli.py`) or sit beside it. - No secret value appears in an error, a log line or a test assertion message. Codes and locations only. - `README.md` and `SECURITY.md` say that `tokens-equal` compares every pair in normalised form, and say what the normalised form is. - `make check` passes. Synthetic data only. ## Primary files - `src/messages_mind_mcp/startup.py` - `src/messages_mind_mcp/kit/scopes.py` - `tests/test_config_cli.py` - `README.md` - `SECURITY.md` ## Human act ruling: the operator approves dispatch with `svd:go` and names T4 for the merge of this secret-check change (CONV-40) ## Blocked by - #56 ## Sequencing #56 is at its gate with spec base `99a849c` and writes `tests/test_config_cli.py`, `README.md` and `SECURITY.md`. This issue goes after #56 merges and before #65, which also writes `startup.py`. --- Filed under: operator word "accept" sha256:c125d0397b60
Collaborator

⏸ SVD architect gate: dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair

Status: CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity standard · dispatch effort medium

Run: 20261115T135627Z-5777e317

Held because: CLEAN but 3 open risk(s) (1 sequencing · 1 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. Should the check also refuse pairs that match only after non-ASCII whitespace stripping? The deleted token-vs-key loop (startup.py:133-134) used str.strip().lower(), which strips Unicode whitespace (such as NBSP) and \x1c-\x1f. The ruled normalised form (#68 triage) covers only ASCII whitespace and ASCII letters, so a token of NBSP+key that is refused today would pass. read_key_file also strips \x1c-\x1f from the key file, so a salt of \x1c+key would not be refused either. Lean: follow the ruling exactly, because these files are contrived and code and docs then agree. Alternative: keep the old str-based loop as an extra check, which is stricter but leaves a second, undocumented normalisation. [decision]
  2. Blocker #56 is merged: 0486d0a carries 'Closes #56' and is this spec's base. Nothing else blocks dispatch. #65 also writes startup.py and must dispatch after this PR merges. If #65 lands first, the drift guard halts on startup.py and this spec needs a codex-svd rebaseline. [sequencing — blocked by #56]
  3. The Half-A sandbox could not run .venv/bin/python or uv, so no test baseline and no make check were measured. Check: on the host, run make check at 0486d0a before the first edit and again on the PR head. Record both passed/skipped counts in the PR body and confirm the failure set is unchanged apart from the new and updated tests passing. [verification]

Change: In kit/scopes.py, add normalised(value: bytes) -> bytes = value.strip(b" \t\n\r\x0b\x0c").lower() beside first_equal (scopes.py:38-46). Make first_equal normalise each entry once, then compare every pair with hmac.compare_digest. Keep the same pair order, keep no early exit, and keep n(n-1)/2 comparisons. In startup.py, keep the labelled list (121-130) and its single first_equal call (131), and delete the str-based token-vs-key loop (132-136). The raw salt still goes to Secrets (150). Do not touch Tokens.post_init or Tokens.match. Extend test_a_token_equal_to_another_secret_is_refused (test_config_cli.py:1947-1991) with a refusing-verbs column and 10 new normalised cases: salt-key upper/leading/trailing/newline, salt-token, and token-token. Add a raw-salt test. Unit-test normalised in test_kit.py. Rewrite the identical tokens-equal sentence at README.md:401 and SECURITY.md:66 to define the normalised form, and update the pinned assertion in tests/test_feed.py:484-498.

Files: src/messages_mind_mcp/kit/scopes.py · src/messages_mind_mcp/startup.py · tests/test_config_cli.py · tests/test_kit.py · tests/test_feed.py · README.md · SECURITY.md

Decision: accept the 3 open risk(s) above and dispatch this spec (svd:go), or park (svd:skip) / re-spec (svd:respec)?

Your call (when this issue is held at the gate via svd:hold):

  • add label svd:go — approve; Half-B dispatch accepts exactly this spec (open risks accepted)
  • add label svd:fire beside svd:go — approve AND authorise the Half-B fire from the phone; never on its own
  • add label svd:skip — park it; dispatch refuses it and the issue stays for a human
  • add label svd:respec — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context

Spec: /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-15-startup-secret-check-compare-the-salt-and-every-secret-pair.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-15-startup-secret-check-compare-the-salt-and-every-secret-pair.md

### ⏸ SVD architect gate: dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair **Status:** CLEAN after 0 rework round(s) · 0 blocking defect(s) · 0 lens(es) INCONCLUSIVE (could not run) · 0 lens(es) DEGRADED (deterministic denial) · complexity `standard` · dispatch effort `medium` **Run:** `20261115T135627Z-5777e317` **Held because:** CLEAN but 3 open risk(s) (1 sequencing · 1 verification · 1 decision) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. Should the check also refuse pairs that match only after non-ASCII whitespace stripping? The deleted token-vs-key loop (startup.py:133-134) used str.strip().lower(), which strips Unicode whitespace (such as NBSP) and \x1c-\x1f. The ruled normalised form (#68 triage) covers only ASCII whitespace and ASCII letters, so a token of NBSP+key that is refused today would pass. read_key_file also strips \x1c-\x1f from the key file, so a salt of \x1c+key would not be refused either. Lean: follow the ruling exactly, because these files are contrived and code and docs then agree. Alternative: keep the old str-based loop as an extra check, which is stricter but leaves a second, undocumented normalisation. [decision] 2. Blocker #56 is merged: 0486d0a carries 'Closes #56' and is this spec's base. Nothing else blocks dispatch. #65 also writes startup.py and must dispatch after this PR merges. If #65 lands first, the drift guard halts on startup.py and this spec needs a codex-svd rebaseline. [sequencing — blocked by #56] 3. The Half-A sandbox could not run .venv/bin/python or uv, so no test baseline and no make check were measured. Check: on the host, run make check at 0486d0a before the first edit and again on the PR head. Record both passed/skipped counts in the PR body and confirm the failure set is unchanged apart from the new and updated tests passing. [verification] **Change:** In kit/scopes.py, add `normalised(value: bytes) -> bytes` = `value.strip(b" \t\n\r\x0b\x0c").lower()` beside `first_equal` (scopes.py:38-46). Make `first_equal` normalise each entry once, then compare every pair with hmac.compare_digest. Keep the same pair order, keep no early exit, and keep n(n-1)/2 comparisons. In startup.py, keep the `labelled` list (121-130) and its single `first_equal` call (131), and delete the str-based token-vs-key loop (132-136). The raw `salt` still goes to Secrets (150). Do not touch Tokens.__post_init__ or Tokens.match. Extend test_a_token_equal_to_another_secret_is_refused (test_config_cli.py:1947-1991) with a refusing-verbs column and 10 new normalised cases: salt-key upper/leading/trailing/newline, salt-token, and token-token. Add a raw-salt test. Unit-test `normalised` in test_kit.py. Rewrite the identical tokens-equal sentence at README.md:401 and SECURITY.md:66 to define the normalised form, and update the pinned assertion in tests/test_feed.py:484-498. **Files:** `src/messages_mind_mcp/kit/scopes.py` · `src/messages_mind_mcp/startup.py` · `tests/test_config_cli.py` · `tests/test_kit.py` · `tests/test_feed.py` · `README.md` · `SECURITY.md` **Decision:** accept the 3 open risk(s) above and dispatch this spec (`svd:go`), or park (`svd:skip`) / re-spec (`svd:respec`)? **Your call** (when this issue is held at the gate via `svd:hold`): - add label `svd:go` — approve; Half-B dispatch accepts exactly this spec (open risks accepted) - add label `svd:fire` **beside** `svd:go` — approve AND authorise the Half-B fire from the phone; never on its own - add label `svd:skip` — park it; dispatch refuses it and the issue stays for a human - add label `svd:respec` — discard this spec; the next Half-A run re-produces it with this record as prior-attempt context <sub>Spec: `/Users/piers/.local/state/exhaust/groupthink/specs/2026-11-15-startup-secret-check-compare-the-salt-and-every-secret-pair.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-15-startup-secret-check-compare-the-salt-and-every-secret-pair.md`</sub>
Collaborator

spec-verify-dispatch Half B for dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair completed integration verify.

  • PR: #74
  • Branch: feat/svd-dev-messages-mind-mcp-69-startup-secret-check-compar-f6ff7503
  • Commit: 1eac95853e
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/75/pipeline/71/1
  • Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll
  • Warning: Remote check ci/woodpecker/pr/validation is still pending at verdict time; the runner should re-poll it.
  • Warning: The PR body was not inspected for the required 'Boot refusal (new operator-visible behaviour)' line, Closes #69 and the passed/skipped counts. Host make check on the PR head: 1372 passed, 58 skipped, 2 deselected. The base was not re-measured here.
  • CI wait: ci/woodpecker/pr/validation -> pass
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261115T141029Z-f6ff7503 --confirm-merge)
spec-verify-dispatch Half B for dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair completed integration verify. - PR: https://git.groupthink.asia/dev/messages-mind-mcp/pulls/74 - Branch: feat/svd-dev-messages-mind-mcp-69-startup-secret-check-compar-f6ff7503 - Commit: 1eac95853e9c3575ba1dc247e143bc417b4512d2 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/75/pipeline/71/1 - Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll - Warning: Remote check ci/woodpecker/pr/validation is still pending at verdict time; the runner should re-poll it. - Warning: The PR body was not inspected for the required 'Boot refusal (new operator-visible behaviour)' line, `Closes #69` and the passed/skipped counts. Host make check on the PR head: 1372 passed, 58 skipped, 2 deselected. The base was not re-measured here. - CI wait: ci/woodpecker/pr/validation -> pass - Decision: review the PR and merge? (`codex-svd ship --run-id 20261115T141029Z-f6ff7503 --confirm-merge`)
Collaborator

spec-verify-dispatch Half B for dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair completed integration verify.

  • PR: #74
  • Branch: feat/svd-dev-messages-mind-mcp-69-startup-secret-check-compar-f6ff7503
  • Commit: 1eac95853e
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: True
  • Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/75/pipeline/71/1
  • Checks: PR #74 head 1eac958: ci/woodpecker/pr/validation green. Local make check passed with 1374 passed and 58 skipped. No blockers.
  • Warning: self-review: the two prescribed startup comments exceeded the 120-column limit; the subagent wrapped them without changing the wording (fixed, advisory only).
  • Warning: PR body co-author trailer names gpt-6.1-terra. This is cosmetic and does not block the merge.
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261115T141029Z-f6ff7503 --confirm-merge)
spec-verify-dispatch Half B for dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair completed integration verify. - PR: https://git.groupthink.asia/dev/messages-mind-mcp/pulls/74 - Branch: feat/svd-dev-messages-mind-mcp-69-startup-secret-check-compar-f6ff7503 - Commit: 1eac95853e9c3575ba1dc247e143bc417b4512d2 - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: True - Check ci/woodpecker/pr/validation: green https://ci.groupthink.asia/repos/75/pipeline/71/1 - Checks: PR #74 head 1eac958: ci/woodpecker/pr/validation green. Local make check passed with 1374 passed and 58 skipped. No blockers. - Warning: self-review: the two prescribed startup comments exceeded the 120-column limit; the subagent wrapped them without changing the wording (fixed, advisory only). - Warning: PR body co-author trailer names gpt-6.1-terra. This is cosmetic and does not block the merge. - Decision: review the PR and merge? (`codex-svd ship --run-id 20261115T141029Z-f6ff7503 --confirm-merge`)
Collaborator

spec-verify-dispatch Half B for dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair completed integration verify.

  • PR: #76
  • Branch: feat/svd-dev-messages-mind-mcp-69-startup-secret-check-compar-1efbe3b2
  • Commit: 6a7dde9022
  • Build: none
  • Test: green
  • Reader audit clean: True
  • Spec fidelity: True
  • Ready for merge: False
  • Check ci/woodpecker/pr/validation: pending https://ci.groupthink.asia/repos/75/pipeline/72/1
  • Checks: PR #76 head 6a7dde9: Woodpecker ci/woodpecker/pr/validation pending. Local: ruff, format, mypy clean; pytest 1372 passed, 58 skipped, 2 deselected. Blocker: PR body lacks the required 'Boot refusal' line.
  • Blocker: PR metadata: add a line "Boot refusal (new operator-visible behaviour): check, sync and forget now refuse a salt that equals the store key or a token in normalised form; the api refuses tokens equal to each other or to the key in normalised form" to the PR body
  • Blocker cause: work for PR metadata: add a line "Boot refusal (new operator-visible behaviour): check, sync and forget now refuse a salt that equals the store key or a token in normalised form; the api refuses tokens equal to each other or to the key in normalised form" to the PR body; no denial signature; evidence: Spec acceptance criterion: 'The PR body carries a "Boot refusal (new operator-visible behaviour)" line and Closes #69.' PR #76 body has Closes #69 but grep -ci 'boot refusal' returns 0.
  • Warning: The PR body also lacks the base re-measure wording the spec asks for beyond counts; it does state 1,372 passed / 58 skipped vs base 1,359 / 58, which matches this run.
  • Warning: The PR body carries a 'Co-Authored-By: gpt-6.1-terra' trailer; informational only.
  • Warning: Subagent deviation 'self-review' items (test_feed.py wording assertion, wrapped comments for 120-char limit) are in-scope and verified: ruff, ruff format and mypy clean.
  • Rework: 0 round(s), outcome metadata-hold
  • Escalation: PR metadata blocker(s) hold the run without code rework: PR metadata: add a line "Boot refusal (new operator-visible behaviour): check, sync and forget now refuse a salt that equals the store key or a token in normalised form; the api refuses tokens equal to each other or to the key in normalised form" to the PR body; edit the PR title or body by hand, then re-run integrate or run the own-execution gate.
  • Decision: resolve the blockers above and rerun integrate, or park this PR for a human?
spec-verify-dispatch Half B for dev/messages-mind-mcp#69 startup-secret-check-compare-the-salt-and-every-secret-pair completed integration verify. - PR: https://git.groupthink.asia/dev/messages-mind-mcp/pulls/76 - Branch: feat/svd-dev-messages-mind-mcp-69-startup-secret-check-compar-1efbe3b2 - Commit: 6a7dde9022dd1b3e2f866bca4e2e687b9eb9490a - Build: none - Test: green - Reader audit clean: True - Spec fidelity: True - Ready for merge: False - Check ci/woodpecker/pr/validation: pending https://ci.groupthink.asia/repos/75/pipeline/72/1 - Checks: PR #76 head 6a7dde9: Woodpecker ci/woodpecker/pr/validation pending. Local: ruff, format, mypy clean; pytest 1372 passed, 58 skipped, 2 deselected. Blocker: PR body lacks the required 'Boot refusal' line. - Blocker: PR metadata: add a line "Boot refusal (new operator-visible behaviour): check, sync and forget now refuse a salt that equals the store key or a token in normalised form; the api refuses tokens equal to each other or to the key in normalised form" to the PR body - Blocker cause: work for PR metadata: add a line "Boot refusal (new operator-visible behaviour): check, sync and forget now refuse a salt that equals the store key or a token in normalised form; the api refuses tokens equal to each other or to the key in normalised form" to the PR body; no denial signature; evidence: Spec acceptance criterion: 'The PR body carries a "Boot refusal (new operator-visible behaviour)" line and `Closes #69`.' PR #76 body has Closes #69 but grep -ci 'boot refusal' returns 0. - Warning: The PR body also lacks the base re-measure wording the spec asks for beyond counts; it does state 1,372 passed / 58 skipped vs base 1,359 / 58, which matches this run. - Warning: The PR body carries a 'Co-Authored-By: gpt-6.1-terra' trailer; informational only. - Warning: Subagent deviation 'self-review' items (test_feed.py wording assertion, wrapped comments for 120-char limit) are in-scope and verified: ruff, ruff format and mypy clean. - Rework: 0 round(s), outcome metadata-hold - Escalation: PR metadata blocker(s) hold the run without code rework: PR metadata: add a line "Boot refusal (new operator-visible behaviour): check, sync and forget now refuse a salt that equals the store key or a token in normalised form; the api refuses tokens equal to each other or to the key in normalised form" to the PR body; edit the PR title or body by hand, then re-run integrate or run the own-execution gate. - Decision: resolve the blockers above and rerun integrate, or park this PR for a human?
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/messages-mind-mcp#69
No description provided.