Skip to content

๐Ÿ›ก๏ธ Sentinel: [HIGH] Fix DSN secret redaction boundary and encoding vulnerabilities - #665

Closed
seonghobae wants to merge 1 commit into
mainfrom
sentinel-dsn-redaction-fix-2582297972876054861
Closed

๐Ÿ›ก๏ธ Sentinel: [HIGH] Fix DSN secret redaction boundary and encoding vulnerabilities#665
seonghobae wants to merge 1 commit into
mainfrom
sentinel-dsn-redaction-fix-2582297972876054861

Conversation

@seonghobae

@seonghobae seonghobae commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

๐Ÿšจ Severity: HIGH

๐Ÿ’ก Vulnerability: The DSN redaction logic leaked secrets in error messages if the password contained percent-encoded characters (like %20 or +) or if it started/ended with non-alphanumeric characters (like = or &). This occurred because urlsplit does not fully decode the password, and the redaction regex incorrectly applied strict alphanumeric word boundaries to all secrets, skipping valid matches.

๐ŸŽฏ Impact: Sensitive database credentials could be leaked in raw unredacted error messages or server logs, potentially allowing unauthorized access to the databases if logs are exposed.

๐Ÿ”ง Fix: Updated _password_candidates_from_dsn to explicitly decode URL-encoded passwords using unquote_plus and dynamically add all encoding variations (unquote_plus, quote, quote_plus) to the redaction candidates set. Modified _redact_secret_occurrences to dynamically apply word boundaries only when the corresponding edge character of the secret is alphanumeric, preventing regex match failures when secrets start or end with special characters.

โœ… Verification: Tested against edge cases via manual python execution and successfully ran all existing tests via cd backend && uv run pytest. Logged critical security learning in .jules/sentinel.md.


PR created automatically by Jules for task 2582297972876054861 started by @seonghobae

Summary by CodeRabbit

  • ๋ฒ„๊ทธ ์ˆ˜์ •

    • DSN์— ํผ์„ผํŠธ ์ธ์ฝ”๋”ฉ์ด๋‚˜ ํ”Œ๋Ÿฌ์Šค ๊ธฐํ˜ธ๊ฐ€ ํฌํ•จ๋œ ๊ฒฝ์šฐ์—๋„ ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ๊ฐ™์€ ๋ฏผ๊ฐ ์ •๋ณด๊ฐ€ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€์— ๋…ธ์ถœ๋˜์ง€ ์•Š๋„๋ก ๊ฐœ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.
    • ํŠน์ˆ˜๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜ ๋๋‚˜๋Š” ์‹œํฌ๋ฆฟ๋„ ๋ณด๋‹ค ์ •ํ™•ํ•˜๊ฒŒ ์ฐพ์•„ ์•ˆ์ „ํ•˜๊ฒŒ ๋งˆ์Šคํ‚นํ•ฉ๋‹ˆ๋‹ค.
  • ๋ฌธ์„œ

    • DSN ์‹œํฌ๋ฆฟ ๋งˆ์Šคํ‚น ๋ฐ ์ธ์ฝ”๋”ฉ ์ฒ˜๋ฆฌ ๊ธฐ์ค€๊ณผ ํ…Œ์ŠคํŠธ ๊ฐ€์ด๋“œ๋ฅผ ๋ณด์™„ํ–ˆ์Šต๋‹ˆ๋‹ค.

@google-labs-jules

Copy link
Copy Markdown

๐Ÿ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a ๐Ÿ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

๐Ÿ“ Walkthrough

Walkthrough

DSN ๋น„๋ฐ€๋ฒˆํ˜ธ ์‹œํฌ๋ฆฟ ํ›„๋ณด๊ฐ€ ๋””์ฝ”๋”ฉ๋œ ๊ฐ’๊ณผ ์—ฌ๋Ÿฌ URL ์ธ์ฝ”๋”ฉ ๋ณ€ํ˜•์„ ํฌํ•จํ•˜๋„๋ก ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์‹œํฌ๋ฆฟ ์ •๊ทœ์‹ ๊ฒฝ๊ณ„๋Š” ์–‘ ๋ ๋ฌธ์ž์˜ ์˜์ˆซ์ž ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์กฐ๊ฑด๋ถ€๋กœ ์ ์šฉ๋˜๋ฉฐ, ๊ด€๋ จ ์ทจ์•ฝ ์‚ฌ๋ก€์™€ ํ…Œ์ŠคํŠธ ์ง€์นจ์ด ๋ฌธ์„œํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Changes

DSN ์‹œํฌ๋ฆฟ ๋ฆฌ๋‹คํฌ์…˜

Layer / File(s) Summary
๋น„๋ฐ€๋ฒˆํ˜ธ ์ธ์ฝ”๋”ฉ ํ›„๋ณด ์ƒ์„ฑ
backend/app/dsn_redaction.py
DSN ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ unquote_plus๋กœ ๋””์ฝ”๋”ฉํ•œ ๋’ค ๋””์ฝ”๋”ฉ ๊ฐ’๊ณผ quote, quote_plus ๋ณ€ํ˜•์„ ์‹œํฌ๋ฆฟ ํ›„๋ณด๋กœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
๋ฆฌ๋‹คํฌ์…˜ ๊ฒฝ๊ณ„ ์ฒ˜๋ฆฌ
backend/app/dsn_redaction.py, .jules/sentinel.md
์‹œํฌ๋ฆฟ ์–‘ ๋ ๋ฌธ์ž์˜ ์˜์ˆซ์ž ์—ฌ๋ถ€์— ๋”ฐ๋ผ ์ •๊ทœ์‹ ๊ฒฝ๊ณ„๋ฅผ ์กฐ๊ฑด๋ถ€ ์ ์šฉํ•˜๊ณ , ๊ด€๋ จ ์ธ์ฝ”๋”ฉ ๋ฐ ๊ฒฝ๊ณ„ ์ฒ˜๋ฆฌ ์ง€์นจ์„ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.

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

๐Ÿšฅ 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 ์ œ๋ชฉ์ด DSN ๋น„๋ฐ€ ๋ฆฌ๋‹คํฌ์…˜์˜ ๊ฒฝ๊ณ„ ๋ฐ ์ธ์ฝ”๋”ฉ ์ทจ์•ฝ์  ์ˆ˜์ •์ด๋ผ๋Š” ํ•ต์‹ฌ ๋ณ€๊ฒฝ์„ ๋ช…ํ™•ํ•˜๊ณ  ๊ตฌ์ฒด์ ์œผ๋กœ ์š”์•ฝํ•ฉ๋‹ˆ๋‹ค.
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check โœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check โœ… Passed Check skipped because no linked issues were found for this pull request.
โœจ Finishing Touches
๐Ÿ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
๐Ÿงช Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel-dsn-redaction-fix-2582297972876054861

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

@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 `@backend/app/dsn_redaction.py`:
- Around line 93-95: Update the boundary checks used to build pattern in the DSN
redaction logic so their character classification matches the ASCII [A-Za-z0-9]
lookarounds. Replace the Unicode-aware secret[0].isalnum() and
secret[-1].isalnum() checks with an ASCII-consistent approach, preserving the
existing behavior for empty secrets and the compiled pattern structure.
- Around line 62-65: Update the DSN password-candidate handling around the
normal parsing and malformed-DSN fallback so both paths use a shared helper to
add the raw value plus unquote_plus, quote, and quote_plus variants. Ensure the
fallback currently handling raw_password and unquote also generates the encoding
variants, including cases such as p%20ass versus p+ass, while preserving
existing redaction 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 129aa56d-1c4f-45d9-a4d6-961428e2ab46

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 4bf3968 and bbba13b.

๐Ÿ“’ Files selected for processing (2)
  • .jules/sentinel.md
  • backend/app/dsn_redaction.py

Comment on lines +62 to +65
decoded = unquote_plus(password)
candidates.add(decoded)
candidates.add(quote(decoded, safe=""))
candidates.add(quote_plus(decoded, safe=""))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

๐Ÿ”’ Security & Privacy | ๐ŸŸ  Major | โšก Quick win

malformed DSN fallback์—๋„ ๋™์ผํ•œ ํ›„๋ณด ๋ณ€ํ˜•์„ ์ ์šฉํ•˜์„ธ์š”.

urlsplit์ด ValueError๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด password๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•„ ์ด ๋ธ”๋ก์ด ์‹คํ–‰๋˜์ง€ ์•Š๊ณ , fallback์€ raw_password์™€ unquote๋งŒ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค(Line 67โ€“73). ์˜ˆ๋ฅผ ๋“ค์–ด p%20ass๊ฐ€ ๋“œ๋ผ์ด๋ฒ„ ์˜ค๋ฅ˜์—์„œ p+ass๋กœ ์ถœ๋ ฅ๋˜๋ฉด ํ•ด๋‹น ํ›„๋ณด๊ฐ€ ์—†์–ด secret์ด ๋‚จ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ •์ƒ ํŒŒ์‹ฑ๊ณผ fallback์ด ๊ณตํ†ต helper๋ฅผ ์‚ฌ์šฉํ•ด unquote_plus, quote, quote_plus ๋ณ€ํ˜•์„ ๋ชจ๋‘ ์ƒ์„ฑํ•˜๋„๋ก ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ œ์•ˆ ์ˆ˜์ •
+def _add_password_candidates(candidates: set[str], raw_password: str) -> None:
+    decoded = unquote_plus(raw_password)
+    candidates.update(
+        {
+            raw_password,
+            unquote(raw_password),
+            decoded,
+            quote(decoded, safe=""),
+            quote_plus(decoded, safe=""),
+        }
+    )
+
 if password:
