Skip to content

Commit 99132ca

Browse files
committed
Don't send cookie and form scope data by default
1 parent 5b6e0bd commit 99132ca

3 files changed

Lines changed: 59 additions & 12 deletions

File tree

ModuleConfig.cfc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ component {
4949
"levelMax" : "ERROR",
5050
// Enable/disable error logging
5151
"enableExceptionLogging" : true,
52+
// Sentry recommends not sending cookie and form data by default
53+
"sendCookies" : false,
54+
"sendPostData" : false,
5255
// Data sanitization, scrub fields and headers, replaced with "[Filtered]" at runtime
5356
"scrubFields" : [],
5457
"scrubHeaders" : [],

models/SentryService.cfc

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ component accessors=true singleton {
8585
"levelMax" : "ERROR",
8686
// Enable/disable error logging
8787
"enableExceptionLogging" : true,
88+
// Whether to include client cookies when sending request information to Sentry
89+
"sendCookies" : false,
90+
// Whether to include POST data (e.g. FORM) when sending request information to Sentry
91+
"sendPostData" : false,
8892
// Data sanitization, scrub fields and headers, replaced with "[Filtered]" at runtime
8993
"scrubFields" : [
9094
"passwd",
@@ -709,21 +713,31 @@ component accessors=true singleton {
709713
// Request interface
710714
// https://develop.sentry.dev/sdk/event-payloads/request/
711715
arguments.captureStruct[ "request" ] = {
712-
"url" : arguments.path,
713-
"method" : arguments.cgiVars.request_method ?: "GET",
714-
"data" : !structIsEmpty( form ) ? sanitizeFields( form ) : sanitizeFields(
715-
isJSON( getHTTPRequestData().content ) ? deserializeJSON( getHTTPRequestData().content ) : {}
716-
),
716+
"url" : arguments.path,
717+
"method" : arguments.cgiVars.request_method ?: "GET",
717718
"query_string" : sanitizeQueryString( arguments.cgiVars.query_string ?: "" ),
718-
// Sentry requires all cookies be strings
719-
"cookies" : sanitizeFields(
719+
"env" : sanitizeEnv( arguments.cgiVars ),
720+
"headers" : sanitizeHeaders( httpRequestData.headers )
721+
};
722+
723+
if ( variables.settings.sendCookies ) {
724+
arguments.captureStruct[ "request" ][ "cookies" ] = sanitizeFields(
720725
cookie.map( function( k, v ){
721-
return toString( v );
726+
return toString( v ); // Sentry requires all cookies be strings
722727
} )
723-
),
724-
"env" : arguments.cgiVars,
725-
"headers" : sanitizeHeaders( httpRequestData.headers )
726-
};
728+
)
729+
}
730+
731+
if ( variables.settings.sendPostData ) {
732+
if ( !structIsEmpty( form ) ) {
733+
arguments.captureStruct[ "request" ][ "data" ] = sanitizeFields( form );
734+
} else {
735+
arguments.captureStruct[ "request" ][ "data" ] = sanitizeFields(
736+
isJSON( httpRequestData.content ) ? deserializeJSON( httpRequestData.content ) : {}
737+
)
738+
}
739+
}
740+
727741
// serialize data
728742
jsonCapture = serializeJSON( arguments.captureStruct );
729743

@@ -884,6 +898,11 @@ component accessors=true singleton {
884898
}
885899
}
886900
}
901+
902+
if ( !variables.settings.sendCookies && structKeyExists( arguments.headers, "Cookie" ) ) {
903+
arguments.headers.Cookie = "[Filtered]";
904+
}
905+
887906
// Sentry requires all headers be strings
888907
return arguments.headers.map( function( k, v ){
889908
return toString( v );
@@ -910,6 +929,25 @@ component accessors=true singleton {
910929
return arguments.data;
911930
}
912931

932+
/**
933+
* Sanitize env/CGI vars
934+
*
935+
* @data The data fields
936+
*/
937+
private any function sanitizeEnv( required any data ){
938+
if ( !isStruct( arguments.data ) ) {
939+
return arguments.data;
940+
}
941+
942+
// don't mutate CGI scope
943+
return arguments.data.map( function( k, v ){
944+
if ( !variables.settings.sendCookies && k == "http_cookie" ) {
945+
return "[Filtered]";
946+
}
947+
return v;
948+
} );
949+
}
950+
913951
/**
914952
* Sanitize the incoming query string
915953
*

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Version 2 of this module includes some potentially breaking changes in how the e
3434

3535
Additionally, Sentry has deprecated sending events to the `/api/{project_id}/store` endpoint in favor of a new `/api/{project_id}/envelope` endpoint (and a new structure for the body of the post requests). Again, if you self-host an older version of the Sentry service, sending events to the `store` endpoint might be your only option. There is a new module setting, `sentryEventEndpoint`, that defaults to `store`, but can be set to `envelope` to enable sending events to the modern endpoint.
3636

37+
In version 2, `cookie` and `form` scope data will not be sent with events by default. To enable sending this data, use the new `sendCookies` and `sendPostData` settings.
38+
3739
## CFML App Installation
3840

3941
If your app uses neither ColdBox nor LogBox, you can still instantiate the `SentryService` and use it directly so long as you prep it with the settings it needs.
@@ -142,6 +144,10 @@ settings = {
142144
enableExceptionLogging : true,
143145
// Send messages to Sentry in a thread
144146
async : true,
147+
// Whether to include client cookies when sending request information to Sentry
148+
sendCookies : false,
149+
// Whether to include POST data (e.g. FORM) when sending request information to Sentry
150+
sendPostData : false,
145151
// Don't sent URL or FORM field values of these names to Sentry
146152
scrubFields : [ 'passwd', 'password', 'password_confirmation', 'secret', 'confirm_password', 'secret_token', 'APIToken', 'x-api-token', 'fwreinit' ],
147153
// Don't sent HTTP header values of these names to Sentry

0 commit comments

Comments
 (0)