The two bad defaults#
Most clients do one of two things with a rejected request. Some discard the body and log HTTP 422. That keeps the logs clean and makes the failure undiagnosable: the same status covers a missing parameter, a duplicate name and a value the provider refuses for its own reasons.
Others log the body, or its message, verbatim. The provider wrote that text for the caller, and it often quotes the caller's input back. A message like Reference refs/heads/fix/rotate-prod-db-password does not exist (an invented example) puts a branch name in the log, and branch names describe unreleased work. The OWASP Logging Cheat Sheet lists what to keep out of logs, including "commercially-sensitive information" and "data of a higher security classification than the logging system is allowed to store". A body you did not write can contain either, and you cannot tell from its length or its characters.
What GitHub documents#
GitHub's REST API returns errors as JSON with a message and, for validation errors, an errors array. Its troubleshooting guide documents four fixed sentences:
Problems parsing JSON, with 400, for a body that is not valid JSON.Body should be a JSON object, with 400, when the endpoint expects an object.Invalid request, with 422, for missing parameters or wrong types.Validation Failed, with 422, with anerrorsarray whose entries carry acode.
The documented codes are missing, missing_field, invalid, already_exists, unprocessable and custom. For custom, the guide says to "refer to the message property to diagnose the error", and that per-error message is free text. Each error entry can also carry resource and field. Those look like schema names, but field can name a key your client put in the request, which is your data again.
That gives a closed set: four sentences and six codes that GitHub wrote, which cannot contain anything you sent. Everything else, including every per-error message, is open text.
The lab#
The lab builds the reason a log line may carry from invented response bodies shaped like GitHub's. It needs Docker and runs in seconds.
import json
# Sentences GitHub documents for 400 and 422, and the documented error codes.
SENTENCES = {"Problems parsing JSON", "Body should be a JSON object",
"Validation Failed", "Invalid request"}
CODES = {"missing", "missing_field", "invalid", "already_exists",
"unprocessable", "custom"}
def reason(status, raw):
"""What may go in the log line. Never message text outside SENTENCES,
and never an error's resource, field or message."""
try:
body = json.loads(raw)
except ValueError:
return {"status": status, "message": "unparsed", "codes": []}
if not isinstance(body, dict):
return {"status": status, "message": "unparsed", "codes": []}
msg = body.get("message")
errors = body.get("errors")
codes = []
for e in errors if isinstance(errors, list) else []:
code = e.get("code") if isinstance(e, dict) else None
codes.append(code if isinstance(code, str) and code in CODES else "other")
return {"status": status,
"message": msg if isinstance(msg, str) and msg in SENTENCES else "other",
"codes": codes}
# Invented response bodies, shaped like GitHub's.
CASES = [
(400, '{"message": "Problems parsing JSON"}'),
(422, '{"message": "Validation Failed", "errors": [{"resource": "PullRequestReviewComment", '
'"field": "path", "code": "invalid"}]}'),
(422, '{"message": "Validation Failed", "errors": [{"resource": "Release", "code": "custom", '
'"field": "tag_name", "message": "tag_name acme-q3-acquisition-launch is not a valid tag"}]}'),
(422, '{"message": "Reference refs/heads/fix/rotate-prod-db-password does not exist"}'),
(422, '{"message": [], "errors": [{"code": {}}]}'),
(400, '<html>upstream error</html>'),
]
for status, raw in CASES:
print(json.dumps(reason(status, raw)))
Save it as reason.py in an empty directory and run it:
docker run --rm --name pl-c-vocab -v "$PWD":/lab:ro -w /lab python:3 python -I reason.py
{"status": 400, "message": "Problems parsing JSON", "codes": []}
{"status": 422, "message": "Validation Failed", "codes": ["invalid"]}
{"status": 422, "message": "Validation Failed", "codes": ["custom"]}
{"status": 422, "message": "other", "codes": []}
{"status": 422, "message": "other", "codes": ["other"]}
{"status": 400, "message": "unparsed", "codes": []}
The release tag and the branch name never reach the output, yet each line still separates the causes an engineer acts on: a malformed body, an invalid parameter, a provider-specific refusal, an unknown message, and a response from something other than the API, such as a proxy's HTML error page.
Rules for the log line#
- Allowlist, never blocklist. Compare each value against documented constants and map the rest to
other. Filters by length, character set or pattern still pass a short branch name or a key such ascustomer_tier. - Never log
resource,fieldor a per-errormessage. They are where request values come back. - Log identifiers you control. The endpoint's route template (
POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews), your own operation name, the status, and the provider's request ID from thex-github-request-idheader give support enough to find the exact request. - Keep the raw body out of error chains too. An error type whose display string includes the body will reach a log eventually, through a panic handler or an error reporter.
- Count
other. A rising count tells you a new message is worth reading. Read it by reproducing the request with test data, not by widening the log.
When you need the full body to debug a specific failure, reproduce the call against a test repository whose names are invented. The guide to reading a reviewer's leaked-token finding covers the same question for values your own code logs.
What happened in production#
In the production case behind this guide, a pull request review ended in failure when GitHub answered 400 to the request that posts the review. Its eight new inline findings never reached the pull request, and nothing recorded why: the client discarded the body of a fatal 400. The cause of that 400 is still unknown for the same reason.
The fix reads the body of a fatal 400 or 422 and logs the reason in the closed vocabulary above, beside the status. Two earlier drafts of it were rejected in code review. The first logged a short message, which could echo a branch name. The second logged resource and field filtered to plain identifier characters, which could still echo a private request key. Only the allowlist passed. The same change retries a review refused with a 400 once with its body alone, as the client already did after a 422.
Where this came from#
Proofline found this in its own GitHub review publishing and included the fix in a production release tagged 1 December 2026. The eight lost inline findings in What happened in production came from that failed post. Proofline reviews GitHub pull requests; new organizations get one calendar month of hosted code review without a cloud connection. Start a free GitHub review ยท Eligibility and fair-use terms
Questions#
Is the errors[].field value ever sensitive?
It can be. For most endpoints it names a documented parameter, but some endpoints accept caller-defined keys, and the field then repeats one of them. Leave it out of logs and recover it by reproducing the request.
What should a client do when the message is other?
Treat it as an unrecognized rejection: fail the operation with the status and the request ID, and count it. If the count rises, reproduce one case with test data and add the new sentence to the allowlist only if the provider documents it as fixed.
Does this apply to providers other than GitHub?
Yes. Most APIs document a small set of error codes and return free-text messages beside them. Log the codes and the provider's request ID, and treat the free text as your user's data.