Skip to content

🔒 fix(netguard): deny IPv6 cloud-metadata (fd00:ec2::254) even under allow-private-sinks (SEC-IMDS6) - #168

Merged
konih merged 2 commits into
mainfrom
fix/sec-imds6-ipv6-metadata
Aug 2, 2026
Merged

konih merged 2 commits into
mainfrom
fix/sec-imds6-ipv6-metadata

Conversation

@konih

@konih konih commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

SEC-IMDS6 (P2/P3) — IPv6 cloud-metadata SSRF gap under --allow-private-sinks

Surfaced by the 2026-08-02 /project-audit (security lens). The SSRF netguard denied the IPv4 metadata IP (169.254.169.254) unconditionally but NOT the AWS IPv6 IMDS endpoint fd00:ec2::254 — which is IPv6-ULA (IsPrivate()==true) and thus ALLOWED once --allow-private-sinks is on, despite the control's own comment promising metadata is always denied.

Fix

Deny fd00:ec2::254 (single /128) unconditionally at BOTH layers — admission (endpoint_guard.go) and dial-time (netguard/dialer.go) — regardless of the opt-in. Narrow carve-out: legitimate ULA sinks (e.g. fd00::1) stay allowed. Zone normalization (WithZone("")) applied before the check so a zoned form fd00:ec2::254%eth0 can't bypass it (Prefix.Contains/equality are zone-sensitive).

Review

Independent review caught a P1 on the first pass — the zoned form fd00:ec2::254%eth0 bypassed the deny; fixed and fresh-re-reviewed → APPROVE. The re-review verified the P1 is closed at both layers and no other representation (uppercase/expanded/IPv4-mapped) bypasses it (all canonicalize via netip.ParseAddr). Regression cases (unzoned + zoned, opt-in on → denied) added to both test matrices; ULA-allowed cases still green. Gates green.

Copilot AI review requested due to automatic review settings August 2, 2026 11:08
@konih
konih merged commit 7374c97 into main Aug 2, 2026
27 checks passed
@konih
konih deleted the fix/sec-imds6-ipv6-metadata branch August 2, 2026 11:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Closes an SSRF netguard gap where enabling --allow-private-sinks unintentionally allowed the AWS IPv6 IMDS endpoint (fd00:ec2::254) because it is IPv6 ULA (IsPrivate()==true). The fix enforces an unconditional deny for that single /128 at both admission-time validation and dial-time enforcement, including a bypass fix for zoned literals (e.g. %eth0).

Changes:

  • Add an unconditional deny-list entry for fd00:ec2::254/128 in admission (internal/validation/endpoint_guard.go) and normalize away IPv6 zones before prefix matching.
  • Add an unconditional dial-time rejection for fd00:ec2::254 in netguard (internal/sink/netguard/dialer.go) using zone-stripped equality.
  • Add regression tests covering unzoned and zoned IPv6 IMDS literals under --allow-private-sinks, while keeping generic ULA allow-cases green.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/validation/endpoint_guard.go Denies fd00:ec2::254/128 unconditionally and strips zones before deny-prefix matching to prevent zoned-literal bypass.
internal/validation/allow_private_sinks_test.go Extends admission test matrix to assert IPv6 IMDS (zoned + unzoned) remains denied even when private sinks are allowed.
internal/sink/netguard/dialer.go Adds dial-time hard deny for fd00:ec2::254, comparing after zone normalization, ensuring enforcement even under opt-in.
internal/sink/netguard/allow_private_sinks_test.go Extends dial-time test matrix to cover IPv6 IMDS (zoned + unzoned) under the opt-in.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants