Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,17 @@ Base URL env vars are not needed for live provider tests; the tests intentionall
| **Add analyzer** | Implement node returning `{"findings": list[Finding]}`, register in `nodes/analyzers/__init__.py` |
| **Initial checks** | `make test-unit`, `make lint`, `make format-check`; see [Testing](#7-testing) for scope |
| **Full contributor tests** | `make test` includes integration tests that may call a configured LLM provider; review [Testing](#7-testing) and provider prerequisites first |


### Report input origin

The resolver stores sanitized `input_origin` metadata separately from `skill_path`
(the local scan root). JSON exposes it as `skill.origin`; SARIF exposes it as
`runs[].properties.inputOrigin`. Both contain `source` and `type` (`directory`,
`file`, `zip`, `url`, or `git`). Terminal and Markdown display the same metadata.
The MCP rendered report includes it; compact MCP responses omit that report as usual.
Local input spelling, including relative paths and whitespace, is retained. URL
userinfo, the entire query and fragments are omitted. Git scp-style inputs are
rendered as credential-free SSH URLs. This records acquisition origin, not a
content digest or a resolved revision. Existing working-directory sources,
finding locations, nested provenance and cleanup retain their semantics.
46 changes: 46 additions & 0 deletions src/skillspector/input_origin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Report-only acquisition metadata, independent of the materialized scan root."""

from urllib.parse import urlsplit, urlunsplit


def input_origin(source: str, source_type: str) -> dict[str, str]:
"""Preserve local names; omit credentials, queries and fragments from URLs.

The origin describes the requested input, not a content digest or resolved
Git revision. Keep it separate from analyzer identities and finding paths.
"""
if source_type in {"git", "url"}:
source = source.strip()
if source_type == "git" and source.startswith("git@"):
# Git's scp-style spelling is not parsed as an ordinary URL.
source = "ssh://" + source.split("@", 1)[1].replace(":", "/", 1)
return input_origin(source, source_type)
else:
try:
parsed = urlsplit(source)
if not parsed.hostname or parsed.scheme not in {"https", "http", "ssh", "git"}:
raise ValueError("unsupported origin URL")
host = parsed.hostname
if ":" in host:
host = f"[{host}]"
if parsed.port is not None:
host += f":{parsed.port}"
source = urlunsplit((parsed.scheme, host, parsed.path, "", ""))
except ValueError:
source = "<redacted-url>"
return {"type": source_type, "source": source}
26 changes: 26 additions & 0 deletions src/skillspector/nodes/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from skillspector import __version__ as skillspector_version
from skillspector.dependency_sources import redact_text
from skillspector.inference_usage import looks_like_credential, sanitize_inference_usage
from skillspector.input_origin import input_origin
from skillspector.inspection_ledger import (
MAX_FINDING_OUTPUT_RECORDS,
RESOURCE_MEASUREMENT_UNITS,
Expand Down Expand Up @@ -791,6 +792,7 @@ def _build_sarif(
analysis_completeness: Mapping[str, object] | None = None,
execution_successful: bool = True,
structured_summaries: list[dict[str, object]] | None = None,
origin: dict[str, str] | None = None,
) -> dict[str, object]:
"""Build one SARIF invocation with canonical inspection notifications."""
results: list[SarifResult] = []
Expand Down Expand Up @@ -1144,6 +1146,7 @@ def notification_from_exception(
results=results,
columnKind="unicodeCodePoints",
invocations=invocations,
properties={"inputOrigin": origin} if origin is not None else None,
)
],
}
Expand Down Expand Up @@ -1246,6 +1249,7 @@ def _format_terminal(
show_suppressed: bool = False,
analysis_completeness: Mapping[str, object] | None = None,
execution_successful: bool = True,
origin: dict[str, str] | None = None,
) -> str:
"""Generate styled Rich output with literal, control-safe dynamic text."""
suppressed = suppressed or []
Expand All @@ -1262,6 +1266,9 @@ def _format_terminal(
)
console.print(Text.assemble("\n", ("Skill: ", "bold"), _terminal_text(skill_name)))
console.print(Text.assemble(("Source: ", "bold"), _terminal_text(source)))
if origin is not None:
console.print(Text.assemble(("Input origin: ", "bold"), _terminal_text(origin["source"])))
console.print(Text.assemble(("Input type: ", "bold"), _terminal_text(origin["type"])))
console.print(f"[bold]Scanned:[/bold] {datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S UTC')}")

severity_colors = {
Expand Down Expand Up @@ -1652,6 +1659,7 @@ def _format_json(
semantic_runtime_incomplete: bool = False,
runtime_available: bool | None = None,
provider_availability: tuple[bool, str | None] | None = None,
origin: dict[str, str] | None = None,
) -> str:
"""Generate JSON report string."""
suppressed = suppressed or []
Expand All @@ -1661,6 +1669,7 @@ def _format_json(
"name": skill_name,
"source": skill_path or "",
"scanned_at": datetime.now(UTC).isoformat(),
**({"origin": origin} if origin is not None else {}),
},
"risk_assessment": {
"score": risk_score,
Expand Down Expand Up @@ -1821,6 +1830,7 @@ def _format_markdown(
show_suppressed: bool = False,
analysis_completeness: Mapping[str, object] | None = None,
execution_successful: bool = True,
origin: dict[str, str] | None = None,
) -> str:
"""Generate Markdown report string."""
suppressed = suppressed or []
Expand All @@ -1831,6 +1841,9 @@ def _format_markdown(
lines.append("# SkillSpector Security Report\n")
lines.append(f"**Skill:** {_markdown_cell(skill_name)} ")
lines.append(f"**Source:** {_markdown_code(source)} ")
if origin is not None:
lines.append(f"**Input origin:** {_markdown_code(origin['source'])} ")
lines.append(f"**Input type:** {_markdown_cell(origin['type'])} ")
lines.append(f"**Scanned:** {datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S UTC')} ")
lines.append("")

Expand Down Expand Up @@ -1994,6 +2007,15 @@ def report(state: SkillspectorState) -> dict[str, object]:
has_executable_scripts = state.get("has_executable_scripts", False)
manifest = state.get("manifest") or {}
skill_path = state.get("skill_path")
raw_origin = state.get("input_origin")
origin = None
if (
isinstance(raw_origin, dict)
and isinstance(raw_origin.get("source"), str)
and isinstance(raw_origin.get("type"), str)
and raw_origin.get("type") in {"directory", "file", "zip", "git", "url"}
):
origin = input_origin(raw_origin["source"], raw_origin["type"])
output_format = state.get("output_format") or "sarif"
llm_requested, use_llm = semantic_runtime_intent(state)
raw_llm_call_log = state.get("llm_call_log")
Expand Down Expand Up @@ -2198,6 +2220,7 @@ def report(state: SkillspectorState) -> dict[str, object]:
analysis_completeness=analysis_completeness,
execution_successful=execution_successful,
structured_summaries=structured_summaries,
origin=origin,
)
if output_format == "terminal":
report_body = _format_terminal(
Expand All @@ -2217,6 +2240,7 @@ def report(state: SkillspectorState) -> dict[str, object]:
show_suppressed=show_suppressed,
analysis_completeness=analysis_completeness,
execution_successful=execution_successful,
origin=origin,
)
elif output_format == "json":
report_body = _format_json(
Expand Down Expand Up @@ -2249,6 +2273,7 @@ def report(state: SkillspectorState) -> dict[str, object]:
semantic_runtime_incomplete=semantic_runtime_incomplete,
runtime_available=runtime_available,
provider_availability=(provider_available, provider_error),
origin=origin,
)
elif output_format == "markdown":
report_body = _format_markdown(
Expand All @@ -2268,6 +2293,7 @@ def report(state: SkillspectorState) -> dict[str, object]:
show_suppressed=show_suppressed,
analysis_completeness=analysis_completeness,
execution_successful=execution_successful,
origin=origin,
)
else:
report_body = json.dumps(sarif_report, indent=2)
Expand Down
5 changes: 5 additions & 0 deletions src/skillspector/nodes/resolve_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
selected_source_identity_for_input,
validate_local_input_path,
)
from skillspector.input_origin import input_origin
from skillspector.logging_config import get_logger
from skillspector.state import (
SkillspectorState,
Expand Down Expand Up @@ -66,6 +67,7 @@ def resolve_input(state: SkillspectorState) -> dict[str, object]:
temp_dir = handler.temp_dir_for_cleanup()
update: dict[str, object] = {
"skill_path": str(resolved),
"input_origin": input_origin(input_path, source_type),
"primary_file_path": handler.primary_file_path,
"primary_file_parent_path": handler.primary_file_parent_path,
"selected_source_identity": selected_source_identity_for_input(
Expand Down Expand Up @@ -115,6 +117,7 @@ def resolve_input(state: SkillspectorState) -> dict[str, object]:
resolved = validate_local_input_path(Path(skill_path))
return {
"skill_path": str(resolved),
"input_origin": input_origin(skill_path, "directory"),
"primary_file_path": None,
"selected_source_identity": resolved.name or None,
"temp_dir_for_cleanup": None,
Expand All @@ -124,6 +127,7 @@ def resolve_input(state: SkillspectorState) -> dict[str, object]:
logger.warning("Could not resolve skill_path: %s", e)
return {
"skill_path": None,
"input_origin": None,
"primary_file_path": None,
"selected_source_identity": None,
"temp_dir_for_cleanup": None,
Expand All @@ -132,6 +136,7 @@ def resolve_input(state: SkillspectorState) -> dict[str, object]:

return {
"skill_path": None,
"input_origin": None,
"primary_file_path": None,
"selected_source_identity": None,
"temp_dir_for_cleanup": None,
Expand Down
1 change: 1 addition & 0 deletions src/skillspector/sarif_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class SarifRun(BaseModel):
column_kind: Literal["utf16CodeUnits", "unicodeCodePoints"] | None = Field(
default=None, alias="columnKind"
)
properties: dict[str, object] | None = None
artifacts: list[SarifArtifact] | None = None
invocations: list[SarifInvocation] | None = None
# SARIF 2.1.0 section 3.14.14: resolves artifactLocation.uriBaseId
Expand Down
2 changes: 2 additions & 0 deletions src/skillspector/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class SkillspectorState(TypedDict, total=False):
input_path: str | None
# Only trusted local transports may use the operator's Git credentials.
allow_git_credentials: bool
# Sanitized report-only acquisition identity; never used to resolve findings.
input_origin: dict[str, str] | None
skill_path: str | None
# Relative identity of a wrapped/downloaded explicit file, distinct from passive assets.
primary_file_path: str | None
Expand Down
98 changes: 98 additions & 0 deletions tests/nodes/test_input_origin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Input identity survives materialization without changing finding coordinates."""

import json
import shutil
import zipfile
from pathlib import Path

import pytest

from skillspector.input_origin import input_origin
from skillspector.nodes.report import report
from skillspector.nodes.resolve_input import resolve_input
from skillspector.sarif_models import validate_sarif_report


@pytest.mark.parametrize(
("raw", "kind", "expected"),
[
(" ./literal name ", "directory", " ./literal name "),
("./literal?token=local#name.md", "file", "./literal?token=local#name.md"),
(
" https://user:secret@example.org:8443/a.md?custom=secret#secret ",
"url",
"https://example.org:8443/a.md",
),
("https://user:secret@[::1]:8443/a.md?secret", "url", "https://[::1]:8443/a.md"),
("https://example.org:bad/a.md?secret", "url", "<redacted-url>"),
("https://[bad/a.md", "url", "<redacted-url>"),
("git@example.org:team/repo.git", "git", "ssh://example.org/team/repo.git"),
(
"https://user:secret@github.com/team/repo/tree/main/sub?secret#secret",
"git",
"https://github.com/team/repo/tree/main/sub",
),
],
)
def test_origin_identity_and_redaction(raw, kind, expected):
origin = input_origin(raw, kind)
assert origin == {"source": expected, "type": kind}
assert input_origin(origin["source"], kind) == origin


@pytest.mark.parametrize("kind", ["directory", "file", "zip"])
def test_real_materialization_retains_origin_and_cleanup(tmp_path, monkeypatch, kind):
monkeypatch.chdir(tmp_path)
skill = Path("skill ")
skill.mkdir()
(skill / "SKILL.md").write_text("# Hello")
target = skill
if kind == "file":
target = skill / "SKILL.md"
if kind == "zip":
target = Path("skill.zip")
with zipfile.ZipFile(target, "w") as z:
z.write(skill / "SKILL.md", "SKILL.md")
update = resolve_input({"input_path": str(target)})
assert update["input_origin"] == {"source": str(target), "type": kind}
assert Path(update["skill_path"]).is_dir()
if update["temp_dir_for_cleanup"]:
shutil.rmtree(update["temp_dir_for_cleanup"])
assert not Path(update["skill_path"]).exists()
assert target.exists()


@pytest.mark.parametrize("fmt", ["json", "sarif", "markdown", "terminal"])
def test_all_renderers_keep_origin_separate_and_redacted(fmt):
state = {
"output_format": fmt,
"use_llm": False,
"skill_path": "/tmp/materialized",
"input_origin": {
"type": "url",
"source": "https://user:secret@example.org/SKILL.md?api_key=secret#secret",
},
}
result = report(state)
body = result["report_body"]
assert "secret" not in body and "user:" not in body
expected = {"type": "url", "source": "https://example.org/SKILL.md"}
if fmt == "json":
assert json.loads(body)["skill"]["origin"] == expected
assert json.loads(body)["skill"]["source"] == "/tmp/materialized"
elif fmt == "sarif":
sarif = json.loads(body)
validate_sarif_report(sarif)
assert sarif["runs"][0]["properties"]["inputOrigin"] == expected
else:
assert "https://example.org/SKILL.md" in body and "/tmp/materialized" in body


@pytest.mark.parametrize(
"raw", [None, {}, {"type": [], "source": "x"}, {"type": "url", "source": None}]
)
def test_legacy_or_invalid_state_omits_origin(raw):
result = report({"output_format": "json", "use_llm": False, "input_origin": raw})
assert "origin" not in json.loads(result["report_body"])["skill"]
Loading