An account integration raises an exception and the HTTP library includes the full request URL. That is convenient for debugging until the URL happens to contain a credential. The SolveCaptcha API reference documents account credentials in request parameters. A local test can exercise the scenario without transmitting any credential or making a provider request.

Written with AI. The Python fixture was run locally with invented request data. The cover illustration is AI-generated.

Build a new log record from approved fields

I’d rather record an operation name, an internal request reference and a coarse result than keep a sanitized copy of whatever URL happened to appear. Any blacklist starts from the assumption that the next developer uses the same parameter names. A small allowlist avoids carrying an unexpected fragment, a username embedded in a URL, or a secret in the path.

The sample handles one known account operation and recognizes a correlation ID only when it matches the application’s own narrow format. It turns any different path into a general label. It does not return the URL or the original exception message. This is one layer of defense. A logging middleware or a distributed trace can still capture URLs independently.

import re from urllib.parse import parse_qs, urlsplit REF = re.compile(r"req-[a-z0-9]{1,12}", flags=re.ASCII) def event_for(url, status): parsed = urlsplit(url) record = {"operation": "provider_account" if parsed.path == "/account" else "provider_other", "outcome": "upstream_error" if status >= 500 else "completed"} refs = parse_qs(parsed.query).get("request_ref", []) if len(refs) == 1 and REF.fullmatch(refs[0]): record["request_ref"] = refs[0] return record test_url = ("https://fixture-user:fake-pass@example.test/account?" "key=fake-key&request_ref=req-abc123#private-fragment") record = event_for(test_url, 502) assert record == {"operation": "provider_account", "outcome": "upstream_error", "request_ref": "req-abc123"} assert not any(word in repr(record) for word in ("fixture-user", "fake-pass", "fake-key", "private-fragment")) assert "request_ref" not in event_for( "https://example.test/account?request_ref=req-first&request_ref=req-second", 200 ) assert "request_ref" not in event_for("https://example.test/fake-key?request_ref=bad!", 200) print("The log contains only the operation, outcome and approved reference") 

The test keeps the synthetic secret, username and fragment out of the resulting record. The fictitious /account route represents the adapter’s own routing policy, rather than a path to call on any provider. Expand the fixture alongside that policy if you later add operations.

For an integration test, capture what actually reaches the configured log sink. Exercise one refusal and one transport exception. An assertion on the helper alone will miss a caller that logs the original exception next to the cleaned event.

Make the evidence useful without the URL

Use the application’s internal request reference to correlate an event with a protected diagnostic system, if your team uses one. A support ticket can contain an approximate time, the operation category and the reference. The operator can then find the event without reconstructing the original request from the log. Document which layer generates the reference. If it is generated by the caller and allowed to contain arbitrary text, it can become a second route for unwanted data.