Skip to content

refactor(log): source sensitive redaction lists from config as pure extensions#3961

Merged
PierreBrisorgueil merged 4 commits into
masterfrom
refactor/3953-config-sensitive-markers
Jul 16, 2026
Merged

refactor(log): source sensitive redaction lists from config as pure extensions#3961
PierreBrisorgueil merged 4 commits into
masterfrom
refactor/3953-config-sensitive-markers

Conversation

@PierreBrisorgueil

@PierreBrisorgueil PierreBrisorgueil commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • What changed: SENSITIVE_PATH_MARKERS and SENSITIVE_QUERY_KEYS (module route vocabulary) were hardcoded inside lib/helpers/redactUrl.js. They now read optional config.log.sensitivePathMarkers / config.log.sensitiveQueryKeys keys and Set-union them with the authoritative built-in defaults, behind a shape guard (non-array / malformed config values are ignored, never thrown).
  • Why: route vocabulary is module-specific, not shared-lib concern — modules need a way to extend the redaction surface without forking lib/. Config extension is additive-only by design: config can never shrink, disable, or crash redaction, since the built-ins always apply regardless of what config provides.
  • Related issues: Closes 🔧 Move sensitive path markers from lib/ to config #3953

Scope

  • Module(s) impacted: lib/helpers/redactUrl.js (shared lib), config/defaults/development.config.js
  • Cross-module impact: none — pure additive extension point, existing callers unaffected (empty/absent config = built-in-only behavior, byte-identical to before)
  • Risk level: low

Validation

  • npm run lint
  • npm test
  • Manual checks done (if applicable)

Guardrails check

  • No secrets or credentials introduced (.env*, secrets/**, keys, tokens)
  • No risky rename/move of core stack paths
  • Changes remain merge-friendly for downstream projects
  • Tests added or updated when behavior changed

Notes for reviewers

  • Security considerations: redaction is additive-only by construction — a shape guard means malformed/missing config can never disable or narrow the built-in redaction set, so a misconfigured downstream project cannot accidentally leak sensitive path segments or query params into logs. config/defaults/development.config.js deliberately omits the two keys — a downstream/module-layer default that did set them would otherwise get clobbered by deepMerge's array-replace semantics; a lockstep test pins this (defaults file has no markers/keys) so the omission can't regress silently.
  • Mergeability considerations: redactUrl.js now imports config — verified no circular dependency; degrades gracefully (falls back to built-ins) if config resolution fails.
  • Follow-up tasks (optional): the lockstep guard test currently pins only development.config.js (prod/test configs don't define these keys today); extending the pin to those configs if/when they start defining the keys is a cheap follow-up, not required for this change.

Tests: 2148 green, redactUrl.js at 100% coverage — new cases cover union semantics, empty config, malformed config (shape guard), and the defaults-omission lockstep.

https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup

Summary by CodeRabbit

  • New Features

    • Added runtime configuration options for extending sensitive URL query keys and path markers used during log redaction.
    • Built-in redaction protections remain enforced, while custom entries are merged and deduplicated.
  • Bug Fixes

    • Invalid redaction configuration values are safely ignored with a warning instead of causing failures.
  • Documentation

    • Added guidance describing the available redaction configuration options and their handling.

lib/ must stay module-agnostic — SENSITIVE_PATH_MARKERS and
SENSITIVE_QUERY_KEYS in lib/helpers/redactUrl.js hardcoded auth/invitations
route vocabulary owned by feature modules (#3935). Move both lists to
config.log.sensitivePathMarkers / config.log.sensitiveQueryKeys (current
values as defaults in config/defaults/development.config.js) so a module
extends redaction coverage from its own config without editing shared lib/.

redactUrl.js reads the lists from config once at module load, falling back
to the built-in literals when config or the key is absent — redaction
degrades safely instead of silently redacting nothing in an edge context.
Exports/API unchanged (existing consumers: lib/middlewares/analytics.js,
lib/services/express.js).

Closes #3953

Claude-Session: https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup
deepMerge replaces arrays (no union), so a module-level
config.log.sensitivePathMarkers/sensitiveQueryKeys extension clobbered
the global default instead of extending it, and a `??` fallback let an
explicit empty array silently disable redaction for that vector.
Compute the effective lists as a Set-deduped union of the built-in
DEFAULT_SENSITIVE_* base with config.log.*, so config is purely
additive from any layer and redaction can never be disabled via
config. development.config.js's entries become empty arrays (the
extension point), killing the literal duplication with redactUrl.js.

Claude-Session: https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup
Phase-0 iteration-2 review findings on #3953:
- Remove log.sensitivePathMarkers/sensitiveQueryKeys from
  config/defaults/development.config.js. deepMerge (config/index.js)
  replaces arrays wholesale, so declaring these as [] at Layer 2 (global
  defaults) silently clobbered any Layer 1 (module config) extension of
  the same key. Omitting the key lets a module value pass through
  untouched; a comment documents the extension point.
- Guard redactUrl.js against non-array config values via a
  sanitizeConfigList helper: an object/number would throw at
  module-eval (boot crash), a string would spread char-by-char (silent
  over-redaction). Malformed values now fall back to [] (defaults still
  apply) and log a console.warn identifying the offending config path.
- Add malformed-value tests (object + string) and a lockstep guard test
  pinning that development.config.js never re-declares either key.

Claude-Session: https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup
@PierreBrisorgueil PierreBrisorgueil added the Refactor Neither fixes a bug nor adds a feat label Jul 16, 2026
@PierreBrisorgueil PierreBrisorgueil self-assigned this Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@PierreBrisorgueil, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8d0fee14-0b79-4f61-9e8e-e90616df7017

📥 Commits

Reviewing files that changed from the base of the PR and between 6a48c6a and 605959c.

📒 Files selected for processing (1)
  • lib/helpers/tests/redactUrl.unit.tests.js

Walkthrough

URL redaction now accepts optional configured sensitive query keys and path markers, unions them with built-in defaults, warns on invalid list types, and preserves defaults when configuration is absent. Documentation comments and Jest coverage describe and verify the configuration behavior.

Changes

URL redaction configuration

Layer / File(s) Summary
Configurable redaction lists
config/defaults/development.config.js, lib/helpers/redactUrl.js
Redaction lists combine built-in values with validated runtime configuration, while development configuration comments document the optional extension points and merge behavior.
Configuration sourcing tests
lib/helpers/tests/redactUrl.unit.tests.js
Tests verify configured extensions, default preservation, missing configuration, malformed values, warning emission, and development configuration lockstep checks.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

Suggested labels: security

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: sourcing redaction lists from config as additive extensions.
Description check ✅ Passed The description follows the template and includes the summary, scope, validation, guardrails, and linked issue.
Linked Issues check ✅ Passed The changes satisfy #3953 by moving sensitive markers/keys to config while preserving built-in defaults and keeping redaction additive-only.
Out of Scope Changes check ✅ Passed The edits stay focused on the redaction helper, config defaults, and tests, with no unrelated code changes visible.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/3953-config-sensitive-markers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.72%. Comparing base (5c43bb1) to head (605959c).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3961      +/-   ##
==========================================
+ Coverage   92.70%   92.72%   +0.02%     
==========================================
  Files         169      169              
  Lines        5563     5580      +17     
  Branches     1791     1794       +3     
==========================================
+ Hits         5157     5174      +17     
  Misses        326      326              
  Partials       80       80              
Flag Coverage Δ
integration 61.02% <77.77%> (-0.03%) ⬇️
unit 74.48% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c43bb1...605959c. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil
PierreBrisorgueil marked this pull request as ready for review July 16, 2026 16:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/helpers/tests/redactUrl.unit.tests.js`:
- Around line 197-206: Ensure both affected tests in
lib/helpers/tests/redactUrl.unit.tests.js (lines 197-206 and 208-217) always
restore their console.warn spies: wrap each test body in try/finally and move
warnSpy.mockRestore() into the finally block, preserving the existing assertions
and behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e30538f2-26bf-43ad-9f24-db5f210930f2

📥 Commits

Reviewing files that changed from the base of the PR and between 2edb8e4 and 6a48c6a.

📒 Files selected for processing (3)
  • config/defaults/development.config.js
  • lib/helpers/redactUrl.js
  • lib/helpers/tests/redactUrl.unit.tests.js

Comment thread lib/helpers/tests/redactUrl.unit.tests.js
@PierreBrisorgueil
PierreBrisorgueil merged commit 8c3b208 into master Jul 16, 2026
8 checks passed
@PierreBrisorgueil
PierreBrisorgueil deleted the refactor/3953-config-sensitive-markers branch July 16, 2026 19:44
PierreBrisorgueil added a commit that referenced this pull request Jul 17, 2026
…3972)

OAuth callbacks (GET /api/auth/:strategy/callback?code=...&state=...)
wrote the one-time authorization code and state into the morgan access
log in cleartext. Same single-use-secret-in-URL leak class already
closed for inviteToken/reset/verify-email (#3955/#3961).

Add 'code' and 'state' to DEFAULT_SENSITIVE_QUERY_KEYS in
lib/helpers/redactUrl.js so they are redacted by default everywhere,
without requiring per-project config. Update the JSDoc and the
development.config.js comment that documents the built-in defaults,
and add unit tests covering the OAuth callback shape.

Closes #3967

Claude-Session: https://claude.ai/code/session_01WfNC8bt1TgL4AsiYgCEGup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Neither fixes a bug nor adds a feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🔧 Move sensitive path markers from lib/ to config

1 participant