check_apt_key: reject extra pub without fpr, secret keys, option injection, and unnormalized expected (CHECK-APT-KEY-PARSING-AND-GUARDS) #1610

Merged
IlyassRS3 merged 1 commit from upstream-pr/1610 into main 2026-11-28 10:37:19 +00:00
IlyassRS3 commented 2026-11-25 05:51:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T05:51:09Z.


Item ID: CHECK-APT-KEY-PARSING-AND-GUARDS (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches scripts/check_apt_key.py).

What changed

  • Count primary pub keys even when they lack an fpr record (scripts/check_apt_key.py, primary_fingerprints): previously a pub record followed by another pub, sub/ssb/sec, or EOF without an fpr line was silently dropped, so appending an extra pub record without fpr after the pinned key passed check(). Now every pub record without a matching fpr appends "" (rendered as <missing> in diagnostics), causing check() to fail.
  • Reject secret key records (sec / ssb) in check(): previously a sec record appended after the pinned pub key was ignored and passed check(). Key files handed to apt must contain public key material only.
  • Pass -- end-of-options before path in show_keys(): prevents a key file path starting with - from being interpreted as a gpg option.
  • Normalize and validate expected inside check() and guard non-strings in normalize(): direct callers passing lowercase/spaced fingerprints now match, invalid/empty expected values are refused before invoking gpg, and normalize(None) returns None instead of raising TypeError.
  • Support -h / --help and default argv=None in main().
  • Synthetic regression tests (tests/test_check_apt_key.py): 6 new tests plus expanded test_normalize covering all of the above (no game files, no GPU, no real gpg required).

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only Python script on macOS)
  • python3 -W error -I tests/test_check_apt_key.py -v: 19 passed
  • python3 -W error -I tests/test_text_write_line_endings.py: passed
  • python3 -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py: clean
  • python3 -m compileall -q scripts/check_apt_key.py tests/test_check_apt_key.py: clean
  • Mutation test (tests/test_check_apt_key.py against unpatched main:scripts/check_apt_key.py): 7 failures, 1 error across the 19 tests (all new tests fail on unpatched main).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485971801 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1610). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T05:51:09Z. --- Item ID: `CHECK-APT-KEY-PARSING-AND-GUARDS` (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches `scripts/check_apt_key.py`). ## What changed - **Count primary `pub` keys even when they lack an `fpr` record (`scripts/check_apt_key.py`, `primary_fingerprints`)**: previously a `pub` record followed by another `pub`, `sub`/`ssb`/`sec`, or EOF without an `fpr` line was silently dropped, so appending an extra `pub` record without `fpr` after the pinned key passed `check()`. Now every `pub` record without a matching `fpr` appends `""` (rendered as `<missing>` in diagnostics), causing `check()` to fail. - **Reject secret key records (`sec` / `ssb`) in `check()`**: previously a `sec` record appended after the pinned `pub` key was ignored and passed `check()`. Key files handed to `apt` must contain public key material only. - **Pass `--` end-of-options before `path` in `show_keys()`**: prevents a key file path starting with `-` from being interpreted as a `gpg` option. - **Normalize and validate `expected` inside `check()` and guard non-strings in `normalize()`**: direct callers passing lowercase/spaced fingerprints now match, invalid/empty `expected` values are refused before invoking `gpg`, and `normalize(None)` returns `None` instead of raising `TypeError`. - **Support `-h` / `--help` and default `argv=None` in `main()`**. - **Synthetic regression tests (`tests/test_check_apt_key.py`)**: 6 new tests plus expanded `test_normalize` covering all of the above (no game files, no GPU, no real `gpg` required). ## Verification - AI-assisted: yes - GPUs tested: none (CPU-only Python script on macOS) - `python3 -W error -I tests/test_check_apt_key.py -v`: **19 passed** - `python3 -W error -I tests/test_text_write_line_endings.py`: passed - `python3 -I scripts/check_no_game_data.py scripts/check_apt_key.py tests/test_check_apt_key.py`: clean - `python3 -m compileall -q scripts/check_apt_key.py tests/test_check_apt_key.py`: clean - Mutation test (`tests/test_check_apt_key.py` against unpatched `main:scripts/check_apt_key.py`): **7 failures, 1 error** across the 19 tests (all new tests fail on unpatched `main`).
copilot-pull-request-reviewer[bot] commented 2026-11-25 05:51:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T05:51:20Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052504857 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1610#pullrequestreview-6052504857). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T05:51:20Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:37:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:37:09Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238013363 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1610#issuecomment-7238013363). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:37:09Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1610
No description provided.