Repository navigation
fix: fail closed on verdict errors and resolve npm aliases - #7
Conversation
probe() marked a response with no verdict status as a server error but
returned last_error, which is None when the error body is JSON. A 429
from the API's throttler ({"statusCode":429,...}) therefore came back as
an advisory "unknown", error_count stayed 0, the comment said every
dependency looked clean, and the workflow passed. Report the HTTP status
as the error so these runs end in ERROR, as the README describes.
Co-authored-by: Claude <noreply@anthropic.com>
The verdict API allows about 100 lookups a minute per IP, so a PR that adds or regenerates a lockfile (432 packages for a new Next.js app) got 429s for most lookups. With the fail-closed commit those runs end in ERROR; retrying after the server's retry-after-* window (1-60 s), at most HFW_RATE_LIMIT_RETRIES times per lookup (default 6), lets them finish with a verdict for every package. Co-authored-by: Claude <noreply@anthropic.com>
npm writes `foo@npm:bar@1.0.0` as node_modules/foo with "name": "bar". The package-lock parser used the key, so an aliased package was checked under the alias name and a malicious version passed. Use `name` when present, as hacktron.ai/tools/package already does. Co-authored-by: Claude <noreply@anthropic.com>
| if exc.code == 429 and retries > 0: | ||
| wait = _retry_after_seconds(exc.headers) | ||
| exc.close() | ||
| time.sleep(wait) | ||
| return http_get_json(url, timeout, retries - 1) |
There was a problem hiding this comment.
P59-FD-2302: Per-coordinate 429 retries can exhaust the CI job time budget
./dependency-scan/scripts/hfw_report.py:180-184 http_get_json sleeps for the server-selected delay and retries each HTTP 429 up to the default six times. A pull-request author only needs to add many distinct syntactically valid coordinates to a supported manifest, and the verdict service must rate-limit the resulting request burst. The scan can then spend up to 360 seconds sleeping for each coordinate while the executor processes the queued work in four-worker waves. This delays the report step and can make the dependency check hit the workflow job timeout before it produces a verdict.
Steps to Reproduce
-
Create a pull-request branch whose base revision does not contain
package-lock.json. Run the separate Python script in thepython_scriptfield at the repository root to create a supported head manifest with 100 distinct package coordinates. -
Run the composite action with
HFW_RATE_LIMIT_RETRIESunset so it uses the default six retries and with the defaultHFW_PARALLELvalue of four. Configure the inheritedHFW_SERVERenvironment variable to a test verdict endpoint that returns HTTP 429 andRetry-After: 1for every/verdict/...request. The same behavior can be observed against the normal verdict service when this pull request causes it to rate-limit the request burst. -
Check the report-step logs for
querying verdicts for 100 package(s) ... parallel=4, and check the test endpoint request log for repeated requests for each coordinate. Each coordinate should receive its initial request plus six retries, with a one-second sleep between retry attempts. -
Check that the report step remains active while the four worker threads sleep and drain the queued coordinates. With
Retry-After: 60, the same response pattern permits up to 360 seconds of sleep per coordinate and can prevent the workflow from completing before its job timeout.
import json
from pathlib import Path
count = 100
packages = {
"": {
"name": "rate-limit-retry-poc",
"version": "1.0.0",
}
}
for index in range(count):
packages[f"node_modules/@hfw-poc/package-{index:04d}"] = {
"version": "1.0.0"
}
Path("package-lock.json").write_text(
json.dumps(
{
"name": "rate-limit-retry-poc",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": True,
"packages": packages,
},
indent=2,
)
+ "\n",
encoding="utf-8",
)Fix with AI
A security vulnerability was found by Hacktron.
File: scripts/hfw_report.py
Lines: 180-184
Severity: medium
Vulnerability: Per-coordinate 429 retries can exhaust the CI job time budget
Description:
[./dependency-scan/scripts/hfw_report.py:180-184](./dependency-scan/scripts/hfw_report.py:180-184) `http_get_json` sleeps for the server-selected delay and retries each HTTP 429 up to the default six times. A pull-request author only needs to add many distinct syntactically valid coordinates to a supported manifest, and the verdict service must rate-limit the resulting request burst. The scan can then spend up to 360 seconds sleeping for each coordinate while the executor processes the queued work in four-worker waves. This delays the report step and can make the dependency check hit the workflow job timeout before it produces a verdict.
Proof of Concept:
**Steps to Reproduce**
1. Create a pull-request branch whose base revision does not contain `package-lock.json`. Run the separate Python script in the `python_script` field at the repository root to create a supported head manifest with 100 distinct package coordinates.
2. Run the composite action with `HFW_RATE_LIMIT_RETRIES` unset so it uses the default six retries and with the default `HFW_PARALLEL` value of four. Configure the inherited `HFW_SERVER` environment variable to a test verdict endpoint that returns HTTP 429 and `Retry-After: 1` for every `/verdict/...` request. The same behavior can be observed against the normal verdict service when this pull request causes it to rate-limit the request burst.
3. Check the report-step logs for `querying verdicts for 100 package(s) ... parallel=4`, and check the test endpoint request log for repeated requests for each coordinate. Each coordinate should receive its initial request plus six retries, with a one-second sleep between retry attempts.
4. Check that the report step remains active while the four worker threads sleep and drain the queued coordinates. With `Retry-After: 60`, the same response pattern permits up to 360 seconds of sleep per coordinate and can prevent the workflow from completing before its job timeout.
```python
import json
from pathlib import Path
count = 100
packages = {
"": {
"name": "rate-limit-retry-poc",
"version": "1.0.0",
}
}
for index in range(count):
packages[f"node_modules/@hfw-poc/package-{index:04d}"] = {
"version": "1.0.0"
}
Path("package-lock.json").write_text(
json.dumps(
{
"name": "rate-limit-retry-poc",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": True,
"packages": packages,
},
indent=2,
)
+ "\n",
encoding="utf-8",
)
```
Affected Code:
if exc.code == 429 and retries > 0:
wait = _retry_after_seconds(exc.headers)
exc.close()
time.sleep(wait)
return http_get_json(url, timeout, retries - 1)
Acceptance criteria:
- Acceptance is defined by the **actual reported behavior**, not by tests passing.
- Reproduce the issue, or narrow the exact code path that produces it, *before* changing code. State what you confirmed.
- Fix the underlying cause. Mitigations that paper over the reported behavior do not count as a fix.
- Add a regression test that fails on the unpatched code and passes on the fix. If a regression test is genuinely impractical (e.g. race condition, infra-level issue), say so and explain why.
- Existing tests passing is **not** the bar. Do not declare done on tests-pass theatre.
Only change what is necessary to fix this vulnerability. Do not refactor adjacent code or modify unrelated files.
Triage: Reply !fp <reason> (false positive), !valid (confirmed), !accepted_risk <reason>, or !fixed (resolved). Any other reply is saved as a triage note.
Reason is optional but improves future scans — e.g. !fp internal endpoint, not user-facing.
A JSON 429 from the verdict API currently becomes an advisory
unknownwitherror_count=0, so a PR can introduce a malicious package and still pass with “All dependencies look clean.” npm aliases can also query the alias name instead of the actual registry package.This PR imports Cheryl Aurelia's fail-closed/retry commits and npm alias follow-up, preserving their authorship. It retries 429s using the longest numeric retry window (1–60 seconds, six retries by default), fails when retries are exhausted, and uses the registry
namefor aliases in npm lockfiles with apackagesmap.Review found a remaining gap in the supplied patch: a truthy
status, including HFW's422 {"status":"error"}, still passed without an error. The additional fix requires a successful HTTP response and a recognized verdict status, validates completed verdict levels, and reports malformed JSON shapes as errors. Failed or incomplete reports no longer claim that every dependency is clean. Valid pending/scanning responses remain advisory; error runs stop before posting the PR comment.Validation:
git diff --checkpass.malicious_count=2; error scenarios exit 3 witherror_count=1.debug@4.4.2andaxios@1.14.1controls currently return malicious verdicts. Rate limiting was simulated locally.Sources: reported demo, fail-closed/retry branch, alias follow-up.