Blog / A09:2021 Security Logging and Monitoring Failures
A09:2021 · Security Logging and Monitoring Failures

The Upstream's Error Text Goes Straight to Your Log

You log the error text an upstream server returns. If that server is compromised or spoofed, it writes into your logs through the exception you dutifully record.

upstream returnserror fieldsfields buildexception messageexception caughtand loggedcontrol charssplit the lineforged recordslandATTACKER INPUTIMPACTwritten to logs
Attack path · upstream returns error fields → fields build exception message → exception caught and logged → control chars split the line → forged records land

You log the error text an upstream server returns. If that server is compromised or spoofed, it writes into your logs through the exception you dutifully record.

What goes wrong

When an upstream server returns an error, the code folds its error text into an exception message and logs it. That text is not yours. It arrives across the network, from a party you happen to integrate with, and it can contain newlines and control sequences as easily as a human-readable message.

A compromised or spoofed upstream can use that path to write its own lines into your log. Because the data rides inside an error, it flows through the part of the code least likely to sanitize anything. Exception handlers tend to log first and ask questions never.

The trap is trusting a server you have a relationship with. Integration partners get breached, DNS gets redirected, a proxy goes rogue. Their response is still input, and input headed for a log needs the same newline stripping you would apply to a request body.

The pattern

Vulnerable
function throwOnError(resp) {
  if (resp.error) {
    throw new Error(resp.error + ': ' + resp.error_description)  // remote text
  }
}
// elsewhere
try { throwOnError(resp) }
catch (e) { log.warn(e.message) }   // remote text into the log
Hardened
function throwOnError(resp) {
  if (resp.error) {
    const code = sanitize(resp.error).slice(0, 64)
    throw new AppError('upstream_error', { code })   // structured, bounded
  }
}
try { throwOnError(resp) }
catch (e) { log.warn('upstream rejected request', e.fields) }
How the pipeline adjudicated itPROVEN
ABCDEFGH

Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

Log forgery from an integration partner is easy to overlook precisely because you trust that partner. The severity stays low until the day their systems are the ones that get popped, and then your logs quietly narrate whatever the attacker wants. Treat every field of a remote response as untrusted before it reaches a log line, the same way you treat a request from an anonymous client.

Check your own code