Skip to content

fix: skip GIT ranges and handle last_affected in OSV version matching - #1499

Open
0z5a wants to merge 1 commit into
oracle:mainfrom
0z5a:fix/osv-git-ranges-last-affected
Open

0z5a wants to merge 1 commit into
oracle:mainfrom
0z5a:fix/osv-git-ranges-last-affected

Conversation

@0z5a

@0z5a 0z5a commented Nov 20, 2026

Copy link
Copy Markdown

Summary

Fixes two of the three cases in #1498 for OSVDevService.is_version_affected(), which the GitHub Actions vulnerability check (mcn_githubactions_vulnerabilities_1) uses:

  • GIT ranges are no longer compared as versions. Before, their commit hashes failed to parse, the range became "from 0 with no fix", and every version matched, including fixed versions.
  • last_affected is now an inclusive upper bound. Before, it was ignored and every later version matched.

The third case in #1498 (only the first matching affected entry is read) is not changed here, see "Not covered".

Description of changes

  • is_version_affected() skips ranges with "type": "GIT". If a record has no other range for the package, it raises APIAccessError like the existing "missing ranges" / "missing events" cases, so the check records the analysis as incomplete instead of guessing.
  • The events of a range are read in order by a new helper _is_version_in_events(). Each introduced starts an interval that ends at the next fixed (exclusive) or last_affected (inclusive). An interval without an end contains all later versions. A side effect is that an events list with more than one introduced / fixed pair now uses all pairs. Before, only the last introduced and the last fixed were kept.
  • The existing behaviour for values that do not parse as versions is kept: an unparsable introduced is treated as 0, an unparsable end means "no end". This is in a second helper, _parse_event_version().
  • The version string is parsed once before the loop instead of once per range.

Related issues

Refs #1498

How I found it

I read is_version_affected() while looking at how the GitHub Actions check matches versions, and then ran it against the current OSV records for the "GitHub Actions" ecosystem to see which record shapes it has to handle. GHSA-5xjx-3w67-w9x9 (pypa/gh-action-pypi-publish) and the compose-lint advisories have a GIT range next to the ECOSYSTEM range, and GHSA-r4fj-r33x-8v88 uses last_affected. For these records the function returned True for versions outside the affected range.

Where this can show up in practice

This is my estimate.

  • A repository that uses a fixed release of an action whose advisory has a GIT range, for example pypa/gh-action-pypi-publish@v1.14.3, gets a finding for that advisory from mcn_githubactions_vulnerabilities_1, and the recommendation is to upgrade although it is already on the fixed version. This affects every GitHub Actions record with a GIT range. GitHub's newer advisories often have one.
  • A repository that uses a release after last_affected gets the same kind of finding.
  • In both cases mcn_githubactions_vulnerabilities_1 fails for the repository, so a pipeline that gates on this check fails until the finding is suppressed.

Testing

New cases in tests/slsa_analyzer/package_registry/test_osv_dev.py. The records are small inline dicts with the same ranges as the real advisories, so the tests do not use the network. The rlespinasse/github-slug-action cases put two intervals into one events list. That shape is synthetic (I did not find it in the current GitHub Actions records), the real advisory has them in two affected entries.

case version main this PR
ECOSYSTEM fixed 1.14.3 + GIT range (pypi-publish) v1.14.3 True (fails) False
same v1.14.2 True True
ECOSYSTEM introduced 0.2.0, fixed 0.31.0 + GIT range (compose-lint) 0.1.0 True (fails) False
same 0.31.0 True (fails) False
only a GIT range 45.0.0 True (fails, expected APIAccessError) APIAccessError
introduced 0, last_affected 0.3.1 (wenxian) 0.3.1 True True
same 0.3.2 True (fails) False
two pairs in one events list: [0, 1.1.1) and [2.0.0, 2.1.1) 1.0.0 False (fails) True
same 1.2.0 False False
same 2.0.0 True True
same 2.1.1 False False
  • pytest tests/slsa_analyzer/package_registry/test_osv_dev.py tests/slsa_analyzer/checks/test_github_actions_vulnerability_check.py: 45 passed. On main with the new tests, 6 of them fail (the rows marked "fails").
  • ruff format --check, ruff check, pylint --rcfile pyproject.toml and mypy --config-file pyproject.toml on the two changed files pass.
  • I also ran the function on the unchanged OSV records: pypi-publish v1.14.3, compose-lint 0.1.0 / 0.31.0 and wenxian 0.3.2 now return False, pypi-publish v1.14.2 and wenxian 0.3.1 still return True.

macOS, Python 3.12.

Not covered

  • Case 3 of [Bug] - OSV version matching flags fixed versions (GIT ranges, last_affected) and misses later affected entries #1498, more than one affected entry for the same package (GHSA-7f32-hm4h-w77q for rlespinasse/github-slug-action@v2.0.0, GHSA-2c6m-6gqh-6qg3 for actions/runner). Reading all entries is what the OSV schema says. But GHSA-vqf5-2xx6-9wfm has a second entry for github/codeql-action that is introduced: 2.26.11 with no fixed, so reading all entries would report it for every current codeql-action release, including the v4 that Macaron's own workflows use. I left this out until it is clear how you want that case handled, and kept it in the issue.
  • The versions list of an affected entry is still not used.
  • Advisories that only have a GIT range are now reported as an incomplete analysis instead of a match. Mapping commit ranges to tags would be a separate change.

Checklist

  • I have reviewed the contribution guide.
  • My PR title and commits follow the Conventional Commits convention.
  • My commits include the "Signed-off-by" line.
  • I have signed my commits following the instructions provided by GitHub. Note that we run GitHub's commit verification tool to check the commit signatures. A green verified label should appear next to all of your commits on GitHub.
  • I have updated the relevant documentation, if applicable.
  • I have tested my changes and verified they work as expected.

OCA pending: I will sign the Oracle Contributor Agreement with the e-mail used in the Signed-off-by line.

OSVDevService.is_version_affected compared the commit hashes of GIT ranges as versions. They failed to parse, so the GIT range matched every version, including fixed ones. last_affected events were ignored, so a range ending in last_affected matched all later versions too, and only the last introduced/fixed pair of an events list was used.

Skip GIT ranges, read the events of each range as a sequence of intervals that end at fixed (exclusive) or last_affected (inclusive), and raise APIAccessError if no non-GIT range is left.

Refs oracle#1498

Signed-off-by: Dezhen Lu <dezhen.lu@student.uni-tuebingen.de>
@0z5a
0z5a requested a review from behnazh-w as a code owner November 20, 2026 08:11
@oracle-contributor-agreement

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Nov 20, 2026

This branch has not been deployed

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

Labels

OCA Required At least one contributor does not have an approved Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant