[PR #2334] merge_check: guard ref option injection, bounds, and git timeouts #2338

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2334
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/merge-check-safety


📝 Commits (1)

  • d6bb80d merge_check: guard ref option injection, bounds, and git timeouts

📊 Changes

2 files changed (+105 additions, -7 deletions)

View changed files

📝 scripts/merge_check.py (+40 -7)
➕ tests/test_merge_check_safety.py (+65 -0)

📄 Description

Claimed in the coordination issue as: MERGE-CHECK-OPTION-INJECTION-BOUNDS-AND-GIT-TIMEOUT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194083451)

What and why

  • Add _validate_ref() in scripts/merge_check.py to reject empty, padded, or hyphen-prefixed git refs in --main and PR=REF (blocking git CLI option injection such as 12=--all or --main=--exec=...).
  • Validate PR numbers cleanly in parse_pair() (>= 1 ASCII integer with at most one leading #, rejecting 0=main and ##12=main) and add _positive_int (--depth >= 1) and _nonnegative_int (--min-length >= 0) bounds validators.
  • Add GIT_TIMEOUT = 120 in git(), converting subprocess.TimeoutExpired into GitError so hung git invocations return clean exit code 2 with a merge_check: diagnostic.
  • Add standard-library unit tests in tests/test_merge_check_safety.py.

Tested

  • python -I tests/test_merge_check_safety.py -v: 2 passed, 0 failed (detached upstream/main baseline with only the new test file fails with 9 subtest failures and 1 error).
  • python -I tests/test_merge_check.py -v: 24 passed, 0 failed.
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q scripts/merge_check.py tests/test_merge_check_safety.py, and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🔄 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/2334 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/merge-check-safety` --- ### 📝 Commits (1) - [`d6bb80d`](https://github.com/ubiquitarianism/leonida/commit/d6bb80df42a2ebf3cf827ac5381b68df38aec20c) merge_check: guard ref option injection, bounds, and git timeouts ### 📊 Changes **2 files changed** (+105 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `scripts/merge_check.py` (+40 -7) ➕ `tests/test_merge_check_safety.py` (+65 -0) </details> ### 📄 Description Claimed in the coordination issue as: MERGE-CHECK-OPTION-INJECTION-BOUNDS-AND-GIT-TIMEOUT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194083451) ### What and why - Add `_validate_ref()` in `scripts/merge_check.py` to reject empty, padded, or hyphen-prefixed git refs in `--main` and `PR=REF` (blocking git CLI option injection such as `12=--all` or `--main=--exec=...`). - Validate PR numbers cleanly in `parse_pair()` (`>= 1` ASCII integer with at most one leading `#`, rejecting `0=main` and `##12=main`) and add `_positive_int` (`--depth >= 1`) and `_nonnegative_int` (`--min-length >= 0`) bounds validators. - Add `GIT_TIMEOUT = 120` in `git()`, converting `subprocess.TimeoutExpired` into `GitError` so hung git invocations return clean exit code `2` with a `merge_check:` diagnostic. - Add standard-library unit tests in `tests/test_merge_check_safety.py`. ### Tested - `python -I tests/test_merge_check_safety.py -v`: 2 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails with 9 subtest failures and 1 error). - `python -I tests/test_merge_check.py -v`: 24 passed, 0 failed. - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q scripts/merge_check.py tests/test_merge_check_safety.py`, and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <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#2338
No description provided.