Skip to content

fix(logging): redact URL query strings in logs and error responses - #457

Open
ravi-pplx wants to merge 3 commits into
block:mainfrom
perplexityai:fix/redact-logged-urls
Open

ravi-pplx wants to merge 3 commits into
block:mainfrom
perplexityai:fix/redact-logged-urls

Conversation

@ravi-pplx

@ravi-pplx ravi-pplx commented Nov 21, 2026 •

Copy link
Copy Markdown

Presigned URLs carry their credentials in the query string (for S3, X-Amz-Credential, X-Amz-Signature and X-Amz-Security-Token). These URLs currently reach logs and error responses through:

  • the handler's cache_key log field, which is usually the upstream URL, on fill and serve failures;
  • the request middleware, which binds the raw request URI to the request's logger when log.headers is set, so every later record for that request carries it;
  • ErrorResponse, which logs the request URL;
  • net/http client errors, which quote the failing URL, including redirect targets the client never saw. ErrorResponse and the proxy strategy's error handler also return that text in the response body;
  • the git strategy's ensure-refs endpoint, which returns clone and fetch errors in its 502 body, and git fetch errors quote the remote URL.

Change

  • Loggers from logging.Configure replace URL queries with REDACTED in the message and in string, error and URL attributes, including bound and grouped attributes.
  • Redacted errors keep their formatting, so the text handler still prints the file and line that %+v adds for alecthomas/errors.
  • The middleware's uri and the handler's cache_key are also redacted explicitly, so they stay redacted under any logger.
  • ErrorResponse, the proxy error handler and git ensure-refs redact the bodies they write.

Text redaction is lexical and runs in a single pass, so it stays linear on long header values bound by the middleware:

  • A URL is a double-quoted string, or a word with a / before its ?. Quotes after that / belong to the word, because git prints redirect URLs unquoted, with any quotes in them left as they are.
  • A quoted URL's query runs to the closing quote. net/http errors quote URLs with %q, including relative redirect Location values they fail to parse, and that keeps spaces.
  • An unquoted URL's query runs to the next whitespace, because URL.String leaves quotes in queries unescaped.

Behaviour changes

  • Query strings no longer appear in logs or error response bodies. The URL up to ? is kept.
  • Because the rule is lexical, the text after a ? in a quoted string, or in a word like a/b?c, is redacted even when it is not a URL.
  • In JSON logs, url attributes that held a *url.URL, such as the one ErrorResponse adds, are now strings instead of objects with a field per URL component.

Testing

Each test fails without the corresponding change.

  • TestRedactText covers multiple URLs, nested client errors, escaped quotes, other schemes, path-only and quoted relative URLs, spaces inside quoted URLs, quotes inside unquoted paths and queries, and unclosed quotes.
  • TestRedactTextClientErrors uses errors from a real http.Client following invalid absolute and relative redirects, and redirects with apostrophes or spaces in their location.
  • TestRedactTextIsLinear checks linear time on 1 MiB inputs.
  • TestRedactingHandler covers every attribute shape through both the text and JSON handlers, including the error trace the text handler prints. TestConfigureRedactsURLQueries checks that Configure installs the redacting handler in both modes.
  • TestRedactURI and a new TestMiddleware case cover the middleware's uri.
  • TestErrorResponseRedactsURLQueries covers the ErrorResponse body and log record.
  • TestHTTPProxyErrorRedactsRedirectQuery covers the proxy error body after a redirect to a signed URL fails.
  • A new TestEnsureRefsHandler case covers the ensure-refs 502 body when git fetch fails on a redirect to a signed URL with quotes in its path.
  • TestLoggedCacheKeyOmitsQuery covers the handler's cache_key on a cache hit whose response write fails.

Created with Perplexity

@ravi-pplx
ravi-pplx requested a review from a team as a code owner November 21, 2026 23:09
@ravi-pplx
ravi-pplx requested review from luispadron and removed request for a team November 21, 2026 23:09
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T18:41:33.268976Z 912dd38 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82d99c8a5e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/logging/redact.go Resolved
Comment thread internal/logging/redact_test.go Resolved
Comment thread internal/httputil/error.go Resolved
@ravi-pplx
ravi-pplx force-pushed the fix/redact-logged-urls branch from 82d99c8 to 6d30840 Compare November 21, 2026 23:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d30840724

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/logging/redact.go Resolved
Comment thread internal/logging/redact.go Resolved
Comment thread internal/logging/redact.go Resolved
@ravi-pplx
ravi-pplx force-pushed the fix/redact-logged-urls branch from 6d30840 to 706734c Compare November 21, 2026 23:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 706734c85a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/logging/redact.go Resolved
Comment thread internal/logging/redact.go Resolved
@ravi-pplx
ravi-pplx force-pushed the fix/redact-logged-urls branch from 706734c to 89dfede Compare November 21, 2026 23:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89dfede747

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/logging/redact_test.go Resolved
Comment thread internal/logging/redact.go Resolved
@ravi-pplx
ravi-pplx force-pushed the fix/redact-logged-urls branch from 89dfede to 1eed953 Compare November 21, 2026 23:55

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1eed9530dd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread README.md Resolved
@ravi-pplx
ravi-pplx force-pushed the fix/redact-logged-urls branch 2 times, most recently from 183d1f9 to 37397e5 Compare November 22, 2026 01:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37397e5655

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/logging/redact.go Resolved
Presigned URLs carry their signature in the query string, and such URLs
reach the logs in several ways: the handler logs the cache key, which is
usually the upstream URL; the request middleware binds the raw request
URI to the logger it passes on; ErrorResponse logs the request URL; and
client errors quote the URL they failed on, including redirect targets
the client never saw. ErrorResponse, the proxy strategy and the git
strategy's ensure-refs endpoint also return error text, including git's
quoted remote URL, in the response body.

Loggers from Configure now replace URL queries with REDACTED in the
message and in string, error and URL attributes. In text, a URL is a
double-quoted string or a word with a "/" before its "?". Quotes after
that "/" belong to the word, since git prints redirect URLs unquoted and
with their quotes as is. A quoted URL's
query runs to the closing quote, since net/http errors quote URLs with
%q, which keeps spaces. An unquoted one runs to the next whitespace,
since URL.String leaves quotes in queries unescaped. The scan is a
single pass, so long header values bound by the middleware stay cheap.
The middleware and the handler's cache_key also redact explicitly, so
they stay redacted under any logger. ErrorResponse, the proxy
strategy's error handler and git ensure-refs redact the bodies they
write.

Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx
ravi-pplx force-pushed the fix/redact-logged-urls branch from 37397e5 to c0c8235 Compare November 22, 2026 02:04
Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx

Copy link
Copy Markdown
Author

@codex review

Created with Perplexity

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b3c1193833

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/logging/redact.go Resolved
Signed-off-by: Ravi Agarwal <ravi@perplexity.ai>
Co-authored-by: Perplexity <noreply@perplexity.ai>
@ravi-pplx

Copy link
Copy Markdown
Author

@codex review

Created with Perplexity

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 912dd38321

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant