Skip to content

fix(security): URL credential masking uses urllib and httpx2, so passwords containing '@' and non-http schemes are masked and IPv6 hosts stay intact #1109

Closed

Description

@dan-petty

Problem

Lines cited at dcafadf.
At 132ecc5, config/constants.py:2222 is :2223; no other cited line moved.

Credentials in URLs are masked by hand-written string code in four places. Each one leaks or breaks something that urllib.parse and httpx2 already handle. Every result below comes from an offline probe against httpx2 2.13.0 at dcafadf.

  • Exception details keep part of the password. SSRFBlockedError (exceptions/security.py:40-53) finds the host with netloc.partition("@"), which splits at the first '@'. urllib and httpx2 split userinfo at the last '@'.
    • SSRFBlockedError("http://u:p@[email protected]/x").details["target_url"] is http://<auth>@[email protected]/x. That is the value after the base class has masked it.
    • For http://169.254.169.254:abc/, the constructor itself raises a plain ValueError ("Port could not be cast to integer value as 'abc'"), so the refusal is never built.
  • The URL masker drops IPv6 brackets. mask_uri_credentials (security/sanitizer.py:288-307) rebuilds the authority from hostname with an f-string.
    • http://u:pw@[2001:db8::1]:8080/p comes out as http://u:***@2001:db8::1:8080/p, which no parser can read back.
    • Its regex fallback (:302-307) is the only reason some passwords are masked today. mysql://root:pa/[email protected]/x and mysql://root:12/[email protected]/x both come out as mysql://root:***@example.com/x, and http://u:1234#[email protected]/ as http://u:***@example.com/.
  • The telemetry endpoint masking is wrong in two ways. sanitize_telemetry_endpoint (sanitizer.py:343-366):
    • turns http://[::1]:4318 into http://::1:4318;
    • leaves http://100.64.1.2:4318 unmasked, because 100.64.0.0/10 is neither is_private nor is_loopback;
    • matches loopback against a string tuple (:352).
  • The free-text redactor only handles http and https. This is the URL entry of redact_text's pattern table (sanitizer.py:235-239), https?://[^:/\s@]+:[^@/\s?#]+@.
    • It leaves what follows the first '@': https://u:p@[email protected]/x becomes https://<masked-user>:<masked-password>@[email protected]/x.
    • It rewrites every http:// URL it masks as https://.
    • It leaves these unmasked: postgres://app:s3cret@…, redis://:pw@…, uppercase HTTP://U:PW@…, empty-username http://:secret@…, http://u:pa#ss@… and mysql://root:pa/ss@….
    • Every DevOpsCLIError message and its details pass through redact_text (exceptions/base.py:10-16, :37-44). So do review diffs before they reach the model (ai/review/runner.py:1399, :1741, :1921, :1970).
  • Two call sites pass free text to the URL masker. argo/gitops.py:399 (mask_secrets(mask_uri_credentials(str(exc)))) and sandbox/metrics.py:446 (redact_text(mask_uri_credentials(str(exc)))) both hand an exception message to the single-URL masker. A URL parser finds no userinfo in a sentence, so these calls must rely on the free-text redactor alone.
  • served_by is stored as received. It is LiteLLM's x-litellm-model-api-base reply header (config/constants.py:2222). Its only readers today are ai/client/openai.py:175 and :205. It goes unmasked into:
    • the spend ledger (ai/spend/ledger.py:659-674), which groups by it at :164-165;
    • the call observers (ledger.py:677-691);
    • the event payload (ai/client/unified.py:124-125);
    • the llm.served_by span attribute (unified.py:140-141). Span attributes are stored exactly as passed in (telemetry/tracer.py:362-364, :1033).
  • The Vault address is recorded as given. security/vault_broker.py:170-171 puts vault_addr on the security.vault_broker.get_status span, and the debug logs at :122 and :162 print URLs built from it. The address comes from VAULT_ADDR, and nothing rejects userinfo in it (:71-88).
  • A pass-through wrapper. _sanitize_telemetry_endpoint (server/routes/telemetry.py:21-23) only calls sanitize_telemetry_endpoint. The no-shims rule (AGENTS.md:91) forbids such wrappers. Two test files import it.

The replacement uses library parsers only. One fixed placeholder, <masked-url>, stands for any whole value that is replaced because it cannot be parsed safely.

  • Single URLs (mask_uri_credentials, SSRFBlockedError, the Vault span and logs) are parsed with httpx2.URL. httpx2 2.13.0 is a direct, exact-pinned dependency (pyproject.toml:19), and it is the parser of the client that sends.
    • Fail closed. Return <masked-url>, never the input, in two cases:
      • httpx2 raises httpx2.InvalidURL. It raises Invalid port: 'pa' on mysql://root:pa/[email protected]/x and http://u:pa#[email protected]/.
      • httpx2 finds no userinfo, but the input contains '@'. A password that starts with digits and contains '/', '?' or '#' parses as a port without error: mysql://root:12/[email protected]/x gives host root and port 12, and http://u:1234#[email protected]/ gives host u and port 1234. A password that starts with '/', '?' or '#' (http://u:/[email protected]/) gives host u.
      • Today's regex fallback masks all five. Returning the input in either case would leak passwords that are masked today.
      • The second case also catches a URL with '@' only in its path or query. Key question 7 weighs that cost.
    • Rewrite only when there is a password (u.password is not empty). Use u.copy_with(username=u.username, password="***"). For an empty username, copy_with(username="***", password=None) gives the http://***@… that tests pin. Pass both arguments: copy_with(password="***") alone drops the username. A lone username follows key question 1.
    • Use a URL-safe placeholder, ***. httpx2 percent-encodes <auth> as %3Cauth%3E.
    • SSRFBlockedError masks target_url before cutting it to 256 characters. Its partition("@") and _replace(netloc=…) code is deleted.
      • Its message keeps today's text, for example SSRF blocked: http://<masked>:8000/api (reason) for http://192.0.2.1:8000/api, with scheme, port and path taken from the same httpx2 parse.
      • The message is display text, not a URL, so <masked> is inserted as text. Building it through httpx2 (copy_with(host="<masked>")) gives http://%3Cmasked%3E:8000/api, which fails tests/test_exceptions.py:48 ("<masked>" in str(err)).
      • A target that fails closed gives target_url <masked-url> and the message SSRF blocked: <masked-url> (reason).
  • Free text (the URL entry of redact_text; the pattern table already accepts a callable replacement):
    • Finding candidates. A candidate starts at a scheme in RFC 3986's grammar (section 3.1), capped at 32 characters: [A-Za-z][A-Za-z0-9+.-]{0,31}://. It runs until whitespace or until the next scheme start, so every scheme:// begins its own candidate. One pattern does both: [A-Za-z][A-Za-z0-9+.-]{0,31}://(?:(?![A-Za-z][A-Za-z0-9+.-]{0,31}://)\S)*.
      • Why stop at the next scheme. re.sub matches do not overlap. With a plain \S+ tail, ["http://example.com","http://u:[email protected]"], http://example.com,http://u:[email protected] and https://example.com/login?next=https://u:[email protected]/x are each one candidate whose userinfo is empty, so the second URL's password would pass through. Today's regex masks the second URL in all three.
      • Why not stop at quotes or angle brackets. A raw " in a password (http://u:pa"[email protected]/) would then cut the candidate before its '@' and leak. Today's regex masks it.
      • Speed. The uncapped scheme [A-Za-z][A-Za-z0-9+.-]*:// takes quadratic time: offline, 40,000 letters with no :// took 2.0 s and 3.8 s in two runs. The capped pattern with the lookahead stays linear (see the speed criterion).
      • A scheme longer than 32 characters still matches from a later letter, so its authority is still found.
    • Masking. Parse each candidate with urllib.parse.urlsplit, which also splits userinfo at the last '@'.
      • If urllib finds a password (password is not None, which covers an empty username as in redis://:pw@…), replace only the userinfo inside the candidate text with the <masked-user>:<masked-password> markers (key question 4). The userinfo is the len(username) + 1 + len(password) characters after scheme://; urlsplit returns both undecoded.
      • A lone username (ssh://[email protected]/o/r) follows key question 1: <masked-user>@ if yes, unchanged if no.
      • Never re-serialise the URL. httpx2 turns HTTP://U:[email protected]:80/a/../b into http://U:***@example.com/b, so review diffs would show lowercased schemes and hosts, punycoded names, dropped default ports and removed dot segments. It also rejects the template postgresql://{user}:{password}@{host}:{port}/{db} (Invalid port: '{port}').
    • Fail closed only for candidates that contain '@'. Such a candidate becomes <masked-url> when urlsplit raises, or when urllib found no userinfo and reading .port raises ValueError. The second case is how urllib reports root:pa/ss@… and u:pa#ss@…, where it takes the start of the password for a port.
      • A candidate without '@' stays as is.
      • Templates such as f"postgresql://{user}:{password}@{host}:{port}/{db}" have userinfo, so only their userinfo is replaced.
      • A candidate urllib rejects is replaced whole, trailing characters included. In ["http://example.com","http://u:[email protected]"] the second candidate is http://u:[email protected]"]. Its authority ends in "], which urllib rejects as a broken IPv6 host, so the output ends "<masked-url>. Nothing leaks, but the "] is lost. With a path (…@example.com/x"]), the "] falls in the path and only the userinfo changes.
    • Known limit (free text only). A password that parses as a port (mysql://root:12/[email protected]/x, http://u:1234#[email protected]/, http://u:/[email protected]/) looks the same as a credential-free URL with a port and a later '@' (http://example.com:8080/[email protected], https://example.com:8443/@user). Those must stay unchanged in review diffs, so these candidates stay as written, as they do under today's regex. A password that contains :// also stays, because it starts a new candidate. Single URLs fail closed on both (above).
  • The two callers that pass free text (gitops.py:399, sandbox/metrics.py:446) drop the inner mask_uri_credentials call. They keep the free-text redactor they already apply.
  • Telemetry endpoint.
  • served_by. One helper reads the header named by CONST_AI_GATEWAY_SERVED_BY_HEADER from a reply's headers and returns its value without userinfo, using httpx2.URL(value).copy_with(userinfo=b""). It sits in ai/client/network.py beside stream_served_by (:53).
  • The wrapper is deleted. The route (server/routes/telemetry.py:48) calls sanitize_telemetry_endpoint directly.
  • Out of scope:

Acceptance criteria

  • A parametrised, offline table test pins the old and new behaviour:
Input Function Today After
http://u:p@[email protected]/x SSRFBlockedError(...).details["target_url"] http://<auth>@[email protected]/x http://u:***@example.com/x
http://u: + 300 × p + @example.com/ same masked http://u:***@example.com/ (masked before the 256-character cut)
http://192.0.2.1:8000/api str(SSRFBlockedError(...)) and target_url message holds http://<masked>:8000/api; target_url as given the same
http://169.254.169.254:abc/ SSRFBlockedError(...) raises ValueError constructs; target_url is <masked-url>; the message is SSRF blocked: <masked-url> (…) and holds no 169.254
http://u:pw@[2001:db8::1]:8080/p mask_uri_credentials http://u:***@2001:db8::1:8080/p http://u:***@[2001:db8::1]:8080/p
mysql://root:pa/[email protected]/x, http://u:pa#[email protected]/ mask_uri_credentials mysql://root:***@example.com/x, http://u:***@example.com/ <masked-url>
mysql://root:12/[email protected]/x, http://u:1234#[email protected]/ mask_uri_credentials mysql://root:***@example.com/x, http://u:***@example.com/ <masked-url>
http://:[email protected]:8080/data mask_uri_credentials http://***@example.com:8080/data http://***@example.com:8080/data, as today
https://u:p@[email protected]/x in text redact_text https://<masked-user>:<masked-password>@[email protected]/x https://<masked-user>:<masked-password>@example.com/x
http://u:[email protected]/x in text redact_text scheme rewritten to https:// http://<masked-user>:<masked-password>@example.com/x
postgres://app:[email protected]/x, redis://:[email protected]:6379, HTTP://U:[email protected]/, http://:[email protected]/ in text redact_text unchanged userinfo replaced by the markers; scheme, host and path as written
["http://example.com","http://u:[email protected]/x"] redact_text second URL masked, scheme rewritten to https:// ["http://example.com","http://<masked-user>:<masked-password>@example.com/x"]
["http://example.com","http://u:[email protected]"] redact_text second URL masked, scheme rewritten to https:// ["http://example.com","<masked-url> (fails closed; no pw)
https://example.com/login?next=https://u:[email protected]/x redact_text second URL masked https://example.com/login?next=https://<masked-user>:<masked-password>@example.com/x
url=http://example.com;db=postgres://u:[email protected]/x redact_text unchanged url=http://example.com;db=postgres://<masked-user>:<masked-password>@example.com/x
mysql://root:pa/[email protected]/x, http://u:pa#[email protected]/ in text redact_text unchanged <masked-url>
mysql://root:12/[email protected]/x, http://u:1234#[email protected]/ in text redact_text unchanged unchanged (the known limit)
f"postgresql://{user}:{password}@{host}:{port}/{db}" in text redact_text unchanged postgresql://<masked-user>:<masked-password>@{host}:{port}/{db}, no placeholder
<a href="http://u:[email protected]/x">x</a> redact_text scheme rewritten to https:// only the userinfo changes; every other byte is identical
http://example.com:8080/[email protected], x = "http://[" + h redact_text unchanged unchanged
custom://[email protected]/path, https://[email protected]/o/r both maskers unchanged as key question 1 decides
http://[::1]:4318 sanitize_telemetry_endpoint http://::1:4318 http://[::1]:4318
http://100.64.1.2:4318 same unchanged http://internal-ip:4318
http://u:[email protected]:4318/v1/traces same http://<internal-ip>:4318/v1/traces http://internal-ip:4318/v1/traces
http://[invalid-ipv6 same <internal-endpoint> <internal-endpoint>
  • served_by. A mocked gateway reply has x-litellm-model-api-base: http://u:[email protected]:11434. On both the blocking and the streaming path, these hold http://example.com:11434 and no pw:
    • the ledger row;
    • the call-observer payload;
    • the event payload;
    • the llm.served_by span attribute.
  • A reply whose header is http://u:12/[email protected]:11434 stores no served_by on either path.
  • The source test for served_by's helper passes. Today rg -n 'CONST_AI_GATEWAY_SERVED_BY_HEADER|x-litellm-model-api-base' src prints config/constants.py:2222 and openai.py:21, :175 and :205. Afterwards it prints only the constant and the helper's module.
  • Vault. With VAULT_ADDR=https://u:[email protected]:8200, the get_status span's vault_addr attribute and the debug log lines contain no pw.
  • Speed. A test masks each of these in under 1 s:
    • 100 KB of text holding 1,000 credential URLs;
    • 100 KB of letters with no ://;
    • 100 KB with no whitespace holding 25,000 a://;
    • 100 KB with no whitespace of http://u:[email protected], repeated.
    • An offline prototype of these rules took 0.02 to 0.06 s for each across three runs, and no pw survived. The loose bound keeps the test from flaking on slow hosts.
  • No construct left.
  • Tests updated:
    • tests/test_consolidation_security_sanitizer.py: <internal-ip> becomes internal-ip at :273 and :277. :112-114 follows key question 1, and so do :57, :92 and :104 if its stricter alternative is chosen.
    • tests/test_exceptions.py:58: <auth>@ becomes user:***@.
    • tests/test_subsystem_containment_and_redaction.py:209-215: imports from devops_cli.security.sanitizer (:210), and <internal-ip> becomes internal-ip at :214-215.
    • tests/test_network_security_and_trace_correlation.py: imports from devops_cli.security.sanitizer (:15, used at :63-81), and <internal-ip> becomes internal-ip at :69.
    • These stay green unchanged:
      • tests/test_consolidation_security_sanitizer.py:117-147 (DevOpsCLIError and VaultError masking);
      • tests/test_exceptions.py:44-50, which pins <masked> in the message and an unchanged target_url;
      • tests/test_scan_outcomes_and_gating.py:360-372, which pins https://<masked-user>:<masked-password>@git.example.com/ for an https input;
      • tests/test_argo_gitops.py:427-442;
      • tests/test_docs_ingester.py:201-215;
      • tests/test_ai_served_by.py.
  • Tests run offline, with no DNS lookups and no sockets. uv run devops ci passes.
  • A changelog.d fragment names:
    • the newly covered schemes;
    • http:// URLs keeping their scheme;
    • the <masked-url> placeholder;
    • the internal-ip placeholder;
    • stripping userinfo from served_by.

Key questions

  • Should a lone username be masked, as in https://[email protected]/o/r? Proposed: yes (owner decision). The URL masker writes ***@ and free text gets <masked-user>@, because in this CLI's URLs a lone username is more often a token than a name.
    • Costs:
      • tests/test_consolidation_security_sanitizer.py:112-114 changes;
      • review diffs show ssh://<masked-user>@github.com/… for ssh://[email protected]/….
    • The same reasoning applies to the <token>:x-oauth-basic@ form used with GitHub OAuth tokens. There, the URL masker's user:***@ still shows the token. A stricter alternative masks the username whenever a password is present as well (***@). That changes the user:***@ outputs pinned at tests/test_consolidation_security_sanitizer.py:57, :92 and :104.
  • May the free-text scan use a regex? Proposed: yes, because no library finds URLs inside prose.
  • Why two parsers? Proposed:
    • httpx2.URL for single URLs. It is the sending client's parser, and it builds the masked URL with brackets kept.
    • urlsplit for free text, where the URL must be spliced rather than re-serialised.
    • urlsplit for the telemetry endpoint too, where httpx2 is looser (http://[invalid-ipv6).
    • Both split userinfo at the last '@'.
  • Which placeholder goes where? Proposed:
    • *** inside URLs that httpx2 builds;
    • internal-ip for the telemetry host;
    • <masked-url> for a whole value that fails closed, in single URLs and in free text;
    • in free text, the existing <masked-user>/<masked-password> markers. ai/tasks/verify_finding_system.md:59 tells the model that checks review findings that <masked-kind> markers are the tool's redactions and that any other mask is the file's own text, so *** in a review diff would be misread. <masked-url> follows the marker form.
  • Strip served_by's userinfo, or mask it? Proposed: strip it. The ledger groups by served_by (ledger.py:164-165), userinfo adds nothing to a display, and a masked username would still split the groups.
  • Does the telemetry endpoint wait for fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897? Proposed: yes. It uses fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897's loopback predicate in place of the tuple at sanitizer.py:352, which fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897 also lists. If this item is ready first, it ships everything else, and the telemetry endpoint follows in a second PR after fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897 PR1.
  • Is failing closed on a stray '@' too broad for single URLs? Proposed: no; accept the cost.
    • A credential-free URL with '@' only in its path or query becomes <masked-url>. Today's fallback already garbles such a URL when a ':' follows the scheme: http://example.com:8080/[email protected] becomes http://example.com:***@example.com. It leaves one without a ':' unchanged, such as https://example.com/x/[email protected]/mod.ts.
    • The visible cost is in the docs crawler. It labels each chunk and its result with mask_uri_credentials of the page URL (ai/library/docs_ingester.py:278, :288), so a page whose path has a package@version segment loses its source label. It never shows a password.
    • Single-URL inputs are configuration values, SSRF targets and the Vault address, where '@' outside userinfo is rare. Telling such a URL from a password that starts with digits would need a hand-written check of the authority, which the library-first rule forbids.

Strategic alignment

Activity

  1. added
    type/security
    scope/ai
    scope/security
    scope/telemetry
    priority/p1-high
    on Oct 3, 2026
  2. added this to the v0.2.31 milestone on Oct 8, 2026
  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.31 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: finding identity v2, URL credential masking, tests that leave no state, the Docker endpoint check and the Argo CD/OTel perimeters. Position 3 of 10 in the release's planned merge order. This item still needs refinement before its release starts (see the planning note), so its board Status stays New.

  4. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Owner decision, 2026-10-08, on key question 1: a URL that carries only a username (for example https://[email protected]) is not masked. Only passwords are masked, through urllib and httpx2 as this item specifies. This answers the item's open question, so it is Ready and placed in v0.2.31.

  5. dan-petty-bot commented on Oct 9, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1488, merged into release/v0.2.31 as 0b06ff4.

    Closes #1109.

    Standardizes URL credential masking using httpx2.URL and urllib.parse.urlsplit:

    • Single URI masking (mask_uri_credentials) parses with httpx2.URL, masking password to '***' while preserving IPv6 bracket formatting and non-http schemes. Fails closed to '' on httpx2.InvalidURL or unparsable credentials containing '@'. Preserves lone usernames without password.
    • SSRF error reporting (SSRFBlockedError) eliminates fragile string partition and netloc replacement, using mask_uri_credentials before bounded truncation and formatting with '' host literals.
    • Free-text redaction (redact_text) scans candidate URLs via RFC 3986 32-char scheme lookahead (CONST_URL_CANDIDATE_RE) and splices masked userinfo (:) via urllib.parse.urlsplit, failing closed to '' if invalid candidate contains '@'.
    • OTLP telemetry endpoints (sanitize_telemetry_endpoint) validate IP perimeters using ipaddress (is_global and loopback checks), replacing non-global IPs with 'internal-ip'.
    • AI client gateway responses (extract_served_by) strip user credentials from x-litellm-model-api-base via httpx2.URL(val).copy_with(userinfo=b"").
    • Vault broker traces mask credentials on vault_addr span attributes.

    17 file(s) changed.

    How it was verified

    Check runs at 1a6bf36:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1109-url-credential-masking.md:

    • Parametrized offline table test pins all 25 old and new masking behaviors across single URLs, SSRF targets, free text, and telemetry endpoints (tests/test_url_credential_masking.py::test_acceptance_criteria_table).
    • Passwords containing @, #, or / are masked properly, IPv6 host brackets remain intact, and non-HTTP schemes are covered.
    • http:// URLs keep their scheme without being rewritten to https://.
    • Whole values that fail closed use the <masked-url> placeholder.
    • Internal, private, CGNAT (100.64.0.0/10), link-local, and documentation IPs in telemetry endpoints are masked to the internal-ip placeholder.
    • Userinfo is stripped from served_by across blocking and streaming paths (test_gateway_served_by_blocking_and_streaming_strips_credentials).
    • Only config/constants.py and ai/client/network.py reference x-litellm-model-api-base or CONST_AI_GATEWAY_SERVED_BY_HEADER.
    • Vault get_status span attribute vault_addr contains no credentials (test_vault_broker_status_span_masks_credentials).
    • Free-text URL masking runs in under 1.0 second across 100 KB fixtures (test_free_text_masking_speed).
    • Forbidden constructs (_replace(netloc, partition("@"), https?://[^, ://([^:]*)) are completely eliminated from exceptions/security.py and security/sanitizer.py (test_no_forbidden_constructs_remain).
    • mask_uri_credentials(str( eliminated from src/.
    • _sanitize_telemetry_endpoint wrapper eliminated from src/ and tests/.
    • changelog.d/1109.md records the change.
    • uv run devops ci passes.
  6. added a commit that references this issue on Oct 9, 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

    priority/p1-highscope/aiscope/securityscope/telemetrytype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions