Skip to content

fix: fail closed on verdict errors and resolve npm aliases - #7

Merged
zeyu2001 merged 4 commits into
mainfrom
fix/fail-closed-throttled-verdicts-review
Nov 19, 2026
Merged

zeyu2001 merged 4 commits into
mainfrom
fix/fail-closed-throttled-verdicts-review

Conversation

@zeyu2001

Copy link
Copy Markdown
Member

A JSON 429 from the verdict API currently becomes an advisory unknown with error_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 name for aliases in npm lockfiles with a packages map.

Review found a remaining gap in the supplied patch: a truthy status, including HFW's 422 {"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:

  • 136 tests pass on each of Python 3.11, 3.12, and 3.13.
  • Locked dependency check, Ruff format/lint, script compilation, and git diff --check pass.
  • A temporary caller git repository and loopback HTTP fixture reproduce the upstream bypass, then verify transient-429 recovery, real-name alias lookups (including nested scoped aliases), exhausted retries, JSON scan errors, and non-object JSON responses through manifest extraction and the report CLI. Successful recovery produces malicious_count=2; error scenarios exit 3 with error_count=1.
  • Two read-only live API lookups confirm the demo's debug@4.4.2 and axios@1.14.1 controls currently return malicious verdicts. Rate limiting was simulated locally.

Sources: reported demo, fail-closed/retry branch, alias follow-up.

cherylaurelia and others added 4 commits November 18, 2026 11:02
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>
@zeyu2001
zeyu2001 merged commit f17452c into main Nov 19, 2026
12 checks passed

@hacktron-app-stg hacktron-app-stg Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Severity Count
MEDIUM 1

View full scan results

Comment thread scripts/hfw_report.py
Comment on lines +180 to +184
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Open in Cursor Open in Claude

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.

View finding in Hacktron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants