Skip to content

Accuracy improvements for py/clear-text-logging-sensitive-data #21595

@tacu22

Description

@tacu22

Description of the issue
Hey, I found two common cases where the rule doesn't match in my codebase. One creates noise, the other misses a real leak.

First, SecretStr masks text automatically (e.g., prints '**********'). Logging these objects is safe, but the rule flags them.

from pydantic import SecretStr

password = SecretStr("super_secret")
logging.info("Login: %s", password) # Flagged, but actually safe
  1. Logging an exception object leaks its message (via str), but the rule misses this if the secret is inside the exception.
secret_token = "secret_123"
# logging.error("Auth failed: %s", secret_token)  # Detected ✅
try:
    raise ValueError("Auth failed: {}".format(secret_token))
except ValueError as e:
    # Currently NOT flagged, but leaks 'secret_123' via __str__ ❌
    logging.error("Auth failed: %s", e)  

Maybe we should add the first pattern to the sanitizers and add the second one as a propagator in the taint tracking config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions