Startup secret check: compare the salt with the key as the key reader reads it, and pin the documented limits #75

Closed
opened 2026-11-15 14:35:46 +00:00 by svc-agent-writer · 4 comments

Findings from the two fresh reviews of PR #74 (#69) at 1eac958 that the merge-gate rework does not fix. Neither review found a blocker. The rework fixes the raw-salt test fixture (it now catches a case fold) and rewrites the tokens-equal paragraph in README and SECURITY so that it states the limits below. Line numbers are at 1eac958.

Should fix

  1. A salt that is the key in a form the key reader accepts still passes (startup.py:129-139). read_key_file (store.py:136-144) reads the key as decode("ascii").strip().lower(). That strips \x1c-\x1f as well as ASCII whitespace. The startup check compares the salt with the key only in the normalised form, which keeps \x1c-\x1f. A salt file holding "\x1c" + key or key + "\x1f" passes check, sync and forget on the base and on #74's head. The key reader would read that same file as the key, so the salt is a copy of the key. This is the class of copy #69 targets. It is pre-existing, and the #69 spec ruled it out of scope.
    • Cheap fix: for the salt-vs-key pair, also compare the salt through the key reader's text normalisation, as the token-vs-key loop does for tokens. Refuse a salt that does not decode as ASCII only in that comparison, never in the HMAC path.
    • The rewritten paragraph says "a salt that is the key with a no-break space or \x1c around it is not refused". Change that sentence with the fix.

Test gaps

  1. The documented limits have no test. No case pins that salt = key + NBSP or "\x1c" + key is not refused, so a change in either direction goes unnoticed. Pin the limit, or pin the refusal after item 1.
  2. No case has a key file in a non-canonical form (upper case or padded) against a raw salt equal to the canonical key. The code refuses it correctly in check, sync and forget (probe key-x1c-salt-raw), but nothing pins it.

