Skip to content

fix(reporting): preserve SARIF findings on cyclic symbolic links - #722

Merged
rng1995 merged 11 commits into
NVIDIA:mainfrom
Afloat16:fix/sarif-symlink-loop-locations
Nov 19, 2026
Merged

rng1995 merged 11 commits into
NVIDIA:mainfrom
Afloat16:fix/sarif-symlink-loop-locations

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On Python 3.12, Path.resolve(strict=False) still raises RuntimeError for a symbolic-link loop. A finding whose file is such a link therefore aborts the entire SARIF report, including unrelated findings.

Resolve report locations with the standard library's non-strict os.path.realpath behavior, retaining the link location when the chain cannot be fully resolved. Apply this consistently to scan roots, workspace roots, and artifact paths. Existing workspace-relative paths, external file URIs, and the lexical fallback for links outside the workspace use the same reporting logic.

Merge and current verification (2026-11-19)

At 6cdfe1676b55603c038e24a40ef267127286727c, merged upstream main ac9fc0ef4999ee5eb86eae27ec3a83c880891c92. The only conflict was in CHANGELOG.md; this PR's release note and the upstream independent-diagnostics note are both retained. This PR's non-changelog files are byte-for-byte unchanged from 20ce63304d28bc45bb0910c28d44ea66c8f77bd8.

Re-ran tests/reporting/test_sarif_symlink_loops.py, tests/reporting/test_reporters.py::TestSARIFReporter and tests/reporting/test_junit_reporter.py: 80 passed on Linux with Python 3.12.14. Also passed python -m ruff check src tests, Ruff formatting for the changed Python files, the OSS boundary check, and python -m build (wheel and sdist). Hosted workflows for this merge commit await maintainer approval.

Previous verification

The four initial regressions fail on the unchanged implementation under Python 3.12. The final parameterized coverage exercises self-links and two-link cycles, relative and absolute finding paths, and reports with and without a workspace root.

python -m pytest tests/reporting/test_sarif_symlink_loops.py tests/reporting/test_reporters.py::TestSARIFReporter -q — 25 passed, including existing escaping, external-path, and ordinary SARIF cases.

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes (Unreleased changelog)
  • Ran make lint equivalent: python -m ruff check src tests
  • Full make test did not complete successfully in this environment (see below)
  • Ran make build equivalent: python -m build (wheel and sdist)
  • Did not add credentials, private datasets, or proprietary benchmark content

The unchanged base 8fe9723, tested with python -m pytest -x -q, stops after 456 passed and 19 deselected at tests/ci/test_gateway_benchmark_workflows.py::test_gitlab_enriched_tier1_applies_the_keyless_job_baselines[extra0-expected0]. The sandbox has no /tmp, while that workflow fixture explicitly invokes mktemp -d /tmp/skillevaluator-enriched-tier1.XXXXXX. The same test fails for the same reason on the retry branch. No full-suite pass is claimed.

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this is a real one and the fix is the right size. I built a self-link and a two-link cycle in a temp directory and ran the reporter on main under Python 3.12: render_all raises RuntimeError: Symlink loop and the ordinary findings in the same report are lost with it. On this branch the same input renders all three results with skills/demo/loop.md (workspace case) and a file: URI (no workspace). The 8 new cases fail without the source change and pass with it, and the existing SARIF reporter tests still pass.

Using os.path.realpath is a safe swap here: on 3.12 Path.resolve() is realpath plus a stat() whose only job is to raise on ELOOP, so non-loop paths resolve exactly as before, and 3.13+ already behaves this way. Nothing else in the package imports these helpers, so the change is contained. CHANGELOG line is under Unreleased. Looks good to me.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, @Afloat16, for retaining SARIF findings on cyclic symbolic links. Strict loop detection before the non-strict missing-path fallback also addresses the earlier expanding-cycle artifact-identity issue. I found no new actionable issues on this head.

Validation: 35 focused tests passed, covering self/two-link cycles, expanding cycles, workspace-relative and absolute URIs, simulated Windows error 1921, and existing SARIF behavior.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Second look after the ELOOP follow-up: the new fallback breaks the workspace-containment rule the rest of this module enforces.

