fix(python): resolve and pin webhook endpoints against SSRF #4376
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.59 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #4376"
general
weight: 0.35
prayagupa
Related Issue
Part of #3516. The issue stays open until every language is fixed; this PR covers the two Python packages that send webhooks (agent-mesh and agent-os).
Problem & Solution
Problem: The .NET
WebhookApprover(#3363) already resolves the endpoint host at request time, rejects any record in a blocked range, pins the socket to the validated address throughConnectCallback, and disables proxies. The Python senders did not.HttpAdvisory,VersionedWebhookApprovaland the deprecatedWebhookApprovalin agent-mesh checked the host against three literal strings once, at construction, then handed the URL to the defaulturllibopener, which resolves the name itself, follows redirects and honours proxy variables.WebhookNotifierandWebhookApprovalBackendin agent-os had no URL check at all. On main,_validate_webhook_urlacceptshttp://127.0.0.1/,localhost,127.0.0.1.nip.io,[fd00:ec2::254](the bracketed entry never matches becauseurlparsestrips the brackets),169.254.169.254.(trailing dot) and2130706433(decimal IPv4). A DNS answer that changes between validation and connect also reaches the internal destination.Solution: Add
WebhookEndpointGuardto both packages, mirroring the .NET fix.localhost,metadata.googleand its.internalform, case and trailing-dot normalised), and literal addresses in loopback, private, link-local, shared, multicast, reserved, benchmark and documentation ranges for IPv4 and IPv6. IPv4-mapped and IPv4-compatible forms are unwrapped.inet_atonspellings (decimal, hex, short forms) are parsed withgetaddrinfo(AI_NUMERICHOST), which never touches DNS.endpoint_guard=WebhookEndpointGuard.allowing(["10.0.0.0/8"]). The default allows nothing internal. The resolver is injectable so tests run without network.The guard is wired into
HttpAdvisory,VersionedWebhookApprovalandWebhookApproval(agent-mesh) andWebhookNotifierandWebhookApprovalBackend(agent-os). The module ships in both packages because neither can import the other's development checkout; a test in each keeps the two copies identical.Behaviour change to note: constructing any of these five classes with a loopback or private URL now raises
ValueError. Local-development setups that post to127.0.0.1must passendpoint_guard=WebhookEndpointGuard.allowing([...]). Both package CHANGELOGs record this.Impact on Your Work
Closes the Python half of a cross-SDK SSRF gap. A governance deployment that accepts an approval or advisory webhook URL from configuration could be steered to loopback, RFC1918 or cloud-metadata addresses through a rebinding host name, a redirect, or an unusual address spelling, and the approval flow would then produce an ALLOW from an attacker-reachable receiver. After this change the Python packages hold the same line as .NET.
Timeline
None
Alternatives Considered
urllibconnect. Rejected: the client resolves the name again, so a rebinding name still wins the race. Pinning the validated address is the only way to close it.agent-governance-toolkit-coreand import it from both packages. Rejected for this PR: neither package can import the other's development checkout today, andpip install -e .[dev]on main is unresolvable (agentmesh-platform[dev] pins agentrust-trace<0.6 while core 5.0.0 pins <0.3), so a shared dependency would block the fix. A test in each package asserts the two copies stay byte-identical; moving to a shared module can follow once the dependency pins are untangled.Type of Change
Package(s) Affected
Core & runtime:
Governance & security:
Platform & tooling:
CLI plugins:
Shared / other:
.cspell-repo-terms.txt)Testing
Unit Testing
New files:
agent-governance-python/agent-mesh/tests/test_webhook_guard.py: 110 tests.agent-governance-python/agent-os/tests/test_webhook_guard.py: 53 tests.They cover each attack case with injected DNS answers (loopback, private, link-local, metadata, IPv4-mapped IPv6, decimal and hex IPv4,
localhost, trailing dot, bracketed IPv6, subdomains of blocked names), a loopback server that proves the socket is pinned to the validated address and that a 3xx is refused, a patchedconnectthat records the pinned target for the rebinding case, proxy-variable ignoring, scheme rejection, theallowing([...])escape hatch, and a byte-identity check between the two package copies.Adjusted existing tests: agent-mesh
test_advisory.pyandtest_approval_strict.py(tests that post to127.0.0.1:1now allow-list that address; tests that mockedurllib.request.urlopenmock the guard instead); agent-ostest_webhooks.py(same adjustment).Against main's source both new files fail at collection with
ImportError: cannot import name 'webhook_guard', and main's_validate_webhook_urlacceptshttp://127.0.0.1/,localhost,127.0.0.1.nip.io,[fd00:ec2::254],169.254.169.254.and2130706433.Manual Testing
Environment: Python 3.12.3, pytest 9.1.1,
PYTHONPATH=src.pip install -e .[dev]is unresolvable on main today (agentmesh-platform[dev] pins agentrust-trace<0.6; agent-governance-toolkit-core 5.0.0 pins <0.3), so venvs were built withuv venvplus--no-depsand the test dependencies.New and touched suites on the branch:
Full suites, same venv, main vs branch:
PermissionError: missing optional dependencies and subprocess spawn in the sandbox).An independent second pass rebuilt the environments (agent-os with the native ACS SDK built with maturin, as CI does) and re-ran on a detached
origin/mainworktree and on the branch:test_webhook_guard.pyfiles fail at collection withImportError.test_webhook_guard.py+test_advisory.py+test_approval_strict.py: 175 passed. Fulltests/: 2 failed, 4618 passed, 81 skipped. The 2 failures aretests/test_server.py::TestMainModule::test_unknown_component_exitsand::test_no_args_exits(PermissionError: [Errno 13] Permission denied: 'python', subprocess spawn in the sandbox), reproduced identically onorigin/main.test_webhook_guard.py+test_webhooks.py: 73 passed. Fulltests/: 3 failed, 3327 passed, 57 skipped. The 3 failures aretests/test_new_features_batch2.py::TestSandboxProvider::test_subprocess_echo/_timeout/_failure, same subprocess sandbox issue, reproduced identically onorigin/main.Lint and checks:
Eight terms added to
.cspell-repo-terms.txtin sorted position:setsockopt,functools,gaierror,getaddrinfo,getproxies,IPPROTO,NODELAY,NUMERICHOST.Checklist
Attribution & Prior Art
Prior art / related projects (if any):
The design mirrors this repository's own .NET
WebhookApprover(#3363): request-time resolution, deny-set check on every record, pinned connect, no proxy.AI Assistance
If AI tools materially shaped this change, briefly note what was used:
Claude Code drafted the fix and tests under my direction; an independent verification pass re-ran the tests on main and on the branch and probed bypasses, and I reviewed the result.
IP, Patents, and Licensing