Skip to content

fix(network-policy): respect SECUSCAN_ALLOW_LOOPBACK_SCANS for loopback targets#2053

Open
i-OmSharma wants to merge 2 commits into
utksh1:mainfrom
i-OmSharma:fix/network-policy-loopback-scans
Open

fix(network-policy): respect SECUSCAN_ALLOW_LOOPBACK_SCANS for loopback targets#2053
i-OmSharma wants to merge 2 commits into
utksh1:mainfrom
i-OmSharma:fix/network-policy-loopback-scans

Conversation

@i-OmSharma

Copy link
Copy Markdown
Contributor

Description

Resolves #2047.

SECUSCAN_ALLOW_LOOPBACK_SCANS (default True) was previously honored by Safe Mode (validation.py) but ignored by Network Policy (network_policy.py), which unconditionally blocked 127.0.0.0/8 via its default denylist. This caused default Quick Start installations to fail out-of-the-box when running local scans (e.g., 127.0.0.1).

Changes Included

  • Network Policy Exemption (backend/secuscan/network_policy.py): Updated denylist evaluation to skip denylist matching for loopback targets (ip.is_loopback) when settings.allow_loopback_scans is enabled.
  • Targeted Security Scope: Preserved strict egress validation for webhooks in validate_egress_target() to avoid SSRF vectors.
  • Unit Testing (testing/backend/unit/test_network_policy.py): Added TestLoopbackExemption test class covering:
    • 127.0.0.1 IPv4 target allowed when allow_loopback_scans=True.
    • ::1 IPv6 loopback target allowed when allow_loopback_scans=True.
    • 127.0.0.1 blocked when allow_loopback_scans=False.
    • RFC1918 / Private IP ranges (e.g., 10.0.0.1, 169.254.169.254) remain strictly blocked regardless of flag setting.
    • Updated legacy test assertions that asserted unconditional loopback blocks.
  • Documentation (.env.example): Added inline commentary clarifying that SECUSCAN_ALLOW_LOOPBACK_SCANS governs both Safe Mode and Network Policy gates.

Verification

  • Ran full unit test suite: 32/32 passed in test_network_policy.py.
  • Ran ruff lint checks: all clean.

Fixes #2047

…ck targets

Fixes utksh1#2047 by skipping denylist match for loopback IP addresses (127.0.0.1 and ::1) when settings.allow_loopback_scans is enabled in Network Policy.

This brings network_policy.py in alignment with validation.py and fixes the default Quick Start experience for fresh installs.

- Added TestLoopbackExemption test suite in testing/backend/unit/test_network_policy.py.
- Preserved strict validation for webhook egress targets to prevent SSRF vulnerabilities.

Signed-off-by: i-OmSharma <sharmaom1201@gmail.com>
Copilot AI review requested due to automatic review settings July 21, 2026 07:11

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

This PR fixes an inconsistency where SECUSCAN_ALLOW_LOOPBACK_SCANS was honored by Safe Mode but ignored by the Network Policy engine, causing default installs to block loopback targets like 127.0.0.1 and breaking the Quick Start workflow.

Changes:

  • Updated NetworkPolicyEngine.check_access() to exempt loopback targets from denylist evaluation when settings.allow_loopback_scans is enabled.
  • Added unit tests covering IPv4/IPv6 loopback allow/deny behavior under the flag, while ensuring non-loopback denylist rules remain enforced.
  • Updated .env.example commentary to document the setting’s intent.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
backend/secuscan/network_policy.py Adds a loopback exemption in denylist evaluation when allow_loopback_scans is enabled.
testing/backend/unit/test_network_policy.py Adds loopback exemption test coverage and updates legacy assumptions about unconditional loopback blocking.
.env.example Documents the loopback setting’s relationship to Safe Mode and Network Policy.

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

Comment thread .env.example Outdated
Comment on lines +31 to +32
# Applies to both Safe Mode (validation.py) and Network Policy (network_policy.py) —
# both gates must independently permit loopback, and both key off this one setting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the documentation in .env.example and tightened the inline commentary in network_policy.py to explicitly clarify that SECUSCAN_ALLOW_LOOPBACK_SCANS governs scan-target validation (check_access()) only, and does not alter validate_egress_target(), which continues to block loopback targets unconditionally for webhook egress.

Pushed in the latest commit!

Clarified in .env.example and network_policy.py that SECUSCAN_ALLOW_LOOPBACK_SCANS applies strictly to scan-target validation (check_access) and does not relax webhook egress validation (validate_egress_target).
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.

[BUG] SECUSCAN_ALLOW_LOOPBACK_SCANS is ignored by Network Policy - README quick-start example fails on a fresh install

2 participants