Safeguard
Application Security•

CWE-144 Improper Neutralization of Line Delimiters

Line breaks in input can inject new lines into files, headers and messages. Learn how CWE-144 happens and how to neutralize line delimiters.

Safeguard Security Team
2 min read

CWE-144 applies when the product receives input from an upstream component but does not neutralize, or incorrectly neutralizes, special elements that could be read as line delimiters by a downstream component. It is a variant of CWE-140, and it is not specific to any language.

How it happens

Plenty of formats treat the end of a line as meaningful: config files, log files, mail headers, protocol commands. If input containing a line break is placed in one of them, the attacker gets a fresh line of their own.

MITRE's observed example is CVE-2002-0267: a linebreak in a field of a PHP script allows admin privileges when written to a data file.

// Vulnerable: the value is trusted to be a single line
$line = $username . ":" . $level . "\n";
file_put_contents("access.cfg", $line, FILE_APPEND);
// $username = "eve:1" . "\n" . "eve" would write a second, higher entry

As MITRE notes, an injected, absent or malformed delimiter may cause the process to take unexpected actions. The difference from record delimiters (CWE-143) is mostly one of naming. Records and lines often coincide, so the fixes are the same.

What an attacker gains

The listed consequence is an integrity impact with an unexpected state. The attacker adds configuration lines, forges log entries, or alters what a line-oriented parser sees. The example above shows privilege assignment.

How to find it

  • Search for writes of external values into line-oriented outputs.
  • Send CR, LF and CRLF, plus the Unicode line separators your platform may treat as breaks, and check the result.
  • Check how each downstream consumer defines a line, since conventions differ.

How to fix it

  1. Remove or reject line break characters in single-line fields.
  2. Use a serializer or library that encodes line breaks for the format.
  3. Do not build line-based files by string concatenation when the content comes from users.
  4. Validate with an allow list of expected characters.

Quick check

Is checking for just a line feed enough?

No. Carriage return and carriage return plus line feed also end lines in many systems. Reject or encode all of them.

Sources

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.