_resolve_for_reporting returns path.absolute() unchanged when it hits ELOOP, and Path.relative_to in _workspace_relative_path is purely lexical. So a finding path with .. that ends at a symlink loop outside the workspace now comes out as a repo-relative URI. With workspace ws/, scan root ws/skills/demo and a finding on ../../elsewhere/loop.md (a self-loop), this branch writes skills/demo/../../elsewhere/loop.md into SARIF and the JUnit case name. The same finding on a regular file at that path correctly gets a file:// URI, and _unresolved_artifact_path already refuses .. for exactly this reason. Un-normalised skills/demo/../skills/demo/loop.md and unresolved symlinked directory components (skills/demo/updir/demo/loop.md) show up the same way, where every other location in the report is canonical.

Suggest resolving as far as the parent in the fallback, e.g. Path(os.path.realpath(path.parent, strict=False)) / path.name (or normpath when nothing before the loop is a link), so the containment check runs on a normalised path, and adding a ../ case to the new test.

Not blocking: _junit_file_path keeps its own path.resolve().relative_to(scan_root.resolve()) for paths outside the workspace, so JUnit still raises RuntimeError on a cyclic link outside the repo root while SARIF now succeeds. Worth routing it through the same helper.

Nit: the changelog says locations are resolved "as far as possible"; on a loop the code returns the link path as given.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Afloat16 for this contribution! I reviewed 0df92f589d. I reproduced the problem on main, confirmed this change fixes it, checked that the new tests fail on main, and ran the new and related tests on this head (all pass). I left 1 inline comment (1 P3); please take a look.

Comment thread CHANGELOG.md Resolved
… checks

Resolve ordinary parent symlinks and dot segments before retaining the named cyclic suffix, keeping expanding cycles stable. Reuse the loop-safe helper for the JUnit scan-root fallback and cover public SARIF/JUnit locations on Python 3.12 and 3.14. Merge current main and keep the changelog entry under Unreleased.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Addressing the workspace-containment follow-up, fixed in 5772092. The ELOOP fallback now resolves the longest ordinary parent prefix first, then restores the named cyclic suffix and normalizes dot segments before any workspace-containment check. This keeps paths through ordinary symlink parents and .. canonical without repeatedly expanding a cyclic parent. JUnit now uses the same loop-safe helper in its scan-root fallback, so an out-of-workspace cycle also remains reportable on Python 3.12.

The regression coverage exercises SARIF and JUnit through four real path layouts (outside via parent segments, inside via parent segments, an ordinary symlink parent, and a cyclic parent), with both simple and expanding cycles. It checks absolute external locations, relative workspace locations, percent escaping, and stable repeated resolution. A separate simulated Windows error-1921 case verifies the same fallback; this is not a native Windows test claim.

Validation: the new coverage reproduced 13 failures before the fix, with 20 controls passing. The complete symlink-loop, SARIF reporter, and JUnit reporter suites now pass on both Python 3.12 and Python 3.14: 271 tests on each interpreter. Full ruff check src tests, changed-file formatting, and git diff --check pass.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Afloat16 for this contribution and for addressing the earlier review! I re-checked 20ce63304d: all 1 earlier comment is resolved in the code, the tests pass, and I found nothing new. Approving.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Confirmed on this head: a cyclic link reached through parent segments outside the workspace now gets a file: URI in SARIF and the absolute location in JUnit (no more RuntimeError there), links inside the workspace via '..' or a symlinked parent come out as the canonical repo-relative path, and plain files through the same paths are unchanged. The expanded cases cover both reporters. Thanks.

Resolve the CHANGELOG.md conflict by retaining this PR's entry and the upstream independent-diagnostics entry.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Afloat16 and others added 3 commits November 19, 2026 17:17
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
@rng1995
rng1995 enabled auto-merge (squash) November 19, 2026 20:37
@rng1995
rng1995 merged commit 6abca0b into NVIDIA:main Nov 19, 2026
26 checks passed
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.

3 participants