Skip to content

Canonicalization accepts five malformed authority shapes the spec requires be rejected; request_target_uri_malformed unimplemented #978

Closed

Description

@KonstantinMirin

Found while vendoring the complete AdCP 3.1.1 request-signing vector set (#975). Reproductions are canonicalization.json cases, currently strict-xfail in tests/conformance/signing/test_canonicalization.py.

Problem

The spec requires signers to refuse to sign, and verifiers to reject, URLs whose authority is syntactically malformed:

If the authority has userinfo but no host (https://user@/p), no host at all (https://:443/p or https:///p), a bracketed host missing a closing bracket (https://[::1/p), or a bare IPv6 address outside brackets (https://fe80::1/p), the URL is malformed; signers MUST NOT sign it and verifiers MUST reject with request_target_uri_malformed.
— security.mdx, @target-uri canonicalization step 3

IPv6 zone identifiers (RFC 6874) MUST be rejected. ... verifiers MUST reject @target-uri values containing %25 inside [...] with request_target_uri_malformed.
— ibid., step 2

canonicalize_target_uri() rejects only one of the six shapes. The rest are canonicalized into a well-formed-looking result and signed.

Failing cases

case input expected actual
malformed-port-without-host https://:443/p reject accepted as https:///p
malformed-userinfo-without-host https://user@/p reject accepted as https:///p
malformed-empty-authority https:///p reject accepted as https:///p
malformed-bare-ipv6 https://fe80::1/p reject accepted as https://fe80::1/p
malformed-ipv6-zone-identifier https://[fe80::1%25eth0]/p reject accepted unchanged
malformed-ipv6-missing-closing-bracket https://[::1/p reject ✅ rejected (ValueError)

The first three collapse to an empty authority, so @authority enters the signature base as the empty string and @target-uri as https:///p. Two different malformed inputs (https://:443/p and https://user@/p) canonicalize to the identical base — signatures become transferable between them.

malformed-bare-ipv6 is a distinct hazard: _canon_authority() splits fe80::1 on the last colon, yielding host fe80: and port 1, then reassembles it as fe80::1. The round-trip masks the malformation.

request_target_uri_malformed is not implemented

The spec's error code for all of these does not exist anywhere in the SDK — src/adcp/signing/errors.py has no such constant, and grep -rn request_target_uri_malformed src/ is empty. It has its own row in the transport error taxonomy:

| Request @target-uri is syntactically malformed (e.g., empty authority, bare IPv6, IPv6 zone identifier, raw non-ASCII host), OR canonicalized @authority does not byte-match the authority component of the canonical @target-uri (cross-vhost replay) | No | request_target_uri_malformed |

Because the code is missing, the vendored test asserts only that canonicalization refuses (pytest.raises(ValueError)) rather than grading the code. That assertion should be tightened to the spec code once it exists.

Note on the taxonomy row

That same row also covers a second obligation the SDK does not appear to implement: canonicalized @authority must byte-match the authority component of the canonical @target-uri, and verifiers must derive @authority from :authority/Host rather than proxy state. The spec flags it as a cross-vhost replay defense. No vector in the 3.1.1 set exercises it, so it is not covered by the strict-xfail ledger — flagging it here rather than filing separately, since the fix lands in the same place.

Suggested direction

Reject the five shapes in _canon_authority(), add request_target_uri_malformed to the error taxonomy, and map the canonicalization refusal onto it at the verifier boundary.

Activity

  1. added
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Jul 28, 2026
  2. bokelley commented on Jul 28, 2026

    @bokelley
    Contributor

    Triage

    Classification: Bug — spec-mandated rejections missing from canonicalization; request_target_uri_malformed error code unimplemented
    Bucket(s): signing (label absent from repo — gap noted)
    Status: ready-for-human
    Milestone: omitted

    What the experts said:

    • ad-tech-protocol-expert: All five shapes are spec-mandated rejections — none is implementation discretion. Cases 1–3 (empty-authority collapse) create real signature transferability across three distinct malformed inputs. The webhook_target_uri_malformed twin is mandatory in the same commit; REQUEST_TO_WEBHOOK_CODE will silently not translate the new code if the webhook constant is omitted.
    • security-reviewer: Risk is Medium — HTTP clients (httpx, requests) typically reject or normalize these malformed URLs before reaching the signing layer, so the attack precondition is strong. Zone-ID case (case 5) is academic for cloud ad-tech. The @authority/Host-derivation gap (cross-vhost replay defense) is a distinct obligation requiring Host header threading into _resolve_component — track separately; no 3.1.1 vector exercises it.
    • code-reviewer: Do not import errors.py into canonical.py — keep ValueError in _canon_authority() (consistent with the existing unterminated-IPv6 case) and translate to REQUEST_TARGET_URI_MALFORMED inside the verifier's existing except (ValueError, KeyError) block. Bare-IPv6 guard: check ":" in host after rsplit(":", 1) on line 142-143 — the current branch mis-parses fe80::1 as host="fe80:", port=1. Changing behavior of public canonicalize_target_uri/canonicalize_authority (both in __all__) is semver-relevant.

    My take: Clear conformance bug with a well-understood fix path and unanimous expert agreement. Flagged because (a) security-sensitive, (b) behavioral change to two public signing-API functions, and (c) the error taxonomy addition should get human sign-off given downstream consumers may key on error codes.

    Implementation brief:

    • src/adcp/signing/errors.py: add REQUEST_TARGET_URI_MALFORMED = "request_target_uri_malformed" and WEBHOOK_TARGET_URI_MALFORMED = "webhook_target_uri_malformed"; add REQUEST_TARGET_URI_MALFORMED: WEBHOOK_TARGET_URI_MALFORMED to REQUEST_TO_WEBHOOK_CODE
    • src/adcp/signing/canonical.py — _canon_authority() (lines 128–149): (1) after userinfo strip, raise ValueError if netloc is now empty; (2) in the [-branch, raise ValueError if %25 appears inside [...]; (3) in the elif ":" branch, after rsplit(":", 1), raise ValueError if host still contains : (bare IPv6); (4) after all branches, raise ValueError if host is empty
    • src/adcp/signing/verifier.py: in the except (ValueError, KeyError) catch, distinguish URI-malformation from other errors — either with a CanonicalUriError(ValueError) sentinel from canonical.py, or by catching the ValueError from canonicalize_target_uri/canonicalize_authority separately and mapping to REQUEST_TARGET_URI_MALFORMED
    • tests/conformance/signing/test_canonicalization.py: tighten xfail assertions for the five cases from pytest.raises(ValueError) to grading exc.code == REQUEST_TARGET_URI_MALFORMED once the verifier translation is in place; PR test(signing): vendor the complete AdCP 3.1.8 request-signing vector set and pin it against drift #980 will have marked these strict-xfail ready for the fix to XPASS
    • Cross-vhost replay (@authority must byte-match @target-uri authority; derive from Host/:authority not proxy state): out of scope for this fix — file separately

    PR #980 (open, fixing #975 test infrastructure) marks these five cases as strict-xfail, so the changeset for this issue can land before or after #980 merges without conflict — the strict-xfail entry auto-retires on XPASS.


    Triaged by Claude Code. Session: https://claude.ai/code/${CLAUDE_CODE_REMOTE_SESSION_ID}


    Generated by Claude Code

  3. added
    bugSomething isn't working
    and removed
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions