Problem/Motivation
Since #3621017 (7.7.0) Raven::getClient() passes the Sentry SDK's data_collection options:
- cookies are limited to
big_pipe_nojs; - request bodies follow "Send request body to Sentry";
- user info follows "Capture end user IP addresses";
- stack frame variables follow "Reflection tracing".
Cookies are covered. Two categories of the incoming request cannot be configured and keep the SDK defaults, which is deny-list mode with only the SDK's built-in sensitive terms (auth, token, secret, password, key, session, sso, csrf and a few more):
http_headers: every request header is sent, exceptCookie/Set-Cookie, headers whose names match the deny list, andX-Forwarded-For/X-Real-IP. That includesUser-Agent,Accept-Language,Referer(the full URL of the previous page with its query string) and any custom headers a proxy adds.url_query_params: the query string is sent inrequest.urlandrequest.query_string. Only the values of parameters whose names match the deny list become[Filtered]. Parameters such as the OAuth/OpenID Connectcodeandstate, e-mail addresses in exposed filters or search terms are sent as they are.
Separately from the SDK, Raven::log() adds the Drupal log context's request_uri and referer to the event's extra data and to the structured log attributes. Both are full URLs with their query strings.
A site that must not send this data today needs its own OptionsAlter subscriber with a before_send callback that rewrites request and extra on every event.
Steps to reproduce
- Configure a PHP DSN and enable the "Error" log level.
- Request a page with a query string, e.g.
/node/1?code=abc&state=xyz, on which an error is logged. - In Sentry, the event shows the query string in
request.url,request.query_stringandextra.request_uri, and all request headers underrequest.headers.
Proposed resolution
Set data collection for URL query parameters, HTTP request headers and HTTP response headers to allow list, make the allow lists configurable and provide default allow lists. Apply to both the PHP and browser SDKs. Data collection options can still be overridden to change the mode (deny list, disable completely, etc.)
Remaining tasks
Review the MR.
User interface changes
Three new allow list configurations, shared by PHP and browser SDKs, at the bottom of the Raven settings form.
API changes
None.
Data model changes
Three new sequence configs in raven.settings (schema, install config, post-update function).
Text initially generated with AI, with human modifications.
Issue fork raven-3630202
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
daniel.pernold commentedMerge request !84 is ready for review.
Comment #4
mfbWhat do you think about providing default allow lists for headers and query strings like I did for cookies? Some headers, and query strings - as used by Drupal core - should be fairly innocuous.
Comment #5
mfbYes, I do think URL query parameter collection policy should apply to both the PHP SDK and browser SDK. Otherwise, query params leak out as soon as someone enables the browser SDK. However, there is a problem: apparently the dataCollection.urlQueryParams policy doesn't actually work in the 10.x branch of the browser SDK, only in the new 11.x branch. See https://github.com/getsentry/sentry-javascript/pull/23061 Even the query params that are supposed to be filtered by default, such as jwt, leak out in the 10.x branch :(
So there'd have to be a disclaimer that this feature doesn't fully work yet, or wait until the next major version of Raven module, which will use the browser SDK 11.x branch.
Comment #6
daniel.pernold commentedThank you very much for the thorough review and the ideas, mfb!
I've updated MR !84:
HttpUrlCollector, so the configured query parameter policy applies to them as well.accept,cache-control,content-length,content-type,host,if-modified-since,if-none-match,origin,pragma,referer,sec-ch-ua,sec-fetch,user-agent,x-requested-with._drupal_ajax,_format,_wrapper_format,ajax_form,ajax_page_state,check_logged_in,destination,items_per_page,order,page,sort.About the browser SDK: thank you for looking into this and for the link to getsentry/sentry-javascript#23061. Since
dataCollection.urlQueryParamsdoesn't take effect in the 10.x branch, a setting there would promise more than it can deliver today. What would you think of leaving the browser SDK out of this issue and opening a follow-up for the next major version with the 11.x browser SDK? PageAttachments could then pass the same settings on todataCollection.httpHeadersanddataCollection.urlQueryParamsas they are. The new settings sit in the PHP section of the form, so until then they already read as PHP only. Of course, if you'd prefer to have it in this issue with a disclaimer, I'll gladly add that instead.One small thing I noticed while testing: the SDK's sensitive deny list contains "key", so Drupal's search parameter
keysis always sent as[Filtered]. That's probably fine, I just wanted to mention it.Comment #7
mfbI reported the 10.x browser SDK leaking URL query params upstream to Sentry, and did not confirm but it looks like they already fixed it? https://github.com/getsentry/sentry-javascript/issues/25247
In that case, the new query param setting could apply to both PHP and JS - and live at the bottom of the settings form with the capture user IP address setting.
Comment #8
mfbI also suggested upstream that the PHP SDK should filter the Referer header: https://github.com/getsentry/sentry-php/issues/2254 (someone still needs to submit a PR)
If/when that happens, the relevant code could be removed here.
Comment #9
mfbAdditional testing on browser SDK:
In the 10.x browser SDK, User-Agent and Referer are always sent to Sentry as "synthetic" HTTP headers (captured from JS window object) regardless of dataCollection.httpHeaders configuration. In 11.x, setting dataCollection.httpHeaders to FALSE results in these not being sent. Seems like a bug I could report upstream.
In both 10.x and 11.x browser SDK, the Referer is sent to Sentry unfiltered, rather than being processed as a URL, with sensitive query params filtered. Issue reported upstream: https://github.com/getsentry/sentry-javascript/issues/25303
Comment #10
mfbWell, the browser SDK 10.x branch fix (by a bot :) is still pending: https://github.com/getsentry/sentry-javascript/pull/25297
Comment #11
mfbAt this point we should be looking pretty good - the issues I filed on the PHP and browser SDKs have been resolved and backported.
Comment #12
mfbFor simplicity, maybe we can just configure HTTP headers and query parameters as an allow list? Disabling them completely doesn't seem particularly helpful, since it would hide the fact that the request had query parameters.
Now also applying the data collection options to the browser SDK, and the URL for request performance transactions.
Comment #13
mfbComment #14
mfbIf @daniel.pernold or anyone else wants to review this, please do
Comment #16
mfb