Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,16 @@ All notable changes to SkillEvaluator are documented in this file.
without its findings, as with `complete_with_caveats` from an earlier
release.

- A Tier 1 security scan keeps a SkillSpector `partial` or
`complete_with_caveats` report `INCOMPLETE`, instead of passing with the
missing-reference warning above, when the report lists a `missing` reference
on a line that has no ledger row, lists an `ambiguous` reference on any
line, or flags one of its lists as truncated with a key that ends in
`_truncated`, such as `ledger_exceptions_truncated`. Only the line of a
ledger row is checked for a file left out of the scanned copy, so the line of
a reference without a row, or one that a truncated list left out, could name
a file such as `versions/install.sh` and pass unnoticed.

- A PII finding no longer keeps its `evidence_sha256` after CI redaction masks
a credential inside the value the finding reports. In 0.8.0 the finding kept
the digest of the unmasked value, so anyone holding the redacted report could
Expand Down
74 changes: 62 additions & 12 deletions src/skillevaluator/validators/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,18 @@ def _skillspector_provider_retry_row(row: object) -> bool:
)


def _skillspector_flags_truncation(container: Mapping[str, object]) -> bool:
"""Return whether a report object has a ``*_truncated`` key that is neither ``false`` nor ``null``.

SkillSpector flags a list it cut short this way, as in
``ledger_exceptions_truncated``, and what it left out may be a different gap.
"""
return any(
isinstance(key, str) and key.endswith("_truncated") and value is not False and value is not None
for key, value in container.items()
)


def _skillspector_provider_retries_exhausted(data: object) -> bool:
"""Return whether a failed LLM-stage report shows only an LLM provider outage.

Expand Down Expand Up @@ -547,10 +559,7 @@ def _skillspector_provider_retries_exhausted(data: object) -> bool:
if any(container.get(key) for key in _SKILLSPECTOR_REPORT_FAILURE_MARKERS):
return False
# A truncated list may hide a different cause.
if any(
isinstance(key, str) and key.endswith("_truncated") and value is not False and value is not None
for key, value in container.items()
):
if _skillspector_flags_truncation(container):
return False

rows = completeness.get("ledger_exceptions")
Expand Down Expand Up @@ -2264,6 +2273,32 @@ def _skillspector_missing_reference_warning(rows: list[Mapping[str, object]]) ->
)


def _skillspector_missing_references_have_rows(references: list, rows: list[Mapping[str, object]]) -> bool:
"""Whether each ``missing`` entry of *references* is on the line of a ledger row in *rows*, and none is ``ambiguous``.

