RedactingFilter (core/log_redact.py)

FreeRideV3 · freeride/core/log_redact.py · python · MIT
security, tag:knn-classified

Logging filter that redacts API keys and secrets from log messages before handlers format them.

# Source: https://github.com/Shaivpidadi/FreeRideV3 | License: MIT | Copyright 2026 Shaishav Pidadi
# Provided via justclaw.it.com; keep this notice with the code.
"""Keep credentials out of log lines.

Provider errors are logged with their message, and some libraries put
the offending header into that message (httpx: ``Illegal header value
b'Bearer sk-...'``). A malformed key from the environment can therefore
reach the log, and the daemon log is not always private. This filter
rewrites every record before any handler formats it.
"""

from __future__ import annotations

import logging
import re

_PATTERNS = [
    # Known key shapes.
    re.compile(r"sk-or-v1-[A-Za-z0-9]{8,}"),
    re.compile(r"\bsk-[A-Za-z0-9_-]{16,}"),
    re.compile(r"\bgsk_[A-Za-z0-9]{12,}"),
    re.compile(r"\bhf_[A-Z

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key