Repository navigation
fix(plug): broader scrubbing - #1070
Conversation
dbe6f3d to
8408dda
Compare
4b61f38 to
2cf2586
Compare
4b4dd34 to
e05c35a
Compare
2cf2586 to
67cf7dd
Compare
67cf7dd to
7b02f6c
Compare
03dd2d1 to
9240a03
Compare
7b02f6c to
613318d
Compare
9240a03 to
587cfb4
Compare
c3da499 to
72a3430
Compare
3631906 to
1f52d72
Compare
72a3430 to
0fe1d7a
Compare
32d8cf6 to
5c7697d
Compare
0fe1d7a to
2b3f068
Compare
5c7697d to
4ee788a
Compare
2b3f068 to
6d0f0fc
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6d0f0fc. Configure here.
| # when no :url_scrubber is configured, fall back to the no-op | ||
| # default_url_scrubber/1 rather than Sentry.Scrubber's scrubbing default. | ||
| |> Keyword.put_new(:url_scrubber, {__MODULE__, :default_url_scrubber, []}) | ||
| |> Keyword.put(:private_allow_list, Sentry.Config.scrubber()[:conn_private_allow_list]) |
There was a problem hiding this comment.
Bug: The use of Keyword.put bypasses a fallback default for scrubber options, creating a fragile pattern that could crash if a nil config value is ever introduced.
Severity: LOW
Suggested Fix
Replace Keyword.put with Keyword.put_new in plug_context.ex. This will ensure that the option is only set if it's not already present, allowing the fallback default in Sentry.Scrubber.new/1 to be used correctly and making the code more robust against potential nil values from the configuration.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: lib/sentry/plug_context.ex#L158
Potential issue: The code in `plug_context.ex` uses `Keyword.put` to unconditionally set
the `:private_allow_list` option for the scrubber. This bypasses the fallback default
value defined in `sentry/scrubber.ex`. While current configuration validation prevents
`Sentry.Config.scrubber()[:conn_private_allow_list]` from being `nil`, this pattern is
fragile. If a `nil` value were ever passed (e.g., due to a future refactoring or a
configuration initialization issue), it would propagate to `Map.take/2` in the scrubber,
causing a `FunctionClauseError` because the key would be present with a `nil` value, and
the default would not be used.
Also affects:
lib/sentry/scrubber.ex:328~328lib/sentry/scrubber.ex:549~549
Did we get this right? 👍 / 👎 to inform future reviews.
4ee788a to
73a3f74
Compare
6f79afb to
945df7a
Compare
Expand the default @scrubbable_conn_fields so scrub/1 also clears req_cookies and assigns, scrubs body_params and query_params with the default sensitive keys, and reduces private to an allow-list of framework metadata — in addition to today's cookies/req_headers/params. assigns is cleared wholesale because auth libraries (Guardian, Pow, Coherence) routinely store decoded tokens, full user structs, and password hashes there, where no key-based heuristic redacts safely. private mixes sensitive data (the decoded session under :plug_session, Guardian's raw JWT) with high-signal framework routing metadata, so it uses the :private_allow_list strategy: Phoenix routing/render keys are retained (configurable via :scrub_conn_private_allow_list) and everything else is dropped. This keeps the most useful triage breadcrumb — which controller/action failed — without leaking secrets. Expressed entirely through the strategy-aware attribute and the allow-list mechanism from earlier commits — no changes to scrub/1 dispatch or to the consumers (Sentry.PlugContext and Sentry.PlugCapture both funnel through Sentry.Scrubber.scrub/1). The PlugContext request-interface payload is unchanged (it reads back only params/cookies/req_headers); the broadening manifests on the PlugCapture ActionClauseError conn path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…q_cookies scrubbing Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Broadened conn scrubbing now clears req_cookies, so the session cookie value no longer appears in the inspected conn captured into frame vars. Restore the cookie-value assertion alongside the auth-header one. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
945df7a to
823f9ae
Compare

Broadens the default
%Plug.Conn{}scrubbing and adds a:scrubberconfigoption to control which
:privatekeys survive. Since v13.1.1.scrub/1on a conn now also: clearsreq_cookiesandassigns, scrubsbody_params/query_params, and reducesprivateto an allow-list (drops everything else, notably:plug_session).:private_allow_liststrategy +default_private_allow_list/0(Phoenix routing/render metadata).:scrubberconfig option;PlugContextwires it into the per-request scrubber.New
scrubberconfigThis is a top-level key with nested settings because we will need more features eventually once updated "PII handling" spec settles.