Skip to content

fix(secrets): mask JSON/quoted-key credentials#551

Open
marktech0813 wants to merge 3 commits into
vouchdev:mainfrom
marktech0813:fix/549-mask-json-quoted-keys
Open

fix(secrets): mask JSON/quoted-key credentials#551
marktech0813 wants to merge 3 commits into
vouchdev:mainfrom
marktech0813:fix/549-mask-json-quoted-keys

Conversation

@marktech0813

@marktech0813 marktech0813 commented Jul 24, 2026

Copy link
Copy Markdown

Summary

mask_secrets missed JSON/quoted-key credentials (\"password\": \"...\") because the assignment regex required :/= immediately after the key name, with no room for the key's closing quote.

Fold an optional closing quote into the separator group so JSON forms redact while bare key=value / key: value keep working.

Closes #549

Test plan

  • Added regression tests for JSON/quoted-key forms and existing assignment shapes
  • pytest tests/test_secrets.py -q (local if env allows)

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • Improved secret detection for quoted JSON-style keys and common key=value or key: value formats.
    • Sensitive credential values are now more reliably redacted from output.

Allow an optional closing quote after the sensitive key name so
"password": "..." forms redact like bare key=value assignments.

Closes vouchdev#549
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 29 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: CHILL

Plan: Pro Plus

Run ID: 03b1b750-7653-4463-ad0a-6e132f117359

📥 Commits

Reviewing files that changed from the base of the PR and between 8da410a and 0ab722d.

📒 Files selected for processing (2)
  • src/vouch/secrets.py
  • tests/test_secrets.py

Walkthrough

The secret assignment matcher now handles quoted JSON-style keys before : or = operators. Tests cover quoted-key credentials and confirm existing plain assignment masking remains intact.

Changes

Secret masking

Layer / File(s) Summary
Assignment matching and validation
src/vouch/secrets.py, tests/test_secrets.py
The _ASSIGNMENT pattern accepts an optional quote before the assignment operator, with tests covering JSON-style quoted keys and existing plain = and : forms.

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

Possibly related PRs

Suggested reviewers: plind-junior

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change to mask JSON/quoted-key credentials.
Linked Issues check ✅ Passed The regex change and tests address the linked issue's quoted-key credential leak while preserving existing assignment masking.
Out of Scope Changes check ✅ Passed The changes are limited to secret redaction logic and regression tests, with no unrelated additions.
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

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.

@github-actions github-actions Bot added tests tests and fixtures size: XS less than 50 changed non-doc lines labels Jul 24, 2026

@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: 2

🤖 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 `@src/vouch/secrets.py`:
- Around line 40-43: Update the _ASSIGNMENT regex and its replacement logic to
match quoted credential values as complete units, including embedded whitespace,
while retaining the opening and closing quote delimiters. Ensure redaction
preserves the original quoted shape so JSON-like assignments remain valid and
unredacted portions cannot leak.

In `@tests/test_secrets.py`:
- Around line 108-119: Add a whitespace-containing quoted credential case to
test_masks_json_quoted_key_credentials, preferably including escaped quotes, and
assert the complete original value is absent from the masked output while the
surrounding quote structure remains intact.
🪄 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: CHILL

Plan: Pro Plus

Run ID: 132d438a-3533-4a21-a941-80c458246ca1

📥 Commits

Reviewing files that changed from the base of the PR and between f12cf4c and 8da410a.

📒 Files selected for processing (2)
  • src/vouch/secrets.py
  • tests/test_secrets.py

Comment thread src/vouch/secrets.py Outdated
Comment thread tests/test_secrets.py Outdated
Match double/single-quoted assignment values including whitespace and
escapes, and keep the surrounding quotes in the redaction so JSON-shaped
output stays valid and cannot leak a trailing token.
@github-actions github-actions Bot added size: S 50-199 changed non-doc lines and removed size: XS less than 50 changed non-doc lines labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S 50-199 changed non-doc lines tests tests and fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(secrets): mask_secrets misses JSON/quoted-key credentials

1 participant