SkillSpector icon indicating copy to clipboard operation
SkillSpector copied to clipboard

feat(analyzer): detect SSRF (cloud metadata / internal-network / dynamic-host requests)

Open CharmingGroot opened this issue 5 months ago • 1 comments

Fixes #62.

What this adds

A skill that performs SSRF — fetching the cloud metadata endpoint (169.254.169.254) to steal IAM credentials, or making requests to internal hosts — was not flagged by any analyzer. Adds a static_patterns_ssrf analyzer under a new "Server-Side Request Forgery" category:

  • SSRF1 — cloud metadata endpoints (AWS/GCP/Azure 169.254.169.254, metadata.google.internal, Alibaba 100.100.100.200, IPv6 IMDS) — HIGH
  • SSRF2 — requests to loopback / link-local / private-range hosts (localhost, 127.0.0.1, 10., 192.168., 172.16–31., ::1) — MEDIUM
  • SSRF3 — request URL whose host is built from a dynamic/untrusted value (requests.get(f"http://{host}/...")) — MEDIUM

The reproduction from the issue (a metadata credential-theft script) went from LOW (score 13) to CRITICAL (score 84).

Scope / non-overlap

Verified the reproduction triggers none of E1–E4, taint tracking, or behavioral_ast — this is a distinct sink (inbound-to-internal request) from E1 (outbound exfil). The metadata IP is reported by SSRF1 only (no same-line duplicate with SSRF2). First-pass coverage anchors on Python/JS request functions and can be extended.

Testing

  • ruff check src/ tests/ and ruff format --check src/ tests/ pass.
  • pytest -m 'not integration' passes (606 passed, 11 skipped).
  • static_patterns_ssrf at 100% coverage. Tests cover: metadata / internal-host / dynamic-host detection, metadata-IP de-duplication, a false-positive guard (normal public HTTPS request is not flagged), and the node entrypoint.

CharmingGroot avatar Jun 15 '26 02:06 CharmingGroot

Rebased onto current main — conflict in tests/nodes/analyzers/test_static_patterns.py resolved by preserving both the upstream TestRunStaticPatternsAgentSnooping tests and this PR's TestRunStaticPatternsSSRF tests. Each class keeps its own test_node_runs_over_state. uv.lock regenerated. All 28 tests pass. Ready to merge.

CharmingGroot avatar Jun 24 '26 01:06 CharmingGroot

I do see conflicts due to other PRs getting merged. Sorry, can you resolve these ?

rng1995 avatar Jun 24 '26 06:06 rng1995

Resolved merge conflicts with upstream/main (as of the anti-refusal analyzer merge, #65).

Three files had conflicts — in each case both sides added new entries to the same list/dict, so the resolution was to keep both:

  • src/skillspector/nodes/analyzers/__init__.py: kept static_patterns_ssrf (this branch) and static_patterns_anti_refusal (upstream) in both ANALYZER_NODE_IDS and ANALYZER_NODES.

  • src/skillspector/nodes/analyzers/pattern_defaults.py: kept SSRF entries (SSRF1–SSRF3) alongside the new AR entries (AR1–AR3) in RULE_ID_TO_CATEGORY, PATTERN_NAMES, DEFAULT_EXPLANATIONS, and DEFAULT_REMEDIATIONS.

  • tests/nodes/analyzers/test_registry.py: kept both "static_patterns_ssrf" and "static_patterns_anti_refusal" in EXPECTED_ANALYZER_NODE_IDS.

No logic changes — purely additive resolution. Full unit test suite: 937 passed, 2 pre-existing failures in test_meta_analyzer.py that exist on upstream/main itself (unrelated to this branch).

CharmingGroot avatar Jun 24 '26 07:06 CharmingGroot