Repository navigation
fix(security): malformed URLs get a named refusal, not a raw codec error or a 500 (abilityai/trinity#3322) - #3906
Merged
Conversation
…ror or a 500 (#3322) A host the idna codec refuses (an empty or 64+ char label) passed canonical_host's ASCII fallback, and getaddrinfo then raised UnicodeError, which the gaierror arm missed: the template-registry route echoed the codec's text and A2A callers had no reason code. Both resolve sites now map it to PublicUrlRefusal("invalid") / a refusal. An unbalanced bracket (https://[::1/x, x[/y) made urlparse raise a plain ValueError inside reject_embedded_credentials, and the skills-source routes catch only EmbeddedCredentialError, so a typo was a 500. It now falls back to the userinfo regex (still refusing a token) and otherwise leaves the URL to validate_skills_library_url, whose shorthand branch now refuses an unparseable owner/repo with "Invalid URL format". Co-Authored-By: Claude Opus 5.5 <[email protected]>
… fallback contract (#3322) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 22, 2026
Contributor
Author
/review + /validate-prVerdict: APPROVE once CI is green. No critical findings. Lane C ( Review
Fixed after review
Follow-ups filed
Local test note: ~21 IPv6-mapped / range cases fail on Python 3.11 locally on |
dolho
approved these changes
Oct 23, 2026
dolho
left a comment
Contributor
There was a problem hiding this comment.
/review: approve
Scope: clean. Both #3322 inputs now get named 400s instead of a codec error or a 500.
Execution coverage
| changed symbol | executed by | live consumer | verdict |
|---|---|---|---|
_validate_public_https_url except UnicodeError |
test_C12_an_unencodable_ascii_host_is_a_named_refusal (asserts kind invalid, no codec text) |
template-registry and A2A validators | ✅ |
_validate_trusted_a2a_url (gaierror, UnicodeError) |
test_C12_the_trusted_a2a_path_refuses_an_unencodable_host_by_name |
validate_a2a_endpoint_url |
✅ |
reject_embedded_credentials fallback |
D4 parametrized + test_D4_a_userinfo_is_still_refused_when_urlparse_cannot_parse |
routers/skills.py create / update / _validated_source_url, skill_service legacy adoption |
✅ |
validate_skills_library_url shorthand bracket check |
test_D4_the_validator_then_refuses_the_malformed_url |
same routes | ✅ |
Fix mutation: the C12/D4 cases were xfail(strict=True) against the old code, so reverting the fix turns them red.
Checked
- I traced every caller of
reject_embedded_credentials. All three router call sites runvalidate_skills_library_urlright after it and mapValueErrorto a 400.skill_serviceruns it insideexcept ValueError. So the new "return and let the validator refuse it" contract holds everywhere. - I ran the PR's functions directly.
https://tok@[::1/x,x@[/y,//tok@[oopsandtok:pw@[x/yall raiseEmbeddedCredentialError.https://[::1/x,x[/yando]/rfall through, and the validator then refuses them with "Invalid URL format". A balanced[::1]/xis unchanged. - The new refusal uses
label, which matches the siblinginvalidrefusals.
Informational (non-blocking)
validate_skills_library_url("//[oops")still returns//[oopsas an "owner/repo" shorthand, becauseurlparse("https:////[oops")doesn't raise. This is not caused by this PR and the input still fails later. Mentioning it only because it is the same family of bug.
No blocking findings.
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.
Summary
https://a..example.com/, a 64-char label):getaddrinfo's own idna encode raisesUnicodeError, which theexcept socket.gaierrorarms missed._validate_public_https_urlnow raisesPublicUrlRefusal("invalid", "<label> must have a valid hostname"), so the template-registry 400 carries our text and A2A callers get a real reason code. The trust-check resolver (return Nonesite) treats it the same asgaierror.https://[::1/x,x[/y,o]/r):reject_embedded_credentialsno longer leaks urlparse's bareValueError. It falls back to the shared userinfo regex for every shape (still refuseshttps://tok@[::1/x), and otherwise returns so the route'svalidate_skills_library_urlanswers 400 "Invalid URL format". Its shorthand branch now refuses an owner/repo urlparse cannot parse; balanced shorthands like[::1]/xare unchanged (the A8/A12 seam tests still hold).Both inputs already failed closed; this only turns kind-less errors and a 500 into named 400s.
Changes
src/backend/utils/url_validation.pytests/unit/test_ec_url_validation_edges.py: C12 and D4 xfail markers removed (C12 also asserts kindinvalidand no codec text); the D4 precondition that pinned the bareValueErroris replaced by two tests: the validator refuses the malformed URL, and a userinfo is still refused when urlparse cannot parse.Test Plan
cd tests && pytest unit/test_ec_url_validation_edges.py— the 9 C12/D4 cases now pass; no new failurespytest unit -k "url or skill or template or a2a or registry"— 58 failures vs 67 ondevlocally, none new. The remaining ones are IPv6-mapped / special-purpose range verdicts that differ on this machine's Python 3.11 (ipaddress); CI runs 3.13Fixes #3322
🤖 Generated with Claude Code