Home / Learn Secure SQL / Log Injection Awareness
Log Injection Awareness
When a log line itself can be manipulated by attacker-controlled text.
How to think about this
What it is
Log injection happens when attacker-controlled input (containing newline characters or log-format-specific syntax) is written into a log file unescaped, letting it forge what looks like a separate, fake log entry, or in rare cases exploit a vulnerable logging library itself.
Why it matters
This is the same core 'code and data mixing' idea from earlier in the course, applied to log files instead of SQL: a log line is also a structured text format, and attacker-controlled text written into it without care can change its meaning.
Mechanically speaking
Use a structured (JSON) logging library, which naturally avoids this by keeping each field as its own distinct value rather than building one free-text line by concatenation, and keep logging libraries themselves patched and up to date.
Shows up in
- Web application code review
- Backend development
- Database administration
A well-known real-world example (a 2021 vulnerability in a widely-used Java logging library) showed that log-processing logic itself can have serious vulnerabilities, which is also why keeping logging libraries patched and current matters, not just how you call them.
Check yourself
1. Log injection is best prevented by...
Structured fields avoid the concatenation problem.