
Defensive analysis of CVE-2009-4496: terminal escape-sequence injection into Boa web server logs — source review, patch analysis and reproducible checks.
This repository documents a defensive analysis of CVE-2009-4496, a historical vulnerability associated with the Boa web server.
The objective of this project is to examine the vulnerability from a defensive security perspective through:
No active testing, exploitation, authentication attempts, scanning, or modification of third-party systems was performed.
CVE: CVE-2009-4496
Affected software identified by the CVE record: Boa 0.94.14rc21
Weakness classification reported by NVD: CWE-20 — Improper Input Validation
Official NVD severity: CVSS v2.0 5.0 — Medium
CVSS v2.0 vector: AV:N/AC:L/Au:N/C:P/I:N/A:N
The vulnerability concerns the handling of non-printable characters in request data that Boa writes to its logs. The Debian fix targets the error log.
According to the CVE description, specially crafted HTTP requests containing terminal escape sequences could cause such characters to be written to the log without adequate sanitization. The full NVD description is quoted in analysis/CVE-2009-4496.md.
The resulting impact depends on how the log is subsequently displayed and, in particular, on the behavior of the terminal emulator used to view it.
Passive information indicated an HTTP service reporting the following software banner:
Server: Boa/0.94.14rc21
This version is associated with CVE-2009-4496.
However, a version banner alone is not sufficient to establish that a specific system remains vulnerable.
Possible reasons include:
For this reason, the observed system was treated only as a potential version match.
No attempt was made to validate the vulnerability against that system.
Historical Boa source code was reviewed locally, at pinned revisions of the gpg/boa mirror. Revisions and line references are listed in analysis/PATCH-ANALYSIS.md.
The analysis identified error-logging logic in which the request pathname was used when constructing error output: log_error_doc() writes the decoded path (req->pathname) to the error log as received.
Whether control characters can reach that path depends on the build:
allow_8bit.diff (listed in the Debian changelog since 0.94.14rc21-0.1, 2006). It removes the check on percent-decoded bytes, so a percent-encoded ESC is decoded into the path. Before the fix, that path was written to the error log as received whenever the requested file could not be opened.Conceptually, the historical behavior in the Debian build can be represented as:
HTTP request (path with %XX)
↓
percent-decoding (check removed by allow_8bit.diff)
↓
request pathname
↓
error logging
Later corrected code introduces an intermediate escaping operation:
HTTP request
↓
request pathname
↓
escape_pathname()
↓
escaped pathname
↓
error logging
The relevant corrected logic creates a sanitized representation of the pathname before using it in the error log.
This prevents characters requiring special treatment in the pathname from being written directly in their original form. The request line, the Host header and the access log are not changed by the fix (see Patch Analysis).
The corrected implementation evaluates pathname characters before they are written to the log.
Characters considered safe remain unchanged: letters, digits and -_.!~*'():@&=+$,/?, the set Boa also uses for URLs.
Characters requiring escaping are converted to a textual hexadecimal representation of the form:
\xNN
The backslash itself is escaped (as \x5c), so an escaped control character cannot be confused with the same text typed literally in a request.
The security purpose of this transformation is to prevent a control character from reaching the output context in its original form.
For example, the distinction is conceptually:
Raw control character
↓
terminal may interpret it
versus:
Textual representation such as \xNN
↓
displayed as text
The relevant defensive principle is therefore output neutralization of untrusted data before it reaches a potentially sensitive output context.
The corrected implementation introduces an escaping step before the pathname is written to the relevant error output.
The central change can be summarized as:
Before:
request pathname
↓
error log
After:
request pathname
↓
escaping
↓
escaped pathname
↓
error log
The analysis therefore supports the conclusion that the corrective measure addresses the handling of potentially unsafe characters in the pathname before it is written to the error log.
Debian records the issue as fixed in Boa package version:
0.94.14rc21-4
The fix is debian/patches/escape-errorlog.diff. Revision 0.94.14rc21-5 ships the same patch.
Two limitations apply:
req->pathname in log_error_doc() is escaped. The request line and the Host header in the error log, and the whole access log, are still written as received. In the reviewed code, this leaves the CR, TAB and DEL gap described above; ESC is already rejected for those fields. A few CGI error messages also print the decoded path as received. When CGI is enabled by file extension, which is not the default configuration, they could still write percent-encoded control bytes to the error log (source review, not tested).escape_pathname() reads the input through a plain char and sign-extends bytes ≥ 0x80. On platforms where char is signed, such as x86 and x86-64, each such byte produces ten output characters instead of the four reserved, and the helper writes past the end of a heap buffer. Because allow_8bit.diff lets such bytes into the path, a request for a path that contains them and cannot be opened reaches this code. That chain was established by source review. The overflow itself was reproduced at function level with AddressSanitizer. gpg/boa commit 94e1252 (2014) corrects it. Whether Debian shipped a corrected package after 0.94.14rc21-5 could not be determined.