Skip to content

Conversation

@galligan
Copy link
Contributor

@galligan galligan commented Jan 23, 2026

Summary

When configureRedaction() is called with patterns or keys, redaction now applies automatically to all loggers — no need to explicitly pass redaction: { enabled: true } to createLogger().

Problem

Previously, redaction was gated on redactionConfig?.enabled:

configureRedaction({ keys: ["apiKey"] });

// This did NOT redact, despite global rules existing
const logger = createLogger({ name: "app" });
logger.info("Data", { apiKey: "secret" }); // "secret" leaked!

Solution

Check if global rules exist before skipping redaction:

const hasGlobalRules =
  (globalRedactionConfig.patterns?.length ?? 0) > 0 ||
  (globalRedactionConfig.keys?.length ?? 0) > 0;

if ((redactionConfig && redactionConfig.enabled !== false) || hasGlobalRules) {
  // Apply redaction
}

Now the same code works as expected:

configureRedaction({ keys: ["apiKey"] });

const logger = createLogger({ name: "app" });
logger.info("Data", { apiKey: "secret" }); // "[REDACTED]" ✓

Test plan

  • Added test: "global redaction patterns apply without explicit enabled flag"
  • All 42 logging tests pass
  • Typecheck passes

Fixes #40

🤖 Generated with Claude Code

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce38317fcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@galligan galligan force-pushed the p3-5/logging/redaction-default branch from ce38317 to de20be3 Compare January 23, 2026 03:42
Add early return when redaction.enabled is explicitly false, so loggers
can opt out even when global redaction rules exist.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@galligan galligan added the bug Something isn't working label Jan 23, 2026
@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Fixes critical security issue where global redaction rules weren't automatically applied to loggers, potentially leaking sensitive data when redaction: { enabled: true } was omitted
  • Updates packages/logging/src/index.ts to automatically enable redaction when global patterns or keys exist via configureRedaction()
  • Adds comprehensive test coverage for automatic redaction behavior and explicit opt-out scenarios

Important Files Changed

Filename Overview
packages/logging/src/index.ts Modified redaction logic to automatically apply global rules without requiring explicit enabled: true flag
packages/logging/src/__tests__/logging.test.ts Added test cases validating automatic redaction and explicit opt-out behaviors

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it fixes a security vulnerability and improves user experience
  • Score reflects strong implementation with proper edge case handling and comprehensive test coverage, but slight complexity in the redaction logic could benefit from additional review
  • Pay close attention to the redaction logic in packages/logging/src/index.ts to verify the conditional checks are correct

Sequence Diagram

sequenceDiagram
    participant User
    participant Logger as "LoggerInstance"
    participant ProcessMeta as "processMetadata()"
    participant RedactionCheck as "redactValue()"
    participant Sink
    participant Formatter

    User->>Logger: "logger.info(message, metadata)"
    Logger->>Logger: "shouldLog(level, minLevel)"
    Logger->>ProcessMeta: "processMetadata(metadata, redactionConfig)"
    ProcessMeta->>ProcessMeta: "Check explicit enabled: false"
    ProcessMeta->>ProcessMeta: "Check global patterns/keys exist"
    alt Global rules exist OR redaction enabled
        ProcessMeta->>RedactionCheck: "redactValue(metadata, keys, patterns)"
        RedactionCheck-->>ProcessMeta: "redacted metadata"
    end
    ProcessMeta-->>Logger: "processed metadata"
    Logger->>Logger: "Create LogRecord"
    loop For each sink
        Logger->>Formatter: "format(record)"
        Formatter-->>Logger: "formatted string"
        Logger->>Sink: "write(record, formatted)"
    end
Loading

@galligan galligan force-pushed the p3-5/logging/redaction-default branch from 8e14398 to f363099 Compare January 23, 2026 21:19
@galligan
Copy link
Contributor Author

Updated redaction tests to ensure enabled:false still opts out even when global rules are configured after logger creation.

@galligan
Copy link
Contributor Author

Checked for new feedback; no changes needed. Stack still up to date.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants