fix(validation): prevent mixed IPv4/IPv6 allowlist crashes#645
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens safe-mode target validation when allowed_networks contains mixed IPv4/IPv6 CIDRs, preventing version-mismatch errors and adding regression coverage.
Changes:
- Skip allowed-network entries whose IP version (v4/v6) doesn’t match the target network during safe-mode checks.
- Add unit tests covering mixed-version
allowed_networksscenarios to ensure validation doesn’t crash.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| testing/backend/unit/test_validation.py | Adds regression tests for mixed IPv4/IPv6 allowed_networks handling. |
| backend/secuscan/validation.py | Prevents cross-version ipaddress operations by skipping mismatched network versions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # pyrefly: ignore [missing-import] | ||
| import pytest | ||
| import socket | ||
| from backend.secuscan.config import settings |
| def test_validate_target_ipv6_with_ipv4_allowed_network_does_not_crash(monkeypatch): | ||
| monkeypatch.setattr(settings, "allowed_networks", ["127.0.0.0/8"]) | ||
| ok, msg = validate_target("::1", safe_mode=True) | ||
|
|
||
| assert ok is False | ||
| assert msg in { | ||
| "Public IPs/networks not allowed in safe mode (SecuScan Guardrail)", | ||
| "Target not within allowed networks in safe mode (SecuScan Guardrail)", | ||
| } |
| allowed_net = ipaddress.ip_network(pattern, strict=False) | ||
| if net.version != allowed_net.version: | ||
| continue | ||
| if net.subnet_of(allowed_net) or net.overlaps(allowed_net): | ||
| return True |
|
I rebased this branch on the latest upstream/main and pushed the refreshed branch. The remaining CI failures appear unrelated to this PR scope. This PR only modifies:
The failing checks are currently coming from backend/secuscan/workflows.py and frontend unit tests, which are outside this PR’s changes. Local targeted validation tests are passing: py -3.11 -m pytest testing/backend/unit/test_validation.py -q Result: 43 passed. |
utksh1
left a comment
There was a problem hiding this comment.
The IPv4/IPv6 allowlist fix itself is small and in the right area, but this head is not merge-ready because required checks are red: backend-lint and frontend-checks fail, and backend-tests/benchmark are skipped. Please rebase on the current CI baseline and get the full check set green, then request review again.
d496a3a to
e1fff40
Compare
|
Hi @utksh1, I rebased the branch on the latest upstream/main and force-pushed the refreshed head. All required CI checks are now passing successfully, including backend-lint, backend-tests, frontend-checks, and benchmark. Local targeted validation tests are also passing: py -3.11 -m pytest testing/backend/unit/test_validation.py -q Result: 43 passed. Requesting re-review when convenient. Thank you. |
utksh1
left a comment
There was a problem hiding this comment.
Re-reviewed the latest update. The mixed IPv4/IPv6 allowlist crash fix is focused, has symmetric regression coverage, and visible checks are green. Approving.
utksh1
left a comment
There was a problem hiding this comment.
Fresh rebase checks are green. The IPv4/IPv6 allowlist crash fix is focused and covered. Approving.
|
Approved with fresh green checks after branch update. Manual merge is still blocked by repository branch policy, and auto-merge is disabled for this repository, so I am leaving this approved instead of using admin bypass. |
Description
This PR fixes a safe-mode validation bug where mixed IPv4 and IPv6 entries in
allowed_networkscould raise an uncaughtTypeErrorduring target validation.Changes included:
subnet_of()andoverlaps()in_net_within_allowed_networks()Related Issues
Fixes #607
Type of Change
How Has This Been Tested?
Executed:
Result:
42 passed
Verified that:
TypeErrorChecklist