Skip to content

fix(security): StructuredFormatter does not strip CR/LF from exc_info tracebacks / extra fields (CWE-117) #1271

Description

@groupthinking

Summary

StructuredFormatter (src/youtube_extension/backend/config/logging_config.py)
sanitizes nothing at the record level: formatException() only prepends an
"Exception Details:" header and format() returns the base-rendered string
unchanged. As a result, any attacker-controlled CR/LF reaching a sink via
logger.error(..., exc_info=True), logger.exception(...), str(exc), or a
structured extra field can forge or corrupt downstream log lines (CWE-117),
even when the interpolated message was sanitized inline (e.g. via _safe_log
in the v1 router).

Provenance

This gap was surfaced and independently confirmed on
#810 discussion r3699651770,
which noted the fix belongs centrally in the formatter — outside #810's
router.py scope — so it warrants its own focused change.

Acceptance criteria

  • Every rendered log record emits as a single physical line.
  • CR/LF (and other line separators) in message, exc_info traceback, and
    extra fields cannot forge a new log line.
  • Regression tests assert against rendered handler output, not an inline
    sanitizer's return value.
  • Benign records are unchanged.

Fix

Tracked by PR #1270 (central escape of line separators in the final rendered
record via sanitize_log_record() / _UNSAFE_LOG_CHARS).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions