Skip to content

feat: add log scrubbing utility and expand logger redaction paths#1108

Closed
zeroknowledge0x wants to merge 1 commit into
sublime247:mainfrom
zeroknowledge0x:fix/issue-1014-log-scrubbing
Closed

feat: add log scrubbing utility and expand logger redaction paths#1108
zeroknowledge0x wants to merge 1 commit into
sublime247:mainfrom
zeroknowledge0x:fix/issue-1014-log-scrubbing

Conversation

@zeroknowledge0x
Copy link
Copy Markdown

Closes #1014

Summary

Adds a centralized log scrubbing utility and expands pino redaction paths to prevent PII master keys and other secrets from leaking into console outputs.

Changes

1. Expanded Logger Redaction (src/utils/logger.ts)

Added redaction paths for:

  • API keys and credentials (apiKey, api_key, apiSecret, private_key, master_key, etc.)
  • Connection strings (databaseUrl, dbUrl, connectionString, redisUrl)
  • Webhook secrets (webhookSecret, webhook_secret)
  • Service and access keys (serviceKey, access_key, secretKey)
  • Wildcard variants for nested objects

2. Scrub Utility (src/utils/scrub.ts)

New utility for scrubbing secrets from console output:

  • Env-based scrubbing: Automatically redacts values of sensitive env vars (SUPABASE_SERVICE_KEY, DATABASE_URL, API_KEY, JWT_SECRET, etc.)
  • Pattern-based scrubbing: Regex patterns for Bearer tokens, Basic auth, connection strings with embedded passwords, query-string credentials, key=value pairs
  • scrubObject(): Shallow object scrubbing for structured data
  • refreshScrubMap(): Test-friendly env var refresh

3. Applied to Critical Paths (src/config/database.ts)

Applied scrub() to error logging in:

  • Read replica fallback errors (prevents connection string leaks)
  • PgBouncer stats errors

4. Test Suite (src/utils/tests/scrub.test.ts)

Comprehensive tests covering:

  • Env-based redaction for all sensitive vars
  • Bearer/Basic token scrubbing
  • Connection string password scrubbing
  • Query-string credential scrubbing
  • Object scrubbing with immutability verification
  • Safe string pass-through

Testing

Run: npx jest src/utils/__tests__/scrub.test.ts

Closes sublime247#1014

Changes:
- Expand pino redaction paths in logger.ts to cover API keys, private keys,
  master keys, service keys, connection strings, webhook secrets, and more
- Add src/utils/scrub.ts utility for scrubbing secrets from console output
  (env-based + pattern-based scrubbing for Bearer tokens, connection strings,
  query-string credentials, key=value pairs)
- Apply scrub() to database.ts error logging to prevent connection string leaks
- Add comprehensive test suite for scrub utility
@gitguardian
Copy link
Copy Markdown

gitguardian Bot commented May 30, 2026

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - JSON Web Token 45e3b17 src/utils/tests/scrub.test.ts View secret
- - Bearer Token 45e3b17 src/utils/tests/scrub.test.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@sublime247
Copy link
Copy Markdown
Owner

sublime247 commented May 30, 2026

@unsiqasik you are definitely not okay with what you are doing, linking somebody else issues🤦🏽
Disappointed in you!

@sublime247 sublime247 closed this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GOOD FIRST ISSUE] Log Scrubbing Configuration for PII master keys

3 participants