diff --git a/CHANGELOG.md b/CHANGELOG.md index b6c3490..9eaae55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,24 @@ # Changelog +## 1.0.3 (2026-11-24) + +The follow-up to 1.0.2, in the Python SDK, from the review of its fix. The TypeScript SDK +parses URLs as a browser does (WHATWG `URL`) and does not change. + +- **A host a browser reads as another IPv4 address is refused.** A browser reads a host whose + last label is a number as an IPv4 address, abbreviated, octal or hexadecimal: + `https://0x7f.1/` and `https://0177.0.0.1/` are 127.0.0.1, and `https://3.1.2/` is + 3.1.0.2, while the SDK read the names as written. Such a host is now accepted only as a + canonical dotted-quad address (`browser_safe`), and an IP address has no subdomains: + `3.1.2` is not within `1.2` (`host_within`, used for device sign-in links, a company's + device page and Browser Control's company hosts). +- **The URLs 1.0.2 missed are checked too:** a company's logo (`PapSignIn.organization_logo`), + a UCP profile's endpoint (`UcpProfile.endpoint`), the platform profile (`ucp_agent_header`), + a Signature-Agent (sent and verified), a Session JWT's issuer before it is fetched, and the + entries of `protected_resources`. 1.0.2 said every accepted HTTPS URL was checked; with + these it is. + ## 1.0.2 (2026-11-24) A security fix in the Python SDK: a URL the SDK accepts is one a browser reads on the same diff --git a/docs/docs/protocol/conformance-report.mdx b/docs/docs/protocol/conformance-report.mdx index 389a8b5..72029b4 100644 --- a/docs/docs/protocol/conformance-report.mdx +++ b/docs/docs/protocol/conformance-report.mdx @@ -6,7 +6,7 @@ title: Compatibility and conformance report # Compatibility and conformance report -SDK version **1.0.2**, PAP profile **0.4** (as published 2026-11-10), Operations extension **v3**; the pairings run at protocol version **1.0**, the default (1.0 as published 2026-11-14); the suite also runs at 0.4 in every pairing. Each pairing runs every positive, negative and recovery fixture case over real TCP and TLS, the personal agent in one language and the reference company (Manzanita) in the other. A case is skipped, never passed, when a side lacks what it needs; the reason is listed below. +SDK version **1.0.3**, PAP profile **0.4** (as published 2026-11-10), Operations extension **v3**; the pairings run at protocol version **1.0**, the default (1.0 as published 2026-11-14); the suite also runs at 0.4 in every pairing. Each pairing runs every positive, negative and recovery fixture case over real TCP and TLS, the personal agent in one language and the reference company (Manzanita) in the other. A case is skipped, never passed, when a side lacks what it needs; the reason is listed below. ## Pairings diff --git a/docs/docs/releases/compatibility.mdx b/docs/docs/releases/compatibility.mdx index f8d71b7..c674265 100644 --- a/docs/docs/releases/compatibility.mdx +++ b/docs/docs/releases/compatibility.mdx @@ -4,7 +4,7 @@ title: Compatibility # Compatibility -This page is versioned with the SDK: it describes **SDK 1.0.2**. +This page is versioned with the SDK: it describes **SDK 1.0.3**. ## The PAP version implemented @@ -35,6 +35,7 @@ profile, never picked up from an unattended fetch. | SDK (PyPI and npm) | PAP profile | Specification revision | Operations | Breaking changes | | --- | --- | --- | --- | --- | +| `1.0.3` | `0.4` | 2026-11-10 | v3 | none: the Python SDK refuses a host a browser reads as another IPv4 address (abbreviated, octal or hexadecimal, such as `0x7f.1` or `3.1.2`), an IP address has no subdomains, and a company's logo, a UCP endpoint, a Signature-Agent and a Session's issuer are checked as every HTTPS URL is | | `1.0.2` | `0.4` | 2026-11-10 | v3 | none: the Python SDK refuses a URL a browser reads on another host (a backslash, whitespace or a control character anywhere, an authority with anything but RFC 3986 ASCII characters), so a device sign-in link is shown only on the host it was checked on (§4.3) | | `1.0.1` | `0.4` | 2026-11-10 | v3 | none: the four case decks (`./decks`) and the docs describe the cases at Poppy 1.0 as published, with Operations version 3, no longer draft 0.3 | | `1.0.0` | `0.4` | 2026-11-10 | v3 | none: the SDK's version follows Poppy's own, 1.0; the code is 0.37.5's | diff --git a/package.json b/package.json index 3e337ca..4dbcf43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@datalayer/personal-agent-protocol", - "version": "1.0.2", + "version": "1.0.3", "description": "TypeScript SDK for Personal Agent Protocol 0.4 (2026-11-10) and its Operations extension v3", "repository": { "type": "git", diff --git a/personal_agent_protocol/__tests__/test_urls.py b/personal_agent_protocol/__tests__/test_urls.py index e0a48fd..7693a3b 100644 --- a/personal_agent_protocol/__tests__/test_urls.py +++ b/personal_agent_protocol/__tests__/test_urls.py @@ -76,3 +76,110 @@ def test_every_https_check_of_the_sdk_asks_it_first() -> None: } for name, check in places.items(): assert check in (PACKAGE / name).read_text(), name + + +# --- the review of 1.0.2 ------------------------------------------------------------- + + +@pytest.mark.parametrize( + "url", + [ + "https://0x7f.1/device", # hexadecimal and abbreviated: 127.0.0.1 to a browser + "https://0177.0.0.1/device", # octal: 127.0.0.1 + "https://127.1/device", # abbreviated: 127.0.0.1 + "https://3.1.2/device", # abbreviated: 3.1.0.2 + "https://2130706433/device", # one number: 127.0.0.1 + "https://1.2.3.04/device", # a leading zero: octal to a browser + "https://1.2.3.256/device", # out of range: refused by a browser + "https://v.example.0x1/device", # a name that ends in a hexadecimal number + "https://v.example.42/device", # a name that ends in a number + "https://1.2.3.4./device", # a trailing dot + ], +) +def test_a_host_a_browser_reads_as_another_ipv4_address_is_refused(url: str) -> None: + assert not browser_safe(url) + + +@pytest.mark.parametrize( + "url", + [ + "https://127.0.0.1/device", + "https://10.0.0.1:8443/device", + "https://0.0.0.0/", + "https://v.example42/device", # a name whose last label is not all digits + "https://0xv.example/device", # not hexadecimal + ], +) +def test_a_canonical_ipv4_address_or_a_name_is_read_alike(url: str) -> None: + assert browser_safe(url) + + +def test_an_ip_address_has_no_subdomains() -> None: + from personal_agent_protocol.urls import host_within + + assert host_within("login.m.example", "m.example") + assert host_within("m.example", "m.example") + assert not host_within("evilm.example", "m.example") + # `3.1.2` read as a subdomain of `1.2` (a browser opens 3.1.0.2), and an address within another. + assert not host_within("3.1.2", "1.2") + assert not host_within("10.1.2.3", "1.2.3") + assert host_within("10.1.2.3", "10.1.2.3") + assert not host_within("a.2001:db8::1", "2001:db8::1") + assert not host_within("", "m.example") + + +def test_a_company_logo_is_checked_as_every_https_url() -> None: + from personal_agent_protocol.ui import PapSignIn + + def sign_in(logo: str) -> PapSignIn: + return PapSignIn( + mode="device", + open="https://login.m.example/device", + code="WDJB-MJHT", + organization_name="M", + organization_domain="m.example", + organization_logo=logo, + ) + + assert sign_in("https://m.example/logo.svg").organization_logo == "https://m.example/logo.svg" + for logo in ("https://v.example\\.m.example/../logo.svg", "https://0x7f.1/logo.svg"): + with pytest.raises(ValueError): + sign_in(logo) + + +def test_a_ucp_endpoint_is_checked_as_every_https_url() -> None: + from personal_agent_protocol.ucp import UcpProfile + + def endpoint(url: str) -> str | None: + return UcpProfile.model_validate( + { + "version": "2026-04-08", + "services": {"dev.ucp.shopping": [{"transport": "rest", "endpoint": url}]}, + } + ).endpoint() + + assert endpoint("https://shop.m.example/ucp") == "https://shop.m.example/ucp" + assert endpoint("https://v.example\\.m.example/../ucp") is None + assert endpoint("https://0177.0.0.1/ucp") is None + + +def test_every_https_prefix_check_also_asks_it() -> None: + """Where a URL is accepted on its `https://` prefix alone, `browser_safe` is asked too.""" + + places = { + "ucp.py": ["and browser_safe(endpoint)", "not browser_safe(platform_profile)"], + "operator_signatures.py": [ + "not browser_safe(signature_agent)", + "if not browser_safe(agent):", + ], + "company/verify.py": ["not browser_safe(issuer)"], + "models.py": ["not browser_safe(entry)"], + "ui.py": ["not browser_safe(value) or urlsplit(value).scheme"], + "device.py": ["return host_within(host, domain)"], + "browser_control.py": ["return host_within(host, domain)"], + "company/service.py": ["if not host_within(host, own):"], + } + for name, checks in places.items(): + text = (PACKAGE / name).read_text() + for check in checks: + assert check in text, (name, check) diff --git a/personal_agent_protocol/__version__.py b/personal_agent_protocol/__version__.py index b627cf8..d3c35fb 100644 --- a/personal_agent_protocol/__version__.py +++ b/personal_agent_protocol/__version__.py @@ -7,4 +7,4 @@ """Personal Agent Protocol.""" -__version__ = "1.0.2" +__version__ = "1.0.3" diff --git a/personal_agent_protocol/browser_control.py b/personal_agent_protocol/browser_control.py index 239ec7e..8c8ee85 100644 --- a/personal_agent_protocol/browser_control.py +++ b/personal_agent_protocol/browser_control.py @@ -34,6 +34,7 @@ from .errors import PersonalAgentProtocolError from .models import DiscoveryDocument, domain_host from .sessions import PapSession +from .urls import host_within BROWSER_CONTROL_EXTENSION = "browser-control" #: The version this SDK implements (Browser Control 3). @@ -267,7 +268,7 @@ def on_company_host(host: str, organization_domain: str) -> bool: that get `navigator.poppy` (Browser Control 6).""" host, domain = host.lower().rstrip("."), domain_host(organization_domain) - return host == domain or host.endswith(f".{domain}") + return host_within(host, domain) def controller_script(organization_domain: str, channel: str) -> str: diff --git a/personal_agent_protocol/company/__init__.py b/personal_agent_protocol/company/__init__.py index 18ff444..5dfec4b 100644 --- a/personal_agent_protocol/company/__init__.py +++ b/personal_agent_protocol/company/__init__.py @@ -191,7 +191,7 @@ def build_company( reactor.register_plugin( PluginManifest( name="personal-agent-protocol.company", - version="1.0.2", + version="1.0.3", contribution_points=[ COMPANY_STORES.id, COMPANY_ACCOUNTS.id, diff --git a/personal_agent_protocol/company/service.py b/personal_agent_protocol/company/service.py index 8862e3c..80991f2 100644 --- a/personal_agent_protocol/company/service.py +++ b/personal_agent_protocol/company/service.py @@ -175,7 +175,7 @@ UCP_SHOPPING, UCP_VERSION, ) -from ..urls import browser_safe +from ..urls import browser_safe, host_within from .points import ( CLIENT_POLICIES, CLIENT_RESOLVERS, @@ -785,7 +785,7 @@ def __post_init__(self) -> None: # noqa: C901 - one branch per protocol rule if self.device_page is not None: host = (urlsplit(self.device_page).hostname or "").lower() own = domain_host(self.domain) - if not (host == own or host.endswith(f".{own}")): + if not host_within(host, own): # A personal agent shows the link only on the issuer's host or # `organization.domain`, or a subdomain of either (§4.3). The issuer is on # `domain`, and an agent that found the company at an alias knows only that diff --git a/personal_agent_protocol/company/verify.py b/personal_agent_protocol/company/verify.py index 49df4a7..3b48a9d 100644 --- a/personal_agent_protocol/company/verify.py +++ b/personal_agent_protocol/company/verify.py @@ -35,6 +35,7 @@ ) from ..errors import ProofError, SessionError from ..models import ClientMetadata, JsonWebKeySet +from ..urls import browser_safe from .points import ReplayCache #: Companies accept client assertions and delegations signed with these (§4.1, §5.2): both @@ -248,7 +249,7 @@ def unverified_session_issuer(compact: str) -> str: except jwt.PyJWTError as exc: raise _refused("The Session header is not a JWT") from exc issuer = claims.get("iss") - if not isinstance(issuer, str) or not issuer.startswith("https://"): + if not isinstance(issuer, str) or not issuer.startswith("https://") or not browser_safe(issuer): raise _refused("The Session JWT names no personal agent") return issuer diff --git a/personal_agent_protocol/device.py b/personal_agent_protocol/device.py index 1b0188b..b7d8104 100644 --- a/personal_agent_protocol/device.py +++ b/personal_agent_protocol/device.py @@ -44,6 +44,7 @@ proves_with_dpop, ) from .telemetry import sign_in_method, sign_in_result, signed_in_as, traced +from .urls import host_within DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code" @@ -69,7 +70,7 @@ def _host(url: str) -> str: def _within(host: str, domain: str) -> bool: - return host == domain or host.endswith(f".{domain}") + return host_within(host, domain) def verification_host_allowed(url: str, *, issuer: str, domain: str) -> bool: diff --git a/personal_agent_protocol/models.py b/personal_agent_protocol/models.py index e1e7f0c..d9a29f6 100644 --- a/personal_agent_protocol/models.py +++ b/personal_agent_protocol/models.py @@ -903,7 +903,7 @@ def lists_resource(self, domain: str) -> bool: wanted = domain.lower().rstrip(".") for entry in self.protected_resources: - if not entry.startswith("https://"): + if not entry.startswith("https://") or not browser_safe(entry): continue host = entry[len("https://") :] if host and not any(char in host for char in "/?#@") and host.lower() == wanted: diff --git a/personal_agent_protocol/operator_signatures.py b/personal_agent_protocol/operator_signatures.py index d72ff6a..bc4fd94 100644 --- a/personal_agent_protocol/operator_signatures.py +++ b/personal_agent_protocol/operator_signatures.py @@ -41,6 +41,7 @@ from .crypto import jwk_thumbprint from .errors import PersonalAgentProtocolError, ProofError from .reactor import OperatorSignature, OperatorSignatureRequest +from .urls import browser_safe #: The headers of a signed request (RFC 9421 §4; Web Bot Auth §5.2.5). SIGNATURE_HEADER = "Signature" @@ -204,7 +205,11 @@ async def sign_operator_request( `poppy-session` when the request has one. """ - if not signature_agent.startswith("https://") or re.search(r'["\\\s]', signature_agent): + if ( + not signature_agent.startswith("https://") + or not browser_safe(signature_agent) + or re.search(r'["\\\s]', signature_agent) + ): raise ValueError("a Signature-Agent is an HTTPS URL") label = OPERATOR_SIGNATURE_LABEL authorization = request.authorization @@ -519,6 +524,9 @@ async def _checked( keyid = cast(str, offered.parameters["keyid"]) if offered.parameters.get("alg", OPERATOR_SIGNATURE_ALGORITHM) != OPERATOR_SIGNATURE_ALGORITHM: return OperatorVerdict("unverified") + if not browser_safe(agent): + # A Signature-Agent a browser reads on another host names no key: it decides nothing. + return OperatorVerdict("unverified") try: published = await keys(agent, keyid) except PersonalAgentProtocolError: diff --git a/personal_agent_protocol/reactor.py b/personal_agent_protocol/reactor.py index 50ab785..9436856 100644 --- a/personal_agent_protocol/reactor.py +++ b/personal_agent_protocol/reactor.py @@ -1094,7 +1094,7 @@ def build_pap_reactor( platform.register_plugin( PluginManifest( name="personal-agent-protocol.core", - version="1.0.2", + version="1.0.3", contribution_points=[ DISCOVERY_TRANSPORTS.id, URL_SAFETY_POLICIES.id, diff --git a/personal_agent_protocol/ucp.py b/personal_agent_protocol/ucp.py index 0a08673..ad17458 100644 --- a/personal_agent_protocol/ucp.py +++ b/personal_agent_protocol/ucp.py @@ -32,6 +32,7 @@ from .refusals import challenge_parameters from .sessions import AccessToken, PapSession from .transport import SessionHttpClient, session_error +from .urls import browser_safe #: The extension's name and version in `extensions` and `Poppy-Extensions` (UCP extension 2). UCP_EXTENSION = "ucp" @@ -78,6 +79,7 @@ def endpoint(self, service: str = UCP_SHOPPING, transport: str = "rest") -> str entry.get("transport") == transport and isinstance(endpoint, str) and endpoint.startswith("https://") + and browser_safe(endpoint) ): return endpoint return None @@ -123,8 +125,10 @@ def ucp_agent_header(platform_profile: str) -> str: URL would let Companies match a User across Companies (UCP extension 3, 10). """ - if not platform_profile.startswith("https://") or any( - char in platform_profile for char in '"\\ \t\r\n' + if ( + not platform_profile.startswith("https://") + or not browser_safe(platform_profile) + or any(char in platform_profile for char in '"\\ \t\r\n') ): raise ValueError("The platform profile is an HTTPS URL") return f'profile="{platform_profile}"' diff --git a/personal_agent_protocol/ui.py b/personal_agent_protocol/ui.py index bc2eaf4..f800d87 100644 --- a/personal_agent_protocol/ui.py +++ b/personal_agent_protocol/ui.py @@ -154,7 +154,7 @@ def _needs(cls, value: list[str]) -> list[str]: @field_validator("organization_logo") @classmethod def _logo(cls, value: str | None) -> str | None: - if value is not None and urlsplit(value).scheme != "https": + if value is not None and (not browser_safe(value) or urlsplit(value).scheme != "https"): raise ValueError("a company's logo is an HTTPS URL") return value diff --git a/personal_agent_protocol/urls.py b/personal_agent_protocol/urls.py index b920eca..9328196 100644 --- a/personal_agent_protocol/urls.py +++ b/personal_agent_protocol/urls.py @@ -17,12 +17,15 @@ Every URL the SDK accepts as an HTTPS URL is first checked here: one with no backslash, whitespace or control character, and an authority of plain RFC 3986 ASCII characters, is read on the same host by both, so the host the SDK checks -is the host the browser opens. +is the host the browser opens. A host a browser reads as an IPv4 address must be +written in its canonical form, and an IP address has no subdomains +(`host_within`). """ from __future__ import annotations import string +from ipaddress import ip_address from urllib.parse import urlsplit #: The characters of an authority (RFC 3986 §3.2): unreserved, sub-delims, `:`, `@`, `[`, `]`. @@ -56,7 +59,70 @@ def browser_safe(value: str) -> bool: netloc = urlsplit(value).netloc except ValueError: return False - return all(character in _AUTHORITY_CHARACTERS for character in netloc) + if not all(character in _AUTHORITY_CHARACTERS for character in netloc): + return False + try: + host = urlsplit(value).hostname or "" + except ValueError: + return False + # A host a browser reads as an IPv4 address is one only in its canonical form: a + # browser reads `0x7f.1`, `0177.0.0.1` and `3.1.2` as 127.0.0.1, 127.0.0.1 and + # 3.1.0.2, the SDK as the names they are written (the review of 1.0.2). + return not ends_in_a_number(host) or canonical_ipv4(host) + + +def ends_in_a_number(host: str) -> bool: + """Whether a browser reads `host` as an IPv4 address (WHATWG's "ends in a number"): + its last label, a trailing dot aside, is all digits, or `0x` and hexadecimal digits.""" + + labels = host.split(".") + if labels[-1] == "" and len(labels) > 1: + labels.pop() + last = labels[-1] + if last and all(character in string.digits for character in last): + return True + return last[:2].lower() == "0x" and all(character in string.hexdigits for character in last[2:]) + + +def canonical_ipv4(host: str) -> bool: + """Whether `host` is an IPv4 address written as a browser writes it back: four decimal + parts, 0 to 255, with no leading zero, no trailing dot.""" + + parts = host.split(".") + return len(parts) == 4 and all( + part.isascii() + and part.isdigit() + and (part == "0" or not part.startswith("0")) + and int(part) <= 255 + for part in parts + ) + + +def is_ip_address(host: str) -> bool: + """Whether `host` (as `urlsplit` gives it: lowercase, without brackets) is an IP address.""" + + try: + ip_address(host) + except ValueError: + return False + return True + + +def host_within(host: str, domain: str) -> bool: + """Whether `host` is `domain` or one of its subdomains. An IP address has no + subdomains: it is within only itself (`3.1.2` is not within `1.2`; a browser opens + 3.1.0.2).""" + + if not host or not domain: + return False + if ( + is_ip_address(host) + or is_ip_address(domain) + or ends_in_a_number(host) + or ends_in_a_number(domain) + ): + return host == domain + return host == domain or host.endswith(f".{domain}") -__all__ = ["browser_safe"] +__all__ = ["browser_safe", "canonical_ipv4", "ends_in_a_number", "host_within", "is_ip_address"] diff --git a/src/company/index.ts b/src/company/index.ts index 8a370b1..9416ddc 100644 --- a/src/company/index.ts +++ b/src/company/index.ts @@ -137,7 +137,7 @@ export function createCompanyDefaultsPlugin( ) { return definePlugin({ name: "personal-agent-protocol.company", - version: "1.0.2", + version: "1.0.3", contributionPoints: [ CompanyStores, CompanyAccounts, diff --git a/src/reactor.ts b/src/reactor.ts index 914b5a4..93b9842 100644 --- a/src/reactor.ts +++ b/src/reactor.ts @@ -371,7 +371,7 @@ export function createPapCorePlugin(options: PapCoreOptions = {}) { } return definePlugin({ name: "@datalayer/personal-agent-protocol-core", - version: "1.0.2", + version: "1.0.3", contributionPoints: [ DiscoveryTransports, UrlSafetyPolicies,