---
title: "When a reviewer says a log line leaks a token, read the value | Proofline"
description: "Decide by what the logged value contains at runtime and who reads that log."
url: https://proofline.sh/learn/ai-review-sensitive-logging-comment/
---

[Learning center](/learn/)

# When a reviewer says a log line leaks a token, read the value

Decide by what the logged value contains at runtime and who reads that log. If it can carry a credential or personal data, change the line and add a test that asserts the secret is absent from captured logs; if it holds only identifiers, status codes or an error body you have checked, dismiss with what you checked.

Code review The Proofline team November 22, 2026 4 min read

## Find what the value contains

A reviewer sees a variable name and guesses its contents. The guess is often wrong in both directions. A variable called `token` may hold a token count, and a harmless-looking exception may carry a full request URL. Before you answer, find out what the logged expression turns into as a string.

Exceptions are the usual surprise. In `aiohttp`, a `ClientResponseError` prints the request URL, including its query string. Running this against `aiohttp` 3.14.5 with a made-up key:

```
from aiohttp import ClientResponseError, RequestInfo
from multidict import CIMultiDict, CIMultiDictProxy
from yarl import URL

url = URL("https://monitoringapi.example/site/1/overview.json?api_key=FAKEKEY123")
ri = RequestInfo(url, "GET", CIMultiDictProxy(CIMultiDict()), url)
print(ClientResponseError(ri, (), status=503, message="Service Unavailable"))
```

prints `503, message='Service Unavailable', url='https://monitoringapi.example/site/1/overview.json?api_key=FAKEKEY123'`. Any API that takes its key as a query parameter leaks it through that string.

Then ask where the log goes. OWASP's list of data that "should usually not be recorded directly in the logs" includes "Access tokens", "Authentication passwords", "Session identification values" and "Sensitive personal data and some forms of personally identifiable information (PII)". [OWASP Logging Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html#data-to-exclude) For a self-hosted application, the log's readers include everyone the user pastes it to in a bug report.

## A key that was in the exception text

That `aiohttp` behavior was a real Home Assistant bug. An issue reported "SolarEdge: API key is written to the log in plain text when an API request fails". [Issue #188395](https://github.com/home-assistant/core/issues/188395) The fix explained that on a failed request "the raised `aiohttp.ClientResponseError` propagated to `DataUpdateCoordinator` and was logged verbatim." It caught the error in each Monitoring API data service and raised an `UpdateFailed` carrying only the service name and status code, with `from None`. [Pull request](https://github.com/home-assistant/core/pull/188452) Python's [`raise ... from None`](https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement) suppresses the chained context, so the traceback no longer prints the original exception and its URL.

Copilot reviewed the change on 25 October 2026 and flagged a gap in the tests: "The security regression test covers only one of six independent error-sanitization handlers." Its open item read "Cover all Monitoring API sanitization handlers in regression tests." [Review](https://github.com/home-assistant/core/pull/188452#pullrequestreview-5643225657)

The author answered with commit `9ac05c1`, which extended the secret-leak test to every API method the fix covered. The merged test is parametrized over all six API methods; each raises a `ClientResponseError` whose URL contains the key, and each asserts:

```
assert API_KEY not in caplog.text
assert "api_key" not in caplog.text
```

[Merged diff](https://github.com/home-assistant/core/pull/188452/files) The pull request merged on 27 October 2026. The reviewer's comment was right, and the right response was a test. Six handlers written the same way can each be broken separately, and a test that covers one of them proves nothing about the other five.

## A leak that depends on a hypothetical

Eight months earlier, Copilot reviewed a Cloudflare DDNS pull request in the same repository. The code logged a failed record creation with a `_LOGGER.warning` call whose arguments included `resp.status` and `await resp.text()`. Copilot wrote: "The API token is included in the Authorization header and the response text is logged in error messages." It went on: "If the Cloudflare API includes sensitive information in error responses (such as echoing back parts of the request)," "this could expose the API token in logs." [Review comment](https://github.com/home-assistant/core/pull/163104#discussion_r2854588334)

The pull request was closed without merging on 25 February 2026, so this thread has no resolution to follow. It still shows how to read the claim. The token travels in a request header; the log records the response body. The leak exists only if the API echoes request headers into error bodies, which is a claim about Cloudflare's API, not about this code. Settle it by reading the API's documented error format or capturing a real failed response in a test environment. This guide did not check Cloudflare's error format, so it does not say whether the claim was right. If the body turns out to hold only error codes and messages, dismiss and cite the format. If you cannot find out, logging the status and the API's error codes costs little.

## Decide from what the value holds

| What the log line records | Evidence to check | Response |
| --- | --- | --- |
| A credential, session ID or password | The value at runtime, including how its type prints | Change: drop or mask it, and add a test on captured logs |
| An exception or object whose string form you have not checked | Its `__str__` or `toString` output, with a fake secret | Test first, then change if the secret appears |
| One of several handlers already fixed | Whether the test covers each handler | Add the missing test cases |
| A response body from an external API | The API's documented error format, or a captured response | Dismiss with the format, or log codes only |
| Personal data such as names or addresses | Who can read the log, and for how long | Change, or mask to what debugging needs |
| Identifiers, counts or status codes | The values are not secrets | Dismiss, naming what the value is |

A test on captured logs is cheap and keeps the answer after the next refactor. When a reviewer returns to the same line on a later push, the [follow-through guide](/learn/review-finding-follow-through/) covers how to count the repeat.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [A hardcoded secret flag: rotate the key or record why it is not one](/learn/ai-review-hardcoded-secret-comment/)
    
    Code review The Proofline team November 22, 2026 4 min read
    
-   ### [What should a code reviewer do after the author pushes a fix?](/learn/review-finding-follow-through/)
    
    Code review The Proofline team November 20, 2026 3 min read
