Repository navigation
test(security): add direct tests for SSRF-guarded connection classes - #5336
debojyoti10CC wants to merge 1 commit into
Conversation
Covers _resolve_and_validate, guarded HTTP/HTTPS connections (pinned IP, SNI preserved), metadata/link-local blocks and redirect re-validation. Refs Graphify-Labs#5220 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
|
Thanks for the pull request, @debojyoti10CC. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify code review 
Review completed · 934f805ab468
Tip
Merge confidence: 5/5 · Looks safe to merge · 🟠 High impact
No issues reported
The change adds direct tests for URL validation, DNS resolution, pinned HTTP(S) connections, and redirect handling.
Full summary
The change adds direct tests for URL validation, DNS resolution, pinned HTTP(S) connections, and redirect handling. One test documents that a guarded connection uses the first DNS answer it can validate.
Code graph and static checks · 91 functions depend on this change
Impact & health
Impact — 91 functions depend on the 91 functions this change touches.
Health — grade A; no new coupling hotspots.
Formal checks — 91 functions this change can affect weren't formally checked in this review. Formal checks are informational only.
Gate & verification
✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 91 function(s) in the blast radius were not formally verified this run
Test selection
1 of 593 test file(s) selected (0%) via static blast radius.
tests/test_security.py— impact, changed-test
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
|
Bumping this in case it got buried. It is still ready for review, and I am happy to make any changes you would like. Thanks! |
What does this PR do?
Fixes #5220 (point 1: test coverage). The SSRF-guarded connection classes in
graphify/security.pywere only ever exercised through mocked_build_opener, so I added direct tests. They patchsocket.getaddrinfo/socket.create_connection, so there is no real network and no flakiness.Covered:
_resolve_and_validateblocking loopback, RFC1918, link-local metadata, CGN and IPv6 ULA/loopback; the guarded HTTP and HTTPS connections connecting only to the validated IP and refusing blocked ones without opening a socket; the HTTPS connection keepingserver_hostnameas the original host (SNI/cert validation); metadata hostname blocks; and the redirect handler rejecting loopback, metadata andfile://targets while allowing a public one.For point 2 of the issue I did not change behavior. One test pins the current mixed-answer behavior:
_resolve_and_validateis decided by the first record (blocked first raises, clean first is used), whilevalidate_urlrejects if any record is blocked. Whether to align them is a maintainer call, so I left it out of this PR.Type of change
Verification & Invariants
Invariant: a connection never reaches a private/reserved address, and TLS still validates against the original hostname even though we connect to a pinned IP. The new tests assert both directly. Sanity check: changing
server_hostname=self.hostto the IP in the HTTPS connection makestest_https_connection_keeps_sni_hostname_and_pins_ipfail. No production code, generated skill files or persisted state changed.How was this tested?
-p no:hypothesispytestwas needed only because a Windows policy blocks hypothesis's native DLL on my machine. A wider-k "security or fetch or ingest"run hit 2 collection errors from that same environment, so I did not run the full suite.Graphify-specific checklist