Repository navigation
fix(reporting): preserve SARIF findings on cyclic symbolic links - #722
Conversation
Signed-off-by: Afloat <ShuffleMonkey@163.com>
chrisknvidia
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
… 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>
|
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 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 |
Signed-off-by: Afloat <ShuffleMonkey@163.com>
chrisknvidia
left a comment
There was a problem hiding this comment.
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>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Summary
On Python 3.12,
Path.resolve(strict=False)still raisesRuntimeErrorfor 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.realpathbehavior, 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 mainac9fc0ef4999ee5eb86eae27ec3a83c880891c92. The only conflict was inCHANGELOG.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 from20ce63304d28bc45bb0910c28d44ea66c8f77bd8.Re-ran
tests/reporting/test_sarif_symlink_loops.py,tests/reporting/test_reporters.py::TestSARIFReporterandtests/reporting/test_junit_reporter.py: 80 passed on Linux with Python 3.12.14. Also passedpython -m ruff check src tests, Ruff formatting for the changed Python files, the OSS boundary check, andpython -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.make lintequivalent:python -m ruff check src testsmake testdid not complete successfully in this environment (see below)make buildequivalent:python -m build(wheel and sdist)The unchanged base
8fe9723, tested withpython -m pytest -x -q, stops after 456 passed and 19 deselected attests/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 invokesmktemp -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
CHANGELOG.md