logging-formatter-anticrlf
Python logging Formatter for CRLF Injection (CWE-93 / CWE-117) prevention
What it is and what it does
logging-formatter-anticrlf is a security-focused logging formatter that prevents CRLF injection attacks by escaping carriage returns (\r) and linefeeds (\n) in log messages. It wraps Python's standard logging.Formatter with identical construction arguments, so it works as a drop-in replacement in existing logging configurations. By default, CR and LF characters are replaced with their escaped equivalents (\r and \n), preventing attackers from injecting fake log entries or manipulating log output when logs are displayed in browsers or parsed by downstream tools.
The package includes a SubstitutionMap object that manages replacements with built-in safety checks: it prevents you from replacing unsafe characters with other unsafe characters, and it resets to safe defaults if you accidentally assign an unsafe configuration. This design protects against common mistakes where a developer might inadvertently weaken the sanitization. The package addresses CWE-93 (log injection) and CRLF-based forms of CWE-117 (improper output neutralization), though it does not handle all CWE-117 variants such as XSS flaws in browser-rendered logs.
Use it for:
- Secure web applications that log user input or request data to prevent attackers from injecting fake log entries or log forging.
- Systems where logs are aggregated, parsed, or displayed in tools that interpret CR/LF as structural delimiters.
- Compliance-focused projects that need to demonstrate log integrity and prevent log tampering via injection.
- Applications handling untrusted input (API requests, form submissions) that must sanitize before logging.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A drop-in replacement for Python's standard logging.Formatter that escapes carriage returns and linefeeds in log output to prevent CRLF injection attacks (CWE-93 and CWE-117).
Yes, if you log untrusted user input or need to prevent log injection attacks. The package is low-friction (no dependencies), permissively licensed, and has no known vulnerabilities. Maintenance is dormant but the code is stable and the attack surface is minimal. Install it as a standard practice in security-conscious logging setups; the one-line formatter swap makes adoption trivial.
Install
logging-formatter-anticrlf on PyPI
pip
pip install logging-formatter-anticrlfuv
uv add logging-formatter-anticrlfpoetry
poetry add logging-formatter-anticrlfInstalling logging-formatter-anticrlf
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is dormant (last commit 2024-02-23, 1051 days since release), but the package is archived=false and has no known vulnerabilities, suggesting it is stable rather than abandoned.
License in practice
BSD-2-clause is permissive and imposes minimal restrictions on use or redistribution, making it suitable for most projects without licensing concerns.
Quickstart
import logging
import anticrlf
handler = logging.StreamHandler()
handler.setFormatter(anticrlf.LogFormatter('%(levelname)s - %(message)s'))
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.info("Text with newline\nhere") # outputs escaped as \n, not a line break
Verify before relying
- Whether the package is actively maintained or if dormant status reflects intentional stability rather than abandonment.
- Whether Python version support is truly unspecified or if there are practical constraints not documented in the fact sheet.
Package facts
| License | BSD-2-clause (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 1,051 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 185,546/month — #10,008 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: logging_formatter_anticrlf-1.2.1-py3-none-any.whl
Tags
More Security packages
Provides Python bindings to the FreeDesktop.org…
permissive · top 1,000 on PyPI
msalMSAL for Python handles OAuth2 and OpenID…
permissive · top 1,000 on PyPI
joserfcjoserfc implements JOSE standards (JWS, JWE,…
permissive · top 1,000 on PyPI
AuthlibAuthlib provides a complete implementation of…
permissive · top 1,000 on PyPI
argon2-cffi-bindingsProvides low-level CFFI bindings to the…
permissive · top 1,000 on PyPI
adalADAL for Python authenticates applications with…
permissive · top 1,000 on PyPI
logfmterFormats Python stdlib logging output as logfmt…
permissive · top 15,000 on PyPI
defusedcsvDefusedcsv is a drop-in replacement for…
permissive · top 5,000 on PyPI
MarkupSafeMarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
jsonformatterFormats Python logging output as JSON, enabling…
permissive · top 15,000 on PyPI
flake8-logging-formatA flake8 extension that enforces logging best…
permissive · top 15,000 on PyPI
logzerologzero provides pre-configured Python logging…
permissive · top 5,000 on PyPI
linear-tsvParses and writes tabular data in Linear TSV…
permissive · top 15,000 on PyPI
shellescapeProvides a `quote()` function that…
permissive · top 5,000 on PyPI
minilogMinilog wraps Python's standard logging module…
permissive · top 15,000 on PyPI
bandit-sarif-formatterConverts Bandit security analysis output into…
permissive · top 15,000 on PyPI