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
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 logfunction 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) }Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.
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
- Find exception messages built from remote or third-party response fields.
- Sanitize control characters from upstream error text before logging.
- Log a fixed message with bounded structured fields, not raw remote strings.
- Treat responses from trusted integrations as untrusted input at the log boundary.