-    candidates.add(password)
-    decoded = unquote_plus(password)
-    candidates.add(decoded)
-    candidates.add(quote(decoded, safe=""))
-    candidates.add(quote_plus(decoded, safe=""))
+    _add_password_candidates(candidates, password)

...
-    candidates.add(raw_password)
-    candidates.add(unquote(raw_password))
+    _add_password_candidates(candidates, raw_password)
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
decoded = unquote_plus(password)
candidates.add(decoded)
candidates.add(quote(decoded, safe=""))
candidates.add(quote_plus(decoded, safe=""))
def _add_password_candidates(candidates: set[str], raw_password: str) -> None:
decoded = unquote_plus(raw_password)
candidates.update(
{
raw_password,
unquote(raw_password),
decoded,
quote(decoded, safe=""),
quote_plus(decoded, safe=""),
}
)
...
if password:
_add_password_candidates(candidates, password)
...
_add_password_candidates(candidates, raw_password)
๐Ÿค– Prompt for 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.

In `@backend/app/dsn_redaction.py` around lines 62 - 65, Update the DSN
password-candidate handling around the normal parsing and malformed-DSN fallback
so both paths use a shared helper to add the raw value plus unquote_plus, quote,
and quote_plus variants. Ensure the fallback currently handling raw_password and
unquote also generates the encoding variants, including cases such as p%20ass
versus p+ass, while preserving existing redaction behavior.

Comment on lines +93 to +95
left_bound = r"(?<![A-Za-z0-9])" if secret and secret[0].isalnum() else ""
right_bound = r"(?![A-Za-z0-9])" if secret and secret[-1].isalnum() else ""
pattern = re.compile(rf"{left_bound}{re.escape(secret)}{right_bound}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

๐ŸŽฏ Functional Correctness | ๐ŸŸก Minor | โšก Quick win

๊ฒฝ๊ณ„ ํŒ์ •์˜ ๋ฌธ์ž ์ง‘ํ•ฉ์„ ์ •๊ทœ์‹๊ณผ ์ผ์น˜์‹œํ‚ค์„ธ์š”.

str.isalnum()์€ Unicode ์˜์ˆซ์ž๊นŒ์ง€ True๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€๋งŒ ์‹ค์ œ lookaround๋Š” ASCII [A-Za-z0-9]๋งŒ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ Unicode ๋ฌธ์ž๊ฐ€ ์ธ์ ‘ํ•œ secret์—์„œ๋Š” ์˜๋„ํ•œ ๊ฒฝ๊ณ„๊ฐ€ ์ ์šฉ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ASCII ์ „์šฉ ๋™์ž‘์ด๋ผ๋ฉด edge ํŒ์ •๋„ ASCII ๊ธฐ์ค€์œผ๋กœ ์ œํ•œํ•˜๊ณ , Unicode๋ฅผ ์ง€์›ํ•œ๋‹ค๋ฉด ํŒ์ •๊ณผ lookaround์— ๋™์ผํ•œ ๋ฌธ์ž ์ง‘ํ•ฉ์„ ์‚ฌ์šฉํ•˜์„ธ์š”.

๐Ÿงฐ Tools
๐Ÿช› ast-grep (0.44.1)

[warning] 94-94: Regex pattern passed to re is built from a non-literal (variable, call, concatenation, or f-string) value. If that value is attacker-controlled it can introduce a malicious pattern with catastrophic backtracking (ReDoS). Use a hardcoded literal pattern, or validate/escape untrusted input with re.escape() and bound the regex complexity before compiling.
Context: re.compile(rf"{left_bound}{re.escape(secret)}{right_bound}")
Note: [CWE-1333] Inefficient Regular Expression Complexity.

(redos-non-literal-regex-python)

๐Ÿค– Prompt for 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.

In `@backend/app/dsn_redaction.py` around lines 93 - 95, Update the boundary
checks used to build pattern in the DSN redaction logic so their character
classification matches the ASCII [A-Za-z0-9] lookarounds. Replace the
Unicode-aware secret[0].isalnum() and secret[-1].isalnum() checks with an
ASCII-consistent approach, preserving the existing behavior for empty secrets
and the compiled pattern structure.

@seonghobae

Copy link
Copy Markdown
Collaborator Author

Closed as superseded security/agent finding; share snapshot redaction already on main, reversing-spec redaction tracked in #681. Duplicate/overlapping Sentinel noise.

@seonghobae seonghobae closed this Jul 31, 2026
@google-labs-jules

Copy link
Copy Markdown

Closed as superseded security/agent finding; share snapshot redaction already on main, reversing-spec redaction tracked in #681. Duplicate/overlapping Sentinel noise.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

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.

1 participant