-
-
Notifications
You must be signed in to change notification settings - Fork 475
feat(http): [Data Collection 13] Apply cookie collection policy #5811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/data-collection
Are you sure you want to change the base?
Changes from all commits
268920f
1987b1e
9da9baa
ccfe195
d7a900d
501c268
988579b
c4e29eb
b9eeeb5
71619ec
a81ffe7
6cdd40e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,6 +269,28 @@ constructor( | |
| private fun getHeader(key: String, headers: List<HttpHeader>): String? = | ||
| headers.firstOrNull { it.name.equals(key, true) }?.value | ||
|
|
||
| private fun getRequestCookies(headers: List<HttpHeader>): String? { | ||
| val cookies = getHeader("Cookie", headers) | ||
| return if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { | ||
| HttpUtils.filterCookies(cookies, scopes.options.dataCollectionResolver.cookies, null) | ||
| } else if (scopes.options.isSendDefaultPii) { | ||
| cookies | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| private fun getResponseCookies(headers: List<HttpHeader>): String? { | ||
| val cookies = getHeader("Set-Cookie", headers) | ||
| return if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { | ||
| HttpUtils.filterSetCookie(cookies, scopes.options.dataCollectionResolver.cookies) | ||
| } else if (scopes.options.isSendDefaultPii) { | ||
| cookies | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| private fun getRequestHeaders(headers: List<HttpHeader>): MutableMap<String, String>? { | ||
| if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { | ||
| val requestHeaders = mutableMapOf<String, String>() | ||
|
|
@@ -390,9 +412,7 @@ constructor( | |
| val sentryRequest = | ||
| Request().apply { | ||
| urlDetails.applyToRequest(this) | ||
| // Cookie is only sent if isSendDefaultPii is enabled | ||
| cookies = | ||
| if (scopes.options.isSendDefaultPii) getHeader("Cookie", request.headers) else null | ||
| cookies = getRequestCookies(request.headers) | ||
| method = request.method.name | ||
| headers = getRequestHeaders(request.headers) | ||
| apiTarget = "graphql" | ||
|
|
@@ -418,13 +438,7 @@ constructor( | |
|
|
||
| val sentryResponse = | ||
| Response().apply { | ||
| // Set-Cookie is only sent if isSendDefaultPii is enabled due to PII | ||
| cookies = | ||
| if (scopes.options.isSendDefaultPii) { | ||
| getHeader("Set-Cookie", response.headers) | ||
| } else { | ||
| null | ||
| } | ||
| cookies = getResponseCookies(response.headers) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There could be multiple |
||
| headers = getResponseHeaders(response.headers) | ||
| statusCode = response.statusCode | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,18 +36,16 @@ internal object SentryKtorClientUtils { | |
|
|
||
| val sentryRequest = | ||
| io.sentry.protocol.Request().apply { | ||
| // Cookie is only sent if isSendDefaultPii is enabled | ||
| urlDetails.applyToRequest(this) | ||
| cookies = if (scopes.options.isSendDefaultPii) request.headers["Cookie"] else null | ||
| cookies = getRequestCookies(scopes, request.headers["Cookie"]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There could be multiple
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created #5982 so we can change this (likely) in the next major. |
||
| method = request.method.value | ||
| headers = getRequestHeaders(scopes, request.headers) | ||
| bodySize = request.content.contentLength | ||
| } | ||
|
|
||
| val sentryResponse = | ||
| io.sentry.protocol.Response().apply { | ||
| // Set-Cookie is only sent if isSendDefaultPii is enabled due to PII | ||
| cookies = if (scopes.options.isSendDefaultPii) response.headers["Set-Cookie"] else null | ||
| cookies = getResponseCookies(scopes, response.headers["Set-Cookie"]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There could be multiple |
||
| headers = getResponseHeaders(scopes, response.headers) | ||
| statusCode = response.status.value | ||
| try { | ||
|
|
@@ -67,6 +65,28 @@ internal object SentryKtorClientUtils { | |
| scopes.captureEvent(event, hint) | ||
| } | ||
|
|
||
| private fun getRequestCookies(scopes: IScopes, cookies: String?): String? = | ||
| if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { | ||
| HttpUtils.filterCookies( | ||
| cookies, | ||
| scopes.options.dataCollectionResolver.cookies, | ||
| null, | ||
| ) | ||
| } else if (scopes.options.isSendDefaultPii) { | ||
| cookies | ||
| } else { | ||
| null | ||
| } | ||
|
|
||
| private fun getResponseCookies(scopes: IScopes, cookies: String?): String? = | ||
| if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { | ||
| HttpUtils.filterSetCookie(cookies, scopes.options.dataCollectionResolver.cookies) | ||
| } else if (scopes.options.isSendDefaultPii) { | ||
| cookies | ||
| } else { | ||
| null | ||
| } | ||
|
|
||
| private fun getRequestHeaders(scopes: IScopes, headers: Headers): MutableMap<String, String>? { | ||
| if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { | ||
| val requestHeaders = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be multiple
CookieandSet-Cookieheaders. here we are currently only ever processingoneof them and send them to sentry. Is that what we want or should we go through all of these?