Repository navigation
Conversation
Implements the UrlValidator sketch agreed on issue a2aproject#1023: a core validator parses and resolves a URL, runs composable UrlValidationRule objects (RequireScheme, BlockPrivateNetworks with allow_hosts/allow_cidrs), and returns a ResolvedUrl that carries the addresses the host resolved to, so callers can pin connections to a validated address and guard against DNS rebinding. Domain wrappers: - PushNotificationUrlValidator: validate_push_notification_url now delegates to the composable stack; its boolean, fail-closed contract is unchanged (all existing SSRF tests pass unmodified). - AgentCardUrlValidator: new, validating agent card URLs (http/https, public addresses by default, private networks opt-in). Rules and the resolver are individually injectable so deployments can compose custom policies. Issue a2aproject#1023 scopes this to the validator as the foundation for a2aproject#975 and a2aproject#786. Refs a2aproject#1023 Signed-off-by: andy <linux2011@qq.com>
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/server/cluster/database_event_stream.py | 92.86% | 96.94% | 🟢 +4.08% |
| src/a2a/utils/push_url_validator.py | 87.80% | 100.00% | 🟢 +12.20% |
| src/a2a/utils/url_validation.py (new) | — | 99.05% | — |
| Total | 93.10% | 93.23% | 🟢 +0.13% |
Generated by coverage-comment.yml
Linux2010
marked this pull request as draft
October 10, 2026 15:09
Linux2010
marked this pull request as ready for review
October 11, 2026 01:04
Self-review follow-ups for the a2aproject#1023 draft: - expose the address union as public UrlAddress instead of a private alias (it appears in the public ResolvedUrl annotation); - match BlockPrivateNetworks allow_hosts case-insensitively: urlparse lowercases parsed hostnames, so configured exemptions must be normalized too; - deduplicate resolved addresses while preserving resolver order (getaddrinfo repeats addresses across CNAME chains and record families). Signed-off-by: andy <linux2011@qq.com>
…n_url PushNotificationUrlValidator already catches InvalidUrlError and logs, so the wrapper's own try/except was unreachable dead code and showed up as a -25% coverage regression on the per-file report (spotted by the coverage bot on this PR). The wrapper is now a single-line delegation to the domain wrapper, which owns the logging; a dedicated test module locks the boolean, fail-closed contract directly. Signed-off-by: andy <linux2011@qq.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements the
UrlValidatorsketch from #1023 as the shared, composable URL-screening foundation for both SSRF surfaces called out there (agent card URLs and push-notification webhooks):UrlValidator: parses and (optionally) resolves a URL, runs composableUrlValidationRuleobjects in order, and returns aResolvedUrlcarrying the addresses the host resolved to — so callers can pin connections to a validated address (DNS-rebinding protection).RequireSchemeandBlockPrivateNetworks(withallow_hosts/allow_cidrsexemptions for deployments that legitimately use private networks). Custom rules are plainUrlValidationRulesubclasses.PushNotificationUrlValidator—validate_push_notification_urlnow delegates to the composable stack; its boolean, fail-closed contract is unchanged (all existing SSRF tests pass unmodified).AgentCardUrlValidator— new; validates agent card URLs (http/https on public addresses by default, private networks opt-in).Scope note: per #1023 this lands the validator as the foundation; wiring the agent card validator into the client resolution path and a connection-pinning transport are follow-ups (the resolved addresses are returned precisely to enable the latter).
Notes for reviewers:
Rules and the resolver are injectable, which keeps tests deterministic without touching
loop.getaddrinfo.Cancellation is unaffected:
asyncio.CancelledErrorderives fromBaseException, so guards onExceptionnever swallow cancellation.Follow the CONTRIBUTING Guide
PR title follows Conventional Commits (
feat:→ SemVer minor)Tests and linter pass
Appropriate docs were updated (module/ABC docstrings state the contract)
Refs #1023 🦕
Validation
UrlValidatorrejects non-http(s) schemes and hosts resolving to non-public addresses;validate_push_notification_urlkeeps its exact accept/reject behavior.tests/utils/test_url_validation.py; full suite2300 passed, coverage93%(gate 88%).AgentCardUrlValidatorinto the client resolution path (proposed follow-up, happy to add on request).Prepared with AI assistance (WorkBuddy); reviewed and verified by Linux2010