Safeguard
Security Guides•

Should you log HTTP request bodies? When it helps and when it hurts

Default to no. Log metadata, not request bodies, because bodies carry passwords, tokens and personal data. Safe patterns for the few cases that need more.

Safeguard Security Team
4 min read

By default, no. Log request metadata such as method, path, status, size, duration and user ID, and leave the body out. Bodies routinely carry passwords, tokens and personal data, and a log store is usually readable by far more people than the database. Capture bodies only narrowly, briefly and with redaction.

Why bodies are risky

The OWASP Logging Cheat Sheet lists data that should not be logged directly: session identifiers, access tokens, authentication passwords, database connection strings, encryption keys and payment card data. It also names sensitive personal data and commercially sensitive information. Instead, the data should be removed, masked, sanitised, hashed or encrypted. And it says never log data unless it is legally sanctioned.

A request body is where those items live. A login form posts a password. An API call carries a token or a customer record. If you log the whole body, you copy secrets into a second system with weaker controls and often longer retention.

OWASP Top 10 A09 names a related weakness, CWE-532, insertion of sensitive information into a log file.

What to log instead

Log thisSkip this
Method, route template, status codeFull body
Body size and content typeAuthorization and Cookie headers
DurationQuery strings that hold tokens
User and tenant IDsForm fields such as password
Request IDUploaded file contents
Validation outcome, field names that failedThe values that failed

Use the route template, such as a path with an ID placeholder, rather than the raw URL. It groups traffic sensibly and avoids IDs or tokens leaking into paths.

Logging which field failed validation, but not the value, still tells you what an attacker is probing. The OWASP sheet says input validation failures should be treated as suspicious, not as proof of attack.

When you really need bodies

Debugging an integration sometimes needs the payload. Do it in a controlled way:

  1. Enable body logging for one route, one tenant or one request ID, not globally.
  2. Run an allow list of fields to keep, and mask everything else. An allow list is safer than a deny list.
  3. Set a short expiry and a switch that turns it off by itself.
  4. Restrict who can read that stream and record access to it, as the OWASP sheet asks.
  5. Never enable it on authentication, payment or health data routes.

Check what you already log

Search your log store for strings that should not be there: the word password, Bearer, long random looking tokens, email addresses. If a search finds them, fix the code and rotate any exposed secret, since log retention means the secret may have been readable for weeks.

Consider adding a test in CI that posts a known fake secret through the app and fails if the fake value appears in captured log output.

For related reading see sensitive data exposure in application logs.

Quick check

Can I log bodies if I redact the password field?

Redacting known fields helps, but unknown fields still leak. Prefer an allow list of fields you have chosen to keep.

What about response bodies?

The same risk applies. Responses often contain personal data and tokens, so log size and status instead.

Safeguard's SBOM and dependency scanning covers the libraries behind your logging and web stack. You can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.