cadrumo.core.remote_authority module¶
Canonical authority checks for read-only AEAT remote hosts.
This module owns the narrow parsing and suffix predicates used by remote-read guards and authenticated AEAT landings. It reads immutable external constants directly so runtime settings cannot become a competing authority.
- REMOTE_READ_SCHEME: Final[str]¶
The only scheme a remote AEAT read may use. AEAT publishes every public and authenticated read surface over TLS, so a non-
httpsauthority reaching a guard or a landing predicate is a downgrade, never a legitimate surface.
- canonical_remote_hostname(url)[source]¶
Return the bare lower-cased hostname of
url, orNoneto refuse it.This is the single authority for turning a remote URL into the hostname a safety check may compare against an allow-list. It is fail-closed:
Noneis returned — and every caller MUST treat that as a refusal — when the URL is malformed, is notREMOTE_READ_SCHEME, carries user-info credentials, or pins an explicit port.User-info and ports are refused, not stripped and not string-matched, because each of the two obvious shortcuts admits a different attack:
Matching the whole authority (
urlsplit(url).netloc) admitshttps://evil@www6.agenciatributaria.gob.es/— the credential prefix rides along inside a string that still ends in the AEAT suffix, and the browser will send it.Reading a stripped host (
pydantic.AnyUrl.host) silently discards user-info and any port, so the same URL and an:8443redirect both read as a plain AEAT host.
An authority that is not a bare host has no business reaching an authenticated AEAT surface, so it is refused rather than normalised.
- Parameters:
url (
str) – The remote URL to canonicalise, as written by the caller.- Return type:
- Returns:
The lower-cased hostname when the authority is a bare host under
REMOTE_READ_SCHEME, otherwiseNone.
- sanctioned_gov_idp_host_suffixes()[source]¶
Return host suffixes for sanctioned national-IdP surfaces (Cl@ve).
Derived from the
aeat.domains.clavecentral-config entry (Spain’s Cl@ve government identity provider). This is a NARROW, opt-in allowance distinct fromis_aeat_host(): it names the single national-IdP apex an authenticated AEAT flow structurally delegates to, never a data surface.
- is_sanctioned_gov_idp_host(host)[source]¶
Return whether
hostis under a sanctioned government-IdP apex (Cl@ve).Suffix-shaped so the observed login subdomain (
se-pasarela.clave.gob.es) is covered without enumerating unstable IdP subdomains. Admission of such a host in a guard policy is gated separately on an explicit opt-in (seeRemoteStateGuardPolicy.allows_gov_idp_hosts).