Repository navigation
Validate the Rulesets Response Before ruleset_id() Reads It (#1971) - #1988
Conversation
## Summary `repo-config/configure.sh`'s `ruleset_id()` per_page guard fails open on any non-array 2xx response from the rulesets API, not only the CR-mangled case #1880/#1972 fixed, because the guard's own comparison failure inside its `$(...)` subshell never reaches `set -e` (no `inherit_errexit`). ## The defect On a non-array response, `jqr 'length'` prints nothing, so the `[ "" -eq 100 ]` guard fails silently rather than tripping, and the following `ids=` extraction likewise falls through empty rather than aborting. `ruleset_id` returns 0, which both call sites read as "not found": the apply site would create a duplicate ruleset by name, and the check site would misreport "not found" instead of aborting. ## Fix Validate `$out` is a JSON array (`jq_has 'type == "array"' <<<"$out"`, matching the `entries` guard's own pattern) before either the per_page guard or the `ids=` extraction reads it, aborting with a "could not read live ruleset state" message on failure. ## Verification - New `tests/test_configure_ruleset_id.py` lifts `ruleset_id()`'s own lines and exercises it through a stubbed `gh`, invoked the way both real call sites invoke it (`id="$(ruleset_id ...)"`), which is what exposes the subshell-errexit defect. - Confirmed by reverting the fix: every non-array-response case then returns exit 0 with empty stdout (the "not found" misread), and the pre-existing per_page-cap, gh-failure, and duplicate-name cases stay passing throughout. - `shellcheck` and `shfmt -d` clean on `repo-config/configure.sh`. - `python3 -m unittest discover -s tests` (1777 tests), `python3 scripts/repo_gate.py`, and `python3 spec/validate.py` all pass. Closes on promotion: #1971 Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1988 +/- ##
==========================================
Coverage ? 55.42%
==========================================
Files ? 16
Lines ? 7249
Branches ? 0
==========================================
Hits ? 4018
Misses ? 3231
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change correctly blocks the confirmed fail-open path by type-checking the rulesets response before parsing, and the added tests cover both the new abort behavior and the preserved existing guard cases.
Review effort: Lite
Findings: None
What changed in this PR
This pull request hardens repo-config/configure.sh’s ruleset_id() lookup against malformed-but-2xx GitHub API responses by validating the response shape before parsing, and adds a targeted regression test that exercises the function via the same command-substitution call pattern used in production.
Changes:
- Add a
jq_has 'type == "array"'guard inruleset_id()to abort on non-array responses before the length check and id extraction run. - Add
tests/test_configure_ruleset_id.pyto run liftedruleset_id()lines with a stubbedgh, covering the non-array 2xx failure mode and preserving existing guard behaviors.
| File | Description |
|---|---|
| tests/test_configure_ruleset_id.py | Adds an offline unittest harness that lifts ruleset_id() and stubs gh to validate failure propagation under command substitution. |
| repo-config/configure.sh | Validates the rulesets API response is a JSON array before evaluating length or extracting ids, preventing false “not found” reads. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
… and Setup Tooling (#2000) ## Summary Promotes develop to main, carrying the 16 pull requests merged to develop since #1943. - **Wait-loop guard (requirement 7):** [#1999](#1999) credits a comparison bound only inside a `[`, `[[`, or `test` invocation, and [#1996](#1996) reconciles the requirement's README count and diagram with its hook. - **Registry:** [#1994](#1994) and [#1976](#1976) record Vantage-Config's line endings and description. - **Scripts and tooling:** - [#1988](#1988) and [#1972](#1972) harden `ruleset_id()`. - [#1974](#1974) and [#1949](#1949) fix `pr_review.py` `reply --match` and `wait`. - [#1969](#1969), [#1964](#1964), [#1954](#1954) and [#1951](#1951) fix host-setup tool shadowing, shims, hook ownership and dpkg ownership checks. - **Gates and audit:** - [#1980](#1980) triages a path collision. - [#1967](#1967) and [#1962](#1962) tighten sha-pin and version-literal checks. - [#1956](#1956) keeps a folded `if:` visible to the interface audit. Closes #1636 Closes #1639 Closes #1948 Closes #1971 Closes #1718 Closes #1934 Closes #1877 Closes #1880 Closes #1865 Closes #1889 Closes #1966 Closes #1906 Closes #1935 Closes #1901 Closes #1905 Closes #1866 Closes #1897 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
repo-config/configure.sh'sruleset_id()per_page guard fails open onany non-array 2xx response from the rulesets API, not only the CR-mangled
case #1880/#1972 fixed, because the guard's own comparison failure inside
its
$(...)subshell never reachesset -e(noinherit_errexit).The defect
On a non-array response,
jqr 'length'prints nothing, so the[ "" -eq 100 ]guard fails silently rather than tripping, and thefollowing
ids=extraction likewise falls through empty rather thanaborting.
ruleset_idreturns 0, which both call sites read as "notfound": the apply site would create a duplicate ruleset by name, and the
check site would misreport "not found" instead of aborting.
Fix
Validate
$outis a JSON array (jq_has 'type == "array"' <<<"$out",matching the
entriesguard's own pattern) before either the per_pageguard or the
ids=extraction reads it, aborting with a "could not readlive ruleset state" message on failure.
Verification
tests/test_configure_ruleset_id.pyliftsruleset_id()'s ownlines and exercises it through a stubbed
gh, invoked the way both realcall sites invoke it (
id="$(ruleset_id ...)"), which is what exposesthe subshell-errexit defect.
returns exit 0 with empty stdout (the "not found" misread), and the
pre-existing per_page-cap, gh-failure, and duplicate-name cases stay
passing throughout.
shellcheckandshfmt -dclean onrepo-config/configure.sh.python3 -m unittest discover -s tests(1777 tests),python3 scripts/repo_gate.py, andpython3 spec/validate.pyall pass.defects. It flagged one comment-wording inaccuracy (fixed) and one
pre-existing gap in the
ids=extraction for a malformed arrayelement, filed separately as ruleset_id()'s ids= Extraction Still Misreads a Malformed Ruleset Array Element #1987 rather than expanding this fix's
scope.
Closes on promotion: #1971
🤖 Generated with Claude Code