Notes

  1. With two collisions, the reported pair can differ from the base, because normalised equality finds an earlier pair. Example: a read token equal to KEY_HEX.upper(), and a Consumer token equal to the Feeder token. The base reports feed.consumers,feeder.token_file, and #74 reports auth.read_token_file,store.key_file. This follows the "first pair in order" rule, so it is not a defect.
  2. compare_digest now gets normalised inputs, which can differ in length, as the raw inputs could on the base. strip and lower take time that depends on the data. Everything runs once at startup on local files, so no remote party observes it. Not a regression.
  3. Two values that differ only in non-ASCII case, or by NBSP padding (for example a read and an evidence token), are not refused. This is the ruled normalised form (#68 triage), and the rewritten paragraph now says so. Decide whether to keep it.

Triage decisions (2026-11-16)

The operator accepted these decisions ("Yes, my way").

  • Item 1. Fix it. For the salt-vs-key pair, also compare the salt in the key reader's form (decode("ascii").strip().lower(), as in read_key_file). A salt that does not decode as ASCII is skipped in that comparison only. It is never refused for that reason, and the HMAC path still gets the raw salt.
  • The cp key salt case (comment 1) is refused by the same fix. Add a test for it.
  • Item 2 and the test gaps in the comments. Pin each one:
    • the salt refusal after the fix;
    • a key file in a non-canonical form against a raw salt;
    • a salt fixture that ends in "\n" and "\r";
    • normalised over all 256 byte values;
    • the token-vs-key rule for \x1c-\x1f.
  • README and SECURITY. Change the salt-gap sentence to match the fix. Name the token rule exactly (Python str.strip() and str.lower(), which also remove \x1c-\x1f). Say that a non-ASCII key file is refused with key-format, so a no-break-space salt cannot come from a copy.
  • Items 4 and 5. No change. These follow the ruled rules.
  • Item 6. Keep the ruled normalised form (#68 triage).

Sequencing

Run SVD after #65 and #78 merge, because #65 also writes startup.py.


Filed under: #69 merge gate, fresh reviews of PR #74 at 1eac958.

Findings from the two fresh reviews of PR #74 (#69) at `1eac958` that the merge-gate rework does not fix. Neither review found a blocker. The rework fixes the raw-salt test fixture (it now catches a case fold) and rewrites the `tokens-equal` paragraph in README and SECURITY so that it states the limits below. Line numbers are at `1eac958`. ## Should fix 1. **A salt that is the key in a form the key reader accepts still passes** (`startup.py:129-139`). `read_key_file` (`store.py:136-144`) reads the key as `decode("ascii").strip().lower()`. That strips `\x1c`-`\x1f` as well as ASCII whitespace. The startup check compares the salt with the key only in the normalised form, which keeps `\x1c`-`\x1f`. A salt file holding `"\x1c" + key` or `key + "\x1f"` passes `check`, `sync` and `forget` on the base and on #74's head. The key reader would read that same file as the key, so the salt is a copy of the key. This is the class of copy #69 targets. It is pre-existing, and the #69 spec ruled it out of scope. - Cheap fix: for the salt-vs-key pair, also compare the salt through the key reader's text normalisation, as the token-vs-key loop does for tokens. Refuse a salt that does not decode as ASCII only in that comparison, never in the HMAC path. - The rewritten paragraph says "a salt that is the key with a no-break space or `\x1c` around it is not refused". Change that sentence with the fix. ## Test gaps 2. **The documented limits have no test.** No case pins that `salt = key + NBSP` or `"\x1c" + key` is not refused, so a change in either direction goes unnoticed. Pin the limit, or pin the refusal after item 1. 3. **No case has a key file in a non-canonical form** (upper case or padded) against a raw salt equal to the canonical key. The code refuses it correctly in `check`, `sync` and `forget` (probe `key-x1c-salt-raw`), but nothing pins it. ## Notes 4. With two collisions, the reported pair can differ from the base, because normalised equality finds an earlier pair. Example: a read token equal to `KEY_HEX.upper()`, and a Consumer token equal to the Feeder token. The base reports `feed.consumers,feeder.token_file`, and #74 reports `auth.read_token_file,store.key_file`. This follows the "first pair in order" rule, so it is not a defect. 5. `compare_digest` now gets normalised inputs, which can differ in length, as the raw inputs could on the base. `strip` and `lower` take time that depends on the data. Everything runs once at startup on local files, so no remote party observes it. Not a regression. 6. Two values that differ only in non-ASCII case, or by NBSP padding (for example a read and an evidence token), are not refused. This is the ruled normalised form (#68 triage), and the rewritten paragraph now says so. Decide whether to keep it. ## Triage decisions (2026-11-16) The operator accepted these decisions ("Yes, my way"). - **Item 1.** Fix it. For the salt-vs-key pair, also compare the salt in the key reader's form (`decode("ascii").strip().lower()`, as in `read_key_file`). A salt that does not decode as ASCII is skipped in that comparison only. It is never refused for that reason, and the HMAC path still gets the raw salt. - **The `cp key salt` case** (comment 1) is refused by the same fix. Add a test for it. - **Item 2 and the test gaps in the comments.** Pin each one: - the salt refusal after the fix; - a key file in a non-canonical form against a raw salt; - a salt fixture that ends in `"\n"` and `"\r"`; - `normalised` over all 256 byte values; - the token-vs-key rule for `\x1c`-`\x1f`. - **README and SECURITY.** Change the salt-gap sentence to match the fix. Name the token rule exactly (Python `str.strip()` and `str.lower()`, which also remove `\x1c`-`\x1f`). Say that a non-ASCII key file is refused with `key-format`, so a no-break-space salt cannot come from a copy. - **Items 4 and 5.** No change. These follow the ruled rules. - **Item 6.** Keep the ruled normalised form (#68 triage). ## Sequencing Run SVD after #65 and #78 merge, because #65 also writes `startup.py`. --- Filed under: #69 merge gate, fresh reviews of PR #74 at `1eac958`.
Author
Member

Additions from the two fresh reviews of PR #76 at 6a7dde9, the re-dispatch of #69 after PR #74 closed. Neither review found a blocker. The rework already fixed the lower-case raw-salt fixture and the over-broad paragraph. Line numbers are at 6a7dde9.

Filed under: #69 merge gate, fresh reviews of PR #76 at 6a7dde9.

  • Item 1 addition: a copied key file passes as the salt. cp key salt passes check, sync and forget when the key file has \x1c-\x1f around the hex, for example both files holding "\x1c" + hex + "\x1c\n". The paragraph's sentence "two values that are equal byte for byte are refused" can be read as "two identical files are refused", which is false in this case. The salt-gap sentence covers it. When item 1 is fixed, also note that the no-break-space example for the salt cannot come from a copy: the key reader refuses a non-ASCII key file with key-format.
  • Test gap: extra trailing newlines on the salt. Passing salt.rstrip(b"\n") into Secrets keeps every test green (593 targeted, and the full suite). That change would alter the Tombstone hash of any salt file ending in two or more line endings. The fixture " " + "Ss" * 16 + " " ends in the single newline that read_secret_file removes. Fix: end the fixture in "\n" or "\r". No known-answer test pins "less one final newline" in read_secret_file; the raw-salt test compares with the reader itself.
  • Test gap: "The salt gets no such text comparison" has no test. Adding the salt to the token-vs-key text loop keeps the full suite green, and the paragraph is then false. Pin the limit, or change both with item 1.
  • Test gap: normalised strips exactly six bytes. Adding \x00 to _ASCII_WHITESPACE survives the targeted tests. The \x1c assertion pins one byte outside the set, not every byte. Assert over all 256 byte values.
  • Note: "Unicode whitespace" is Python str.isspace. It also removes \x1c-\x1f, which are not Unicode White_Space. The code refuses more than the paragraph says (a read token of "\x1c" + key is refused by check and api). Name the rule exactly.
  • Note: the token-vs-key loop calls first_equal, so its operands are normalised a second time. Harmless and idempotent.
Additions from the two fresh reviews of PR #76 at `6a7dde9`, the re-dispatch of #69 after PR #74 closed. Neither review found a blocker. The rework already fixed the lower-case raw-salt fixture and the over-broad paragraph. Line numbers are at `6a7dde9`. Filed under: #69 merge gate, fresh reviews of PR #76 at `6a7dde9`. - **Item 1 addition: a copied key file passes as the salt.** `cp key salt` passes `check`, `sync` and `forget` when the key file has `\x1c`-`\x1f` around the hex, for example both files holding `"\x1c" + hex + "\x1c\n"`. The paragraph's sentence "two values that are equal byte for byte are refused" can be read as "two identical files are refused", which is false in this case. The salt-gap sentence covers it. When item 1 is fixed, also note that the no-break-space example for the salt cannot come from a copy: the key reader refuses a non-ASCII key file with `key-format`. - **Test gap: extra trailing newlines on the salt.** Passing `salt.rstrip(b"\n")` into `Secrets` keeps every test green (593 targeted, and the full suite). That change would alter the Tombstone hash of any salt file ending in two or more line endings. The fixture `" " + "Ss" * 16 + " "` ends in the single newline that `read_secret_file` removes. Fix: end the fixture in `"\n"` or `"\r"`. No known-answer test pins "less one final newline" in `read_secret_file`; the raw-salt test compares with the reader itself. - **Test gap: "The salt gets no such text comparison" has no test.** Adding the salt to the token-vs-key text loop keeps the full suite green, and the paragraph is then false. Pin the limit, or change both with item 1. - **Test gap: `normalised` strips exactly six bytes.** Adding `\x00` to `_ASCII_WHITESPACE` survives the targeted tests. The `\x1c` assertion pins one byte outside the set, not every byte. Assert over all 256 byte values. - **Note: "Unicode whitespace" is Python `str.isspace`.** It also removes `\x1c`-`\x1f`, which are not Unicode White_Space. The code refuses more than the paragraph says (a read token of `"\x1c" + key` is refused by `check` and `api`). Name the rule exactly. - **Note:** the token-vs-key loop calls `first_equal`, so its operands are normalised a second time. Harmless and idempotent.
Author
Member

This was generated by AI during triage.

The operator accepted the triage decisions on 2026-11-16. They are now in the issue body under "Triage decisions (2026-11-16)". State: ready-for-agent.

> *This was generated by AI during triage.* The operator accepted the triage decisions on 2026-11-16. They are now in the issue body under "Triage decisions (2026-11-16)". State: ready-for-agent.
Collaborator

⏸ SVD architect gate: dev/messages-mind-mcp#75 startup-secret-check-compare-the-salt-with-the-key-as-the-ke

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: 20261116T104510Z-0fa7f947

Held because: CLEAN but 2 open risk(s) (2 verification) — HOLD-ALL parks everything. The risks, verbatim:

Open risks:

  1. No test baseline was measured in the Half-A sandbox (the project .venv python cannot run here). Check: run make check on the pristine base 205d5df before the first edit and record the counts. After the change, make check must show no failures, and the pass count must rise by at least the number of new cases (2 salt rows, 4 read-key rows, 1 copy test, 3 non-canonical-key cases, 2 non-ASCII-salt cases, 1 extra raw-bytes ending). [verification]
  2. Operator-visible refusal: a salt file that is a \x1c-\x1f-padded copy of the key now stops check/sync/forget with tokens-equal at=store.key_file,store.tombstone_salt_file. Check after merge: messages-mind-mcp check --config <live config> on the operator's host still prints config=ok. [verification]

Change: Mirror the token-vs-key text loop at src/messages_mind_mcp/startup.py:143-148. After it, and before the tokens-equal raise at line 149, add a salt-vs-key comparison. When salt is not None, try salt.decode("ascii").strip().lower(); on UnicodeDecodeError skip this comparison only. Otherwise compute first_equal([("store.key_file", key.encode()), ("store.tombstone_salt_file", salt_text.encode())]) unconditionally and assign it to pair only when pair is None. Secrets.salt stays the raw read_secret_file bytes. Update the line-143 comment, and the identical sentences at README.md:439 and SECURITY.md:66, to name Python str.strip()/str.lower() (str.strip() also removes \x1c-\x1f). Those sentences must also say the salt gets the text comparison when it is ASCII, that a non-ASCII salt is skipped (the NBSP limit stays), and that a non-ASCII key file is refused with key-format. Pin it all with parametrize rows and new tests in tests/test_config_cli.py (around 2044-2141), a 256-byte normalised loop in tests/test_kit.py:306, an NBSP key-format case in tests/test_store.py:88, and updated phrase asserts in tests/test_feed.py:494-520.

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

Decision: accept the 2 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-16-startup-secret-check-compare-the-salt-with-the-key-as-the-ke.md — next: codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-16-startup-secret-check-compare-the-salt-with-the-key-as-the-ke.md

— messages-mind@voyager

### ⏸ SVD architect gate: dev/messages-mind-mcp#75 startup-secret-check-compare-the-salt-with-the-key-as-the-ke **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:** `20261116T104510Z-0fa7f947` **Held because:** CLEAN but 2 open risk(s) (2 verification) — HOLD-ALL parks everything. The risks, verbatim: **Open risks:** 1. No test baseline was measured in the Half-A sandbox (the project .venv python cannot run here). Check: run make check on the pristine base 205d5df before the first edit and record the counts. After the change, make check must show no failures, and the pass count must rise by at least the number of new cases (2 salt rows, 4 read-key rows, 1 copy test, 3 non-canonical-key cases, 2 non-ASCII-salt cases, 1 extra raw-bytes ending). [verification] 2. Operator-visible refusal: a salt file that is a \x1c-\x1f-padded copy of the key now stops check/sync/forget with tokens-equal at=store.key_file,store.tombstone_salt_file. Check after merge: `messages-mind-mcp check --config <live config>` on the operator's host still prints config=ok. [verification] **Change:** Mirror the token-vs-key text loop at src/messages_mind_mcp/startup.py:143-148. After it, and before the tokens-equal raise at line 149, add a salt-vs-key comparison. When salt is not None, try salt.decode("ascii").strip().lower(); on UnicodeDecodeError skip this comparison only. Otherwise compute first_equal([("store.key_file", key.encode()), ("store.tombstone_salt_file", salt_text.encode())]) unconditionally and assign it to pair only when pair is None. Secrets.salt stays the raw read_secret_file bytes. Update the line-143 comment, and the identical sentences at README.md:439 and SECURITY.md:66, to name Python str.strip()/str.lower() (str.strip() also removes \x1c-\x1f). Those sentences must also say the salt gets the text comparison when it is ASCII, that a non-ASCII salt is skipped (the NBSP limit stays), and that a non-ASCII key file is refused with key-format. Pin it all with parametrize rows and new tests in tests/test_config_cli.py (around 2044-2141), a 256-byte normalised loop in tests/test_kit.py:306, an NBSP key-format case in tests/test_store.py:88, and updated phrase asserts in tests/test_feed.py:494-520. **Files:** `src/messages_mind_mcp/startup.py` · `README.md` · `SECURITY.md` · `tests/test_config_cli.py` · `tests/test_kit.py` · `tests/test_feed.py` · `tests/test_store.py` **Decision:** accept the 2 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-16-startup-secret-check-compare-the-salt-with-the-key-as-the-ke.md` — next: `codex-svd dispatch --args '<same-json>' --approved-spec-path /Users/piers/.local/state/exhaust/groupthink/specs/2026-11-16-startup-secret-check-compare-the-salt-with-the-key-as-the-ke.md`</sub> — messages-mind@voyager
Collaborator

spec-verify-dispatch Half B for dev/messages-mind-mcp#75 startup-secret-check-compare-the-salt-with-the-key-as-the-ke completed integration verify.

  • PR: #98
  • Branch: feat/svd-dev-messages-mind-mcp-75-startup-secret-check-compar-e128c482
  • Commit: fc9a45dff6
  • 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/91/1
  • Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll
  • Warning: Remote check ci/woodpecker/pr/validation was still pending when measured; the runner should re-poll it.
  • Warning: Operator-visible change: a salt that is a \x1c-\x1f-padded copy of the key now stops check, sync and forget with tokens-equal. The PR body states this. After merge, run messages-mind-mcp check --config <live config> on the host and expect config=ok.
  • Warning: The PR body credits the subagent's pristine baseline as 1520 passed and 60 skipped. This run saw 1535 passed and 58 skipped on the PR head, so the counts differ; no failures either way.
  • CI wait: ci/woodpecker/pr/validation -> pass
  • Decision: review the PR and merge? (codex-svd ship --run-id 20261116T112350Z-e128c482 --confirm-merge)
spec-verify-dispatch Half B for dev/messages-mind-mcp#75 startup-secret-check-compare-the-salt-with-the-key-as-the-ke completed integration verify. - PR: https://git.groupthink.asia/dev/messages-mind-mcp/pulls/98 - Branch: feat/svd-dev-messages-mind-mcp-75-startup-secret-check-compar-e128c482 - Commit: fc9a45dff63f4f73bd3cb81dbbbd718589be295a - 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/91/1 - Checks: required ci/woodpecker/pr/validation resolved pass by CI-wait poll - Warning: Remote check ci/woodpecker/pr/validation was still pending when measured; the runner should re-poll it. - Warning: Operator-visible change: a salt that is a \x1c-\x1f-padded copy of the key now stops check, sync and forget with tokens-equal. The PR body states this. After merge, run `messages-mind-mcp check --config <live config>` on the host and expect config=ok. - Warning: The PR body credits the subagent's pristine baseline as 1520 passed and 60 skipped. This run saw 1535 passed and 58 skipped on the PR head, so the counts differ; no failures either way. - CI wait: ci/woodpecker/pr/validation -> pass - Decision: review the PR and merge? (`codex-svd ship --run-id 20261116T112350Z-e128c482 --confirm-merge`)
svc-svd-writer 2026-11-16 11:45:05 +00:00
  • closed this issue
  • removed the
    svd:go
    label
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#75
No description provided.