Only the line of a row is read for the names it holds
(:func:`_skillspector_reference_line_avoids`), so a ``missing`` entry on
any other line, which SkillSpector reported without a row, would never be.
"""
lines = {(row.get("path"), row.get("start_line")) for row in rows}
for reference in references:
if not isinstance(reference, dict):
continue
status = reference.get("status")
if status == "ambiguous":
return False
if status == "missing":
path, line = reference.get("source_path"), reference.get("line")
if (
not isinstance(path, str)
or isinstance(line, bool)
or not isinstance(line, int)
or (path, line) not in lines
):
return False
return True


def _skillspector_missing_reference_notes(
ledger_exceptions: list[dict],
analyzer_statuses: list[dict],
Expand All @@ -2273,6 +2308,7 @@ def _skillspector_missing_reference_notes(
components: object,
scanned_root: Path | None,
*,
completeness: Mapping[str, object],
references: object,
skillspector_version: tuple[int, int, int] | None,
reference_root: Path | None,
Expand All @@ -2291,14 +2327,20 @@ def _skillspector_missing_reference_notes(
skill that SkillSpector did not inspect (:func:`_skillspector_unscanned_names`,
:func:`_skillspector_reference_line_avoids`, with one work budget for all
of the report's lines), such as a link or a file in an artifact directory
left out of a staged scan, and there is no fatal scope exclusion. Any
other ledger rows must be referenced images that
:func:`_skillspector_passive_raster_note` accepts, which then accounts for
the counts, analyzers and limitations, and its note follows. Without them,
no file is partially or entirely uninspected, no finding was filtered out,
there is no limitation, every analyzer is ``completed``, ``not_applicable``
or ``disabled``, and each universal analyzer completed one work item per
component. Anything else keeps the scan INCOMPLETE.
left out of a staged scan, and there is no fatal scope exclusion. Those rows
must also account for the report's ``references``: each ``missing`` entry is
on the line of one of them
(:func:`_skillspector_missing_references_have_rows`), none is ``ambiguous``,
and no ``*_truncated`` key of *completeness* (the report's
``analysis_completeness``) is set, because a list that SkillSpector cut
short may hide a line that nothing here reads. Any other ledger rows must be
referenced images that :func:`_skillspector_passive_raster_note` accepts,
which then accounts for the counts, analyzers and limitations, and its note
follows. Without them, no file is partially or entirely uninspected, no
finding was filtered out, there is no limitation, every analyzer is
``completed``, ``not_applicable`` or ``disabled``, and each universal
analyzer completed one work item per component. Anything else keeps the
scan INCOMPLETE.

*reference_root* is the root of the artifact that the scan belongs to,
and the gap is accepted only when it is *scanned_root* itself. Another
Expand Down Expand Up @@ -2327,6 +2369,10 @@ def _skillspector_missing_reference_notes(
row, skillspector_version, references
):
return None
if _skillspector_flags_truncation(completeness) or not _skillspector_missing_references_have_rows(
references, reference_rows
):
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
return None

notes = [_skillspector_missing_reference_warning(reference_rows)]
if other_rows:
Expand Down Expand Up @@ -2413,6 +2459,7 @@ def _skillspector_reference_caveat_notes(
components: object,
scanned_root: Path | None,
*,
completeness: Mapping[str, object],
references: object,
skillspector_version: tuple[int, int, int] | None,
reference_root: Path | None,
Expand All @@ -2438,6 +2485,7 @@ def _skillspector_reference_caveat_notes(
scope_exclusions,
components,
scanned_root,
completeness=completeness,
references=references,
skillspector_version=skillspector_version,
reference_root=reference_root,
Expand Down Expand Up @@ -3650,6 +3698,7 @@ def _validate_skillspector_report(
analysis_completeness.get("scope_exclusions", []),
data.get("components"),
scanned_root,
completeness=analysis_completeness,
references=analysis_completeness.get("references"),
skillspector_version=skillspector_version,
reference_root=reference_root,
Expand Down Expand Up @@ -3682,6 +3731,7 @@ def _validate_skillspector_report(
analysis_completeness.get("scope_exclusions", []),
data.get("components"),
scanned_root,
completeness=analysis_completeness,
references=analysis_completeness.get("references"),
skillspector_version=skillspector_version,
reference_root=reference_root,
Expand Down
150 changes: 150 additions & 0 deletions tests/validators/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -9189,6 +9189,7 @@ def _missing_reference_notes(payload: dict, scanned_root: Path | None, **options
completeness["scope_exclusions"],
payload["components"],
scanned_root,
completeness=completeness,
references=completeness.get("references"),
skillspector_version=version,
**options,
Expand Down Expand Up @@ -9521,6 +9522,154 @@ def test_report_accounting_must_match_a_fully_inspected_bundle(self, tmp_path: P
payload["analysis_completeness"]["analyzer_statuses"].remove(universal)
assert _missing_reference_notes(payload, skill) is None

@staticmethod
def _install_script_case(tmp_path: Path, version: str) -> tuple[Path, dict, str]:
"""The notes writer with a second line that runs ``versions/install.sh``, which the scanned copy leaves out.

The report is the capture for the first line only, with the line count of ``SKILL.md`` raised to match.
"""
line = "Also run `versions/install.sh` and write the log to `output/log.txt`."
skill = _write_skill(
tmp_path / "notes-writer",
{
**_NOTES_WRITER_FILES,
"SKILL.md": f"{_NOTES_WRITER_FILES['SKILL.md']}\n{line}\n",
"versions/install.sh": "#!/bin/sh\necho ready\n",
},
)
payload = _reference_report(version)
next(component for component in payload["components"] if component["path"] == "SKILL.md")["lines"] += 2
return skill, payload, line

@staticmethod
def _assert_refused(result: ValidationResult, version: str) -> None:
row = "SKILL.md:10 [reference_resolution; reference_missing]"
assert result.is_incomplete
assert result.incomplete_scans == ["skillspector"]
assert result.errors == [
_caveat_error(row)
if version == "2.13.4"
else f"skillspector JSON field 'analysis_completeness' reports incomplete analysis (status 'partial'): "
f"{row}; security scan did not complete"
]
assert not result.warnings
assert "skillspector_reference_caveats" not in result.metadata

@pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"])
@patch("skillevaluator.validators.security.Tools")
def test_line_naming_a_file_left_out_of_the_scan_stays_incomplete_with_a_row(
self, mock_tools, tmp_path: Path, version: str
) -> None:
"""The second line of ``_install_script_case`` is refused once SkillSpector gives it a row."""
skill, payload, line = self._install_script_case(tmp_path, version)
completeness = payload["analysis_completeness"]
completeness["ledger_exceptions"].append(
{**completeness["ledger_exceptions"][0], "start_line": 12, "end_line": 12}
)
completeness["references"].append(
{
"source_path": "SKILL.md",
"line": 12,
"column": 11,
"evidence": line,
"target_path": None,
"status": "missing",
"disposition": "partial",
"reference_kind": "quoted_or_code",
}
)

result = _validate_skillspector_payload(mock_tools, skill, payload)

assert mock_tools.skillspector.run.call_args.args[0][1] != str(skill.resolve())
assert result.incomplete_scans == ["skillspector"]
assert not result.warnings

@pytest.mark.parametrize("status", ["missing", "ambiguous"])
@pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"])
@patch("skillevaluator.validators.security.Tools")
def test_reference_without_a_ledger_row_stays_incomplete(
self, mock_tools, tmp_path: Path, version: str, status: str
) -> None:
"""Nothing reads the line of a reference that has no row, so it could name a file the scan left out."""
skill, payload, line = self._install_script_case(tmp_path, version)
payload["analysis_completeness"]["references"].append(
{
"source_path": "SKILL.md",
"line": 12,
"column": 11,
"evidence": line,
"target_path": None,
"status": status,
"disposition": "partial",
"reference_kind": "quoted_or_code",
}
)

result = _validate_skillspector_payload(mock_tools, skill, payload)

self._assert_refused(result, version)

@pytest.mark.parametrize("flag", ["ledger_exceptions_truncated", "references_truncated"])
@pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"])
@patch("skillevaluator.validators.security.Tools")
def test_truncated_report_stays_incomplete(self, mock_tools, tmp_path: Path, version: str, flag: str) -> None:
"""A list SkillSpector cut short may leave out the line that names a file the scan left out."""
skill, payload, _line = self._install_script_case(tmp_path, version)
payload["analysis_completeness"][flag] = True

result = _validate_skillspector_payload(mock_tools, skill, payload)

self._assert_refused(result, version)

@pytest.mark.parametrize("value", [False, None])
@pytest.mark.parametrize("flag", ["ledger_exceptions_truncated", "references_truncated"])
@pytest.mark.parametrize("version", ["2.12.0", "2.13.3", "2.13.4"])
@patch("skillevaluator.validators.security.Tools")
def test_truncation_flag_that_is_not_set_does_not_block(
self, mock_tools, tmp_path: Path, version: str, flag: str, value: object
) -> None:
skill = _write_skill(tmp_path / "notes-writer", _NOTES_WRITER_FILES)
payload = _reference_report(version)
payload["analysis_completeness"][flag] = value

result = _validate_skillspector_payload(mock_tools, skill, payload)

assert result.passed
assert result.incomplete_scans == []
assert len(result.warnings) == 1

def test_every_missing_reference_needs_a_row_on_its_line_and_no_list_is_truncated(self, tmp_path: Path) -> None:
skill = _write_skill(tmp_path / "notes-writer", _NOTES_WRITER_FILES)
missing = {"source_path": "SKILL.md", "line": 8, "status": "missing"}
evidence = "Write the summary to `output/notes.md` and keep it short."

def refused(*extra: object, **flags: object) -> bool:
payload = _reference_report("2.13.3")
payload["analysis_completeness"]["references"].extend(extra)
payload["analysis_completeness"].update(flags)
return _missing_reference_notes(payload, skill) is None

assert not refused()
# Another reference on the line of the row needs no row of its own; a resolved or rejected one never does.
assert not refused({**missing, "line": 10, "evidence": evidence})
assert not refused({**missing, "status": "resolved"}, {**missing, "line": 3, "status": "rejected"})
# A missing reference on another line or in another file has no row, and nothing else reads its line.
assert refused(missing)
assert refused({**missing, "source_path": "scripts/summarize.py", "line": 10})
assert refused({**missing, "source_path": None})
for line in (None, True, "10", 10.0, [10], {"line": 10}):
assert refused({**missing, "line": line}), line
assert refused({**missing, "source_path": ["SKILL.md"], "line": 10})
# No reference elsewhere may be ambiguous either.
assert refused({**missing, "status": "ambiguous"})
assert refused({**missing, "line": 10, "status": "ambiguous"})
for flag in ("ledger_exceptions_truncated", "references_truncated", "scope_exclusions_truncated"):
for value in (True, 1, "yes", ["x"]):
assert refused(**{flag: value}), (flag, value)
for value in (False, None):
assert not refused(**{flag: value}), (flag, value)

def test_pre_2_12_unresolved_row_needs_a_missing_reference_on_its_line(self) -> None:
row = _reference_report("2.11.2")["analysis_completeness"]["ledger_exceptions"][0]
missing = {"source_path": "SKILL.md", "line": 10, "status": "missing"}
Expand Down Expand Up @@ -10992,6 +11141,7 @@ def notes(rows: list[dict]) -> list[str] | None:
completeness["scope_exclusions"],
payload["components"],
skill,
completeness=completeness,
references=completeness["references"],
skillspector_version=(2, 13, 4),
reference_root=skill,
Expand Down
Loading