A public endpoint writes the raw request body to the console. Add a newline and a fake prefix and an attacker writes their own log lines.
What goes wrong
The endpoint takes text from the request and writes it to the log as-is. A log line is delimited by newlines, and the attacker controls the bytes, so they can drop a newline in the middle and start a line that looks like it came from your system. Fake a timestamp and a level and you can forge an auth-success entry or bury a real event under noise.
The same write also captures whatever the caller sends, so any secret or personal data in that body is now sitting in your log store and everything downstream that copies it. Logs usually have looser access controls than the database. Sensitive data has a way of outliving its welcome there.
This one is low severity on its own. It gets interesting when someone trusts the logs during an incident, or when a secret lands in them and stays. Cheap to fix, easy to forget, worth closing before either happens.
The pattern
app.post('/submit', (req) => {
console.log('received: ' + req.body.text) // raw, unescaped
return ok()
})app.post('/submit', (req) => {
const clean = req.body.text
.replace(/[\r\n]/g, ' ') // no line breaks
.slice(0, 500) // bound the size
log.info('received', { text: redactSecrets(clean) })
return ok()
})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
Logs are evidence. If an attacker can write lines that look like yours, your incident timeline can be salted with fiction and the real events get harder to trust. The retention side is quieter: a password pasted into a request now lives in a system built for keeping things. Neither will page you at 3am, but both cost you when it counts. Strip control characters and redact on the way in. Keep raw caller input out of the log message.
Check your own code
- Find log calls that concatenate raw request data into the message.
- Strip or encode carriage returns and newlines before logging user input.
- Redact secrets and personal data at the logging boundary.
- Prefer structured logging with fields over string concatenation.