Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed

- SARIF reporting retains findings on cyclic symbolic links on Python 3.12, resolving
Comment thread
Afloat16 marked this conversation as resolved.
Resolved
artifact locations as far as possible instead of aborting the entire report.
- GitLab JUnit collection includes nested skill folders in catalog reports.
- API caller now percent-encodes scalar OpenAPI path values as individual segments and rejects `.` and `..` values with a JSON input error.
- Direct Tier 1 validates the target, selected checks and LLM configuration before
Expand Down
28 changes: 22 additions & 6 deletions src/skillevaluator/reporting/sarif_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from __future__ import annotations

import errno
import json
import os
import re
Expand Down Expand Up @@ -90,14 +91,29 @@ def _positive_start_line(line_number: Any) -> int | None:
return None


def _resolve_for_reporting(path: Path) -> Path:
"""Resolve accessible paths while retaining the name of a cyclic artifact.

Python 3.12's non-strict ``Path.resolve()`` still raises for link loops.
Non-strict ``realpath`` can instead expand their suffix on each call, so
detect loops strictly before falling back for missing path components.
"""
try:
return Path(os.path.realpath(path, strict=True))
except OSError as exc:
if exc.errno == errno.ELOOP or getattr(exc, "winerror", None) == 1921:
return path.absolute()
return Path(os.path.realpath(path))


def _resolve_artifact_path(file_path: str, scan_root: Path | None) -> Path:
"""Resolve a validator file path against the scanned skill directory."""
normalized = file_path.replace("\\", "/")
path = Path(normalized)
if scan_root is not None and not path.is_absolute():
return (scan_root / path).resolve()
return _resolve_for_reporting(scan_root / path)
if path.is_absolute():
return path.resolve()
return _resolve_for_reporting(path)
return path


Expand Down Expand Up @@ -147,7 +163,7 @@ def _unresolved_artifact_path(file_path: str, scan_root: Path | None) -> Path |
if not path.is_absolute():
if scan_root is None:
return None
path = scan_root.resolve() / path
path = _resolve_for_reporting(scan_root) / path
return Path(os.path.normpath(path))


Expand All @@ -163,8 +179,8 @@ def _workspace_relative_path(
target is outside it keeps the path of the link, which is what the
finding is about.
"""
root = workspace_root.resolve()
candidates = [path.resolve()]
root = _resolve_for_reporting(workspace_root)
candidates = [_resolve_for_reporting(path)]
unresolved = _unresolved_artifact_path(file_path, scan_root)
if unresolved is not None:
candidates.append(unresolved)
Expand Down Expand Up @@ -193,7 +209,7 @@ def _normalize_artifact_uri(
relative = _workspace_relative_path(path, file_path, workspace_root, scan_root)
if relative is not None:
return _relative_reference(relative.as_posix())
return _file_uri(path.resolve())
return _file_uri(_resolve_for_reporting(path))
if path.is_absolute():
return _file_uri(path)
return _relative_reference(path.as_posix())
Expand Down
67 changes: 67 additions & 0 deletions tests/reporting/test_sarif_symlink_loops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Findings about cyclic links must remain exportable to SARIF."""

import errno
import json
from pathlib import Path

import pytest

from skillevaluator.models import Finding, Severity, ValidationResult
from skillevaluator.reporting import SARIFReporter
from skillevaluator.reporting.sarif_reporter import _resolve_for_reporting


@pytest.mark.parametrize("relative", [False, True])
@pytest.mark.parametrize("two_links", [False, True])
@pytest.mark.parametrize("with_workspace", [False, True])
@pytest.mark.parametrize("expanding", [False, True])
def test_sarif_preserves_a_finding_on_a_symlink_loop(
tmp_path: Path, relative: bool, two_links: bool, with_workspace: bool, expanding: bool
) -> None:
skill = tmp_path / "skills" / "demo"
skill.mkdir(parents=True)
link = skill / "loop.md"
try:
target = "other.md" if two_links else "loop.md"
link.symlink_to(f"{target}/child" if expanding else target)
if two_links:
(skill / "other.md").symlink_to("loop.md")
except OSError:
pytest.skip("symlinks are not available")
result = ValidationResult(validator_name="security")
result.add_finding(
Finding(
category="SECURITY",
severity=Severity.HIGH,
check_name="unsafe-link",
message="The resource is a cyclic symbolic link",
file_path="loop.md" if relative else str(link),
)
)

output = SARIFReporter(workspace_root=tmp_path if with_workspace else None, scan_root=skill).render_all([result])

findings = json.loads(output)["runs"][0]["results"]
assert len(findings) == 1
expected = "skills/demo/loop.md" if with_workspace else link.as_uri()
assert findings[0]["locations"][0]["physicalLocation"]["artifactLocation"]["uri"] == expected
assert findings[0]["message"]["text"] == "The resource is a cyclic symbolic link"


def test_windows_loop_error_preserves_the_named_artifact(monkeypatch, tmp_path: Path) -> None:
path = tmp_path / "loop.md" / ".." / "named.md"
error = OSError(errno.EINVAL, "The name of the file cannot be resolved by the system")
error.winerror = 1921

def realpath(value, *, strict=False):
if strict:
raise error
return f"{value}/child"

monkeypatch.setattr("skillevaluator.reporting.sarif_reporter.os.path.realpath", realpath)

assert _resolve_for_reporting(path) == path.absolute()
assert _resolve_for_reporting(_resolve_for_reporting(path)) == path.absolute()
Loading