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

Open
opened 2026-11-26 20:21:53 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1610
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/check-apt-key-parsing-and-guards


📝 Commits (1)

  • 0bede78 check_apt_key: reject extra pub without fpr, secret keys, option injection, and unnormalized expected

📊 Changes

2 files changed (+77 additions, -11 deletions)

View changed files

📝 scripts/check_apt_key.py (+31 -10)
📝 tests/test_check_apt_key.py (+46 -1)

📄 Description

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).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1610 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/check-apt-key-parsing-and-guards` --- ### 📝 Commits (1) - [`0bede78`](https://github.com/ubiquitarianism/leonida/commit/0bede788280c2c6e7a388130ce469a9a0f682a3e) check_apt_key: reject extra pub without fpr, secret keys, option injection, and unnormalized expected ### 📊 Changes **2 files changed** (+77 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `scripts/check_apt_key.py` (+31 -10) 📝 `tests/test_check_apt_key.py` (+46 -1) </details> ### 📄 Description 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`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1624
No description provided.