Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,29 @@ SC4 uses the [OSV.dev](https://osv.dev) API to check dependencies against the fu

The tool requires outbound HTTPS access to `api.osv.dev` for live vulnerability data. When that is not available, findings are limited to the static fallback list.

## Locked npm dependency contents (opt-in)

Use `--inspect-dependencies` to statically inspect exact public npm tarballs from
`package-lock.json` or `npm-shrinkwrap.json` v2/v3, including recorded transitive,
development, and optional dependencies:

```bash
skillspector scan ./my-skill --inspect-dependencies --no-llm --fail-on-incomplete
```

Artifacts must match their locked SHA-512 integrity hashes. A disposable Linux
worker inspects supported source files and decoded npm scripts without installing
packages or executing their code. Dependency findings include package coordinates,
an artifact digest, and source locations. Missing artifacts, unsupported sources
or formats, unavailable isolation, and exhausted budgets remain incomplete;
`--fail-on-incomplete` prevents them from passing the scan. Reports also show when
inspection was not requested.

This first version supports the public npm registry and Linux x86-64/AArch64
seccomp isolation. Dependency analysis stays local and uses existing static
data-exfiltration, privilege-escalation, and supply-chain patterns. See
[supported content, resource limits, and coverage boundaries](docs/DEPENDENCY_CONTENT_INSPECTION.md).

## Trust model and data egress

SkillSpector is defense-in-depth, not a sandbox. Know what it does and does not do before relying on it:
Expand Down
9 changes: 9 additions & 0 deletions docs/ANALYSIS_RESOURCE_BOUNDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ relevant ceiling is reached, the scanner records the limitation and reports part

Values below are implementation defaults. MiB means 1,048,576 bytes.

## Locked npm dependency inspection

`--inspect-dependencies` adds bounded acquisition and a separate static worker for
each supported, integrity-verified locked artifact. Downloads and decompressed
tar bytes both consume the remaining shared workflow byte budget. Worker runtime,
memory, output, member counts, expansion, and source sizes have independent caps.
Failures and unsupported content remain in the completeness ledger. See
[dependency inspection limits and supported platforms](DEPENDENCY_CONTENT_INSPECTION.md).

## Bundle discovery and materialization

| Resource | Ceiling | Scope |
Expand Down
147 changes: 147 additions & 0 deletions docs/DEPENDENCY_CONTENT_INSPECTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Locked npm dependency content inspection

Advisory checks identify known vulnerable releases. They do not automatically
inspect the source shipped in an external package. Opt in to content inspection:

```bash
skillspector scan ./my-skill --inspect-dependencies --no-llm \
--fail-on-incomplete --format json
```

The flag also applies to each child of a recursive scan and to external sources
followed by `--transitive`. The npm dependency graph comes from the selected
lockfiles; `--transitive` is not required to inspect their recorded transitive
packages. MCP Registry mode rejects the flag. Direct graph callers can set
`inspect_dependencies: True`; the MCP tool does not expose a new argument.

## Supported artifacts

- `package-lock.json` and `npm-shrinkwrap.json`, lockfile versions 2 and 3.
A sibling shrinkwrap takes precedence over a package lock.
- Exact HTTPS `.tgz` URLs on `registry.npmjs.org`, with valid SHA-512 SRI.
Registry redirects, credentials, query strings, alternate hosts, HTTP, local
paths, Git dependencies, workspace links, and bundled lock entries are
unsupported and produce incomplete inspection.
- Every recorded package entry, including development and optional packages and
nested transitive installations. Aliases retain the artifact's actual package
name and all lockfile installation locations. Identical locked artifacts are
inspected once within an invocation.

The scanner uses cached lockfile bytes from bundle discovery. It rejects malformed
or duplicate-key JSON, unsupported lockfile versions, and disagreement between a
sibling package manifest's dependency declarations and the lockfile root. A
manifest in another directory cannot borrow a project's lockfile. Requesting
inspection without an available lockfile records incomplete coverage.

The downloader does not invoke npm, resolve versions, read `.npmrc`, use a
package-manager cache, or inherit proxy and credential configuration. DNS lookup
has its own process timeout; acquisition pins a validated public address while
retaining registry TLS certificate verification and SNI. Redirects and HTTP
content encodings are rejected. Downloaded bytes must match a recorded SHA-512
digest before the artifact reaches the inspection worker. The package's own
`package.json` name and version must also match its locked identity.

HTTP acquisition runs in a disposable downloader process. The parent enforces
the remaining absolute dependency/workflow deadline across process startup,
connection, TLS, response headers, body streaming, and client cleanup, killing
and reaping the downloader on timeout. Slow streams cannot extend the deadline
by sending bytes within each read timeout. Failed acquisition conservatively
charges its granted download-byte allowance when exact consumption is unavailable.

## Static analysis and isolation

Package code is never installed or executed. Each verified tarball is passed to
a fresh isolated Python process with a minimal environment. After trusted scanner
imports, the worker closes additional file descriptors and installs a Linux
seccomp syscall allowlist synchronized across its threads. The allowlist denies
filesystem access, networking, new processes, and execution. No archive member is
written to disk. If this isolation cannot be established, inspection fails closed
with `dependency_sandbox_unavailable`.

This worker currently requires Linux on x86-64 or AArch64 and a kernel that permits
seccomp filter synchronization. Other platforms retain ordinary SkillSpector
scanning; requested dependency inspection remains incomplete.

Supported UTF-8 text extensions are `.js`, `.mjs`, `.cjs`, `.ts`, `.json`, `.py`,
`.sh`, `.bash`, `.zsh`, `.ps1`, `.md`, `.markdown`, `.txt`, `.yaml`, `.yml`, and
`.toml`; conventional license and notice files are also inspected. The worker
uses the existing data-exfiltration, privilege-escalation, and supply-chain
pattern analyzers. It decodes every npm script command, including installation
hooks and commands reached through `npm run`, while retaining the script name
and original `package.json` property location in findings.

Dependency contents receive local static analysis only. This pass does not send
them to an LLM provider, perform additional advisory requests, or run YARA.
Ordinary analysis of the skill still follows its existing LLM, YARA, and OSV
settings. Use `--no-llm` to keep ordinary source analysis local as well.

Unsafe paths, duplicate members, links, special files, malformed archives,
unexamined trailing payloads, unsupported encodings, native modules, binaries,
and other unsupported formats remain visible as inspection gaps. The scanner does
not fetch additional payloads named in installation scripts or generated at runtime.

## Limits

| Resource | Default ceiling |
|---|---:|
| Locked entries considered | 128 per invocation |
| Lockfiles considered | 128 per invocation |
| Lockfile or sibling manifest bytes | 1 MiB each |
| Downloaded bytes | 32 MiB total; 8 MiB per artifact |
| Decompressed tar bytes | 64 MiB total; 16 MiB per artifact |
| Archive headers considered | 4,096 total; 1,024 per artifact |
| Source bytes per member | 1 MiB |
| Compression ratio | 200:1 |
| Decoded package scripts | 128 per package |
| Findings | 1,000 per invocation |
| Dependency pass wall time | 120 seconds |
| Worker wall time | 30 seconds, including startup |
| Worker CPU time | 30 seconds |
| Worker address space | 1 GiB |
| Worker output | 4 MiB |

The remaining shared workflow time, byte, and artifact budgets can reduce these
allowances. Downloads and decompressed tar bytes both consume shared workflow
bytes. A failed worker conservatively consumes its granted expansion allowance;
it cannot obtain a fresh budget through repeated failures. Byte accounting bounds
input work rather than all Python object overhead.

Four environment settings adjust aggregate dependency limits. Each is read at scan
time; invalid, non-positive, and non-finite values retain the default:

| Setting | Default |
|---|---:|
| `SKILLSPECTOR_MAX_DEPENDENCY_INSPECTION_PACKAGES` | `128` |
| `SKILLSPECTOR_MAX_DEPENDENCY_INSPECTION_SECONDS` | `120` |
| `SKILLSPECTOR_MAX_DEPENDENCY_INSPECTION_DOWNLOAD_BYTES` | `33554432` |
| `SKILLSPECTOR_MAX_DEPENDENCY_INSPECTION_EXPANDED_BYTES` | `67108864` |

The lockfile count follows the package-entry limit. Raising aggregate limits does
not raise per-artifact, worker, report, or shared workflow ceilings. Python callers
of `inspect_dependencies` may supply a `DependencyInspectionLimits` instance for
stricter per-call limits.

## Reports and completeness

Dependency findings appear in terminal, JSON, Markdown, and SARIF reports. Each
carries the package name, version, exact artifact SHA-256 digest, lockfile
references, and source location. Artifact identity also scopes finding
fingerprints. Script projections identify their original package manifest
property and the corresponding line within the decoded command.

`analysis_completeness.dependency_inspection` reports `not_requested`, `completed`,
or `partial`, with counts and bounded artifact records. Failed and unsupported
work also appears in the canonical completeness ledger and coverage inventory.
Uninspected content cannot count as fully inspected. Existing findings survive a
later artifact failure. Diagnostic byte counters ending in `_charged` can include
conservative budget reservations after failures.

Incomplete requested inspection prevents a `SAFE` recommendation and keeps
`safe_to_install` false where that verdict is exposed. `--fail-on-incomplete`
additionally causes a failing CLI exit status. With the flag disabled, reports
explicitly show that dependency content inspection was not requested.

Integrity verification establishes correspondence with the lockfile, not publisher
trust or package safety. Coverage is limited to recorded lock entries and the
supported static analysis described here. It does not certify lockfile graph
completeness or that a future installation will use only the inspected artifacts.
53 changes: 47 additions & 6 deletions src/skillspector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ def scan(
"sub-skill separately.",
),
] = False,
inspect_dependencies: Annotated[
bool,
typer.Option(
"--inspect-dependencies",
help="Statically inspect SHA-512-verified public npm artifacts from v2/v3 lockfiles. Never installs packages or executes package code.",
),
] = False,
transitive_enabled: Annotated[
bool,
typer.Option(
Expand Down Expand Up @@ -712,6 +719,7 @@ def scan(
or yara_rules_dir is not None
or min_coverage is not None
or use_shipped_baseline
or inspect_dependencies
or transitive_enabled
or transitive_allow_prefix
or transitive_deny_prefix
Expand All @@ -721,7 +729,7 @@ def scan(
err_console.print(
"[red]Error:[/red] --mcp-registry cannot be combined with "
"--recursive, --baseline, --show-suppressed, --yara-rules-dir, "
"--min-coverage, --use-shipped-baseline, --transitive, "
"--min-coverage, --use-shipped-baseline, --inspect-dependencies, --transitive, "
"--transitive-depth, --transitive-allow-prefix, or --transitive-deny-prefix"
)
raise typer.Exit(code=2)
Expand Down Expand Up @@ -807,7 +815,12 @@ def scan(
# escapes the combined report (e.g. an unwritable --output) exits 2,
# not with a traceback and exit 1, which means "risk found".
try:
_scan_multi_skill(
scan_multi_skill = (
partial(_scan_multi_skill, inspect_dependencies=True)
if inspect_dependencies
else _scan_multi_skill
)
scan_multi_skill(
detection,
format=format,
output=output,
Expand Down Expand Up @@ -897,6 +910,8 @@ def scan(
result = None
try:
scan_skill = partial(_scan_skill, exclude_patterns=exclude) if exclude else _scan_skill
if inspect_dependencies:
scan_skill = partial(scan_skill, inspect_dependencies=True)
result = scan_skill(
input_path=input_path,
format=format,
Expand Down Expand Up @@ -1590,6 +1605,7 @@ def _run_graph_scan(
source_local_only: bool = False,
stream_progress: bool = False,
exclude_patterns: list[str] | None = None,
inspect_dependencies: bool = False,
) -> dict[str, object]:
state = _scan_state(
input_path=input_path,
Expand All @@ -1601,6 +1617,8 @@ def _run_graph_scan(
source_local_only=source_local_only,
exclude_patterns=exclude_patterns,
)
if inspect_dependencies:
state["inspect_dependencies"] = True
if transitive_traversal is not None:
state["transitive_traversal_state"] = transitive_traversal
if initial_inspection_ledger:
Expand All @@ -1616,7 +1634,7 @@ def _run_graph_scan(

analyzer_node_ids = _wired_analyzer_node_ids()
total_analyzers = len(analyzer_node_ids)
total_steps = 5 + total_analyzers
total_steps = 6 + total_analyzers
result = dict(state)

with (
Expand Down Expand Up @@ -1702,13 +1720,16 @@ def _run_graph_scan_for_source(
source_local_only: bool = False,
stream_progress: bool = False,
exclude_patterns: list[str] | None = None,
inspect_dependencies: bool = False,
) -> dict[str, object]:
"""Invoke a scan without widening the legacy call contract for public sources."""
run_graph_scan = (
partial(_run_graph_scan, stream_progress=True) if stream_progress else _run_graph_scan
)
if exclude_patterns:
run_graph_scan = partial(run_graph_scan, exclude_patterns=exclude_patterns)
if inspect_dependencies:
run_graph_scan = partial(run_graph_scan, inspect_dependencies=True)
if initial_inspection_ledger is not None:
if source_local_only:
return run_graph_scan(
Expand Down Expand Up @@ -2050,7 +2071,13 @@ def _scan_transitive(
yara_dir: str | None = None,
traversal: _TransitiveTraversalState | None = None,
source_local_only: bool = False,
inspect_dependencies: bool = False,
) -> dict[str, object]:
scan_child = (
partial(_run_graph_scan_for_source, inspect_dependencies=True)
if inspect_dependencies
else _run_graph_scan_for_source
)
if max_depth <= 0:
report_result = cast(dict[str, object], report(initial_result))
report_result["temp_dir_for_cleanup"] = initial_result.get("temp_dir_for_cleanup")
Expand Down Expand Up @@ -2207,7 +2234,7 @@ def _scan_transitive(
cached = traversal.cache.get(cache_key)
if cached is None:
traversal.record_scan()
child_result = _run_graph_scan_for_source(
child_result = scan_child(
input_path=target,
format=format,
no_llm=no_llm,
Expand Down Expand Up @@ -2573,6 +2600,7 @@ def _scan_skill(
pre_scan_ledger_events: list[dict[str, object]] | None = None,
source_local_only: bool = False,
exclude_patterns: list[str] | None = None,
inspect_dependencies: bool = False,
) -> dict[str, object]:
yara_dir = str(yara_rules_dir.resolve()) if yara_rules_dir else None
active_visited: set[str] = set()
Expand All @@ -2590,6 +2618,8 @@ def _scan_skill(
transitive_traversal = _TransitiveTraversalState(cache=transitive_cache or {})
stream_progress = not verbose and err_console.is_terminal
run_for_source = _run_graph_scan_for_source
if inspect_dependencies:
run_for_source = partial(run_for_source, inspect_dependencies=True)
if exclude_patterns:
run_for_source = partial(run_for_source, exclude_patterns=exclude_patterns)
if pre_scan_ledger_events:
Expand Down Expand Up @@ -2633,7 +2663,12 @@ def _scan_skill(
# returned for the caller's cleanup_result, so remove it here. On success
# the merged result carries the same temp_dir_for_cleanup for the caller.
try:
return _scan_transitive(
scan_transitive = (
partial(_scan_transitive, inspect_dependencies=True)
if inspect_dependencies
else _scan_transitive
)
return scan_transitive(
initial_result=result,
format=format,
no_llm=no_llm,
Expand Down Expand Up @@ -2949,6 +2984,7 @@ def _scan_multi_skill(
min_coverage: float | None = None,
fail_on_findings: bool = False,
max_skills: int | None = None,
inspect_dependencies: bool = False,
**legacy_kwargs: object,
) -> None:
"""Scan each detected sub-skill independently and produce a combined report."""
Expand Down Expand Up @@ -3030,7 +3066,12 @@ def _scan_multi_skill(
)
result: dict[str, object] | None = None
try:
result = _scan_skill(
scan_skill = (
partial(_scan_skill, inspect_dependencies=True)
if inspect_dependencies
else _scan_skill
)
result = scan_skill(
input_path=str(skill.path),
format=format,
no_llm=no_llm,
Expand Down
Loading
Loading