Expand description
Canonical string-based URL redaction for diagnostic surfaces (ADR-0051).
String surgery over raw URL bytes: userinfo in every authority window
is masked as ***, query/fragment content is replaced with
?[redacted] / #[redacted] sentinels, and the result is capped at
256 bytes on a UTF-8 char boundary. Authority windows are enumerated
over maximal runs of / and \ characters: pure-slash runs (the
landed // rule) open a window at two or more characters,
backslash-bearing runs only behind an RFC 3986 scheme prefix. These
helpers never parse — they are the strictest feasible handling for
strings that may be malformed or hostile.
Distinct from crate::endpoint_uri::EndpointUri::to_redacted_string,
which redacts the catalog-driven authored-URI layer (structured
EndpointUri values) and is out of scope here.
Functions§
- redact_
url - Canonical strict redaction of a raw URL string for diagnostic surfaces
(ADR-0051, bd rc-eh49): authority windows are enumerated over maximal
runs of
/and\characters — a pure-slash run of two or more characters opens a window, a backslash-bearing run opens one only behind an RFC 3986 scheme prefix ([a-zA-Z][a-zA-Z0-9+.-]*:) ending immediately before the run (a single\additionally needs a scheme of two-plus characters, or a one-character scheme whose candidate window content is credential-shaped) — and each window ends at the next/,?, or#. A window containing@carries userinfo, and the bytes from window start through the LAST@are masked in place as***@(over-masking is safe, under-masking is not). Every window is scanned, so credentials cannot hide in a later window behind a benign first one. Everything from the earliest?or#is dropped; the sentinels compose: each distinct introducer character (?and/or#) that occurs anywhere in the URL appends its matching?[redacted]/#[redacted]sentinel in first-occurrence order — queries and fragments routinely carry tokens. The result is capped at 256 bytes on a UTF-8 char boundary. There is no URL parser here, so in-place windowed masking is the strictest feasible handling. This is the string layer;crate::endpoint_uri::EndpointUri::to_redacted_stringredacts the catalog-driven authored-URI surface instead. - redact_
url_ fail_ closed - Fail-closed variant of
redact_url: when any authority window ofrawcarries an@, the whole string is replaced with[redacted]— a string with an unvalidated authority marker may carry credentials nothing validated, so nothing of it is rendered (deliberate fail-closed over-redaction per ADR-0051). Otherwise identical toredact_url. - redact_
url_ with_ query_ allowlist - Broker-style redaction: window-mask userinfo like
redact_url, then redact sensitive query params per key while keeping benign ones. A pair whose match key — the raw key single-pass%HH-decoded then lowercased (bd rc-r7v8s) — contains any ofsensitive_key_substringsrenders as{raw_key}=<redacted>(the key keeps its original encoded bytes), EXCEPT when the raw key’s own single-pass minimal decode (seeminimal_decode_pair) is credential-shaped — contains@and also:or//: then the pair renders as a bare<redacted>and the key never echoes (bd rc-yvjp3, ADR-0076 appendix: key-position credential-shape symmetry — the same predicate the benign-key branch applies to the whole pair; a key such asuser%3Asecret%40hostembeds the credentialuser:secret@hostand must not render). Well-known broker parameter names never decode to that shape, so the transport-policy diagnostic value below is preserved. Otherwise, if the pair’sminimal_decode_pairoutput is credential-shaped (contains@and also:or//), the whole pair is replaced with a bare<redacted>: encoded or literaluser:secret@hostvalues must not survive under a benign key, while a lone@(an email address) keeps the pair visible. Every other pair survives byte-for-byte, because non-secret transport policy in query params (ActiveMQ failover URIs) is the sole diagnostic value of logging the broker URL. Fragments are never echoed: everything from the first#is dropped and replaced with the#[redacted]sentinel. The result is capped at 256 bytes on a UTF-8 char boundary. String-based; no URL parser. - window_
has_ at_ sign - Whether a
@appears in any authority window ofraw. Windows come from maximal runs of/and\characters — the same enumeration the mask uses: pure-slash runs of two or more characters always open a window; backslash-bearing runs open one only behind an RFC 3986 scheme prefix ending immediately before the run. Every run is scanned, so credentials cannot hide in a later window behind a benign first one (http://h/a//user:pass@e/) or behind a scheme-prefixed backslash authority (foo:\u:p@e/), while scheme-less drive and UNC paths stay window-free.