Privacy and network traffic
Looking for the previous SDK? See the 6.x network privacy page.
Bugsee records the application's network activity: for each request, its URL, method, headers, status and, within limits, the request and response bodies. To keep personal data out of these records, Bugsee redacts well-known sensitive values on its own, and lets you install a filter that sees, changes or drops every event.
Disabling network capture
Set BugseeOptionCaptureNetwork (BugseeOptions.monitorNetwork) to NO to record no network
traffic, or BugseeOptionCaptureWebSocket (BugseeOptions.monitorWebSocket) to NO to leave
out WebSocket traffic only. See Configuration.
Built-in redaction
With BugseeOptionCaptureNetworkUseDefaultSanitizer (BugseeOptions.sanitizeNetworkData) on,
which is the default, every captured event is redacted before it is recorded. The value of each
sensitive key below is replaced with <redacted>:
- URL query parameters, in the URL and in the URL it was redirected from:
password,passwd,pass,secret,client_secret,token,app_token,access_token,refresh_token,id_token,auth_token,api_key,apikey,authorization,credit_card,creditcard,card_number,cardnumber,cvv,cvc,cvv2,ssn,social_security,pin,private_key,privatekey. - JSON bodies: the same keys, up to 64 levels of nesting. A body is parsed as JSON when its
Content-Typecontainsjson, or when the event has noContent-Type. Other bodies are left as they are. - HTTP headers:
Authorization,Proxy-Authorization,Cookie,Set-Cookie,X-Api-Key,X-Auth-Token,X-Csrf-Token,X-Forwarded-For,X-Real-Ip.
Keys and header names are matched without regard to case.
The built-in redaction runs only while no network filter is set. As soon as you install one —
with setNetworkEventFilter: or the delegate method — your filter alone decides what is
recorded. To keep the built-in redaction, run defaultNetworkSanitizer in your filter, as shown
below.
Network filters
A filter receives every network event before it is recorded, as a BugseeNetworkEvent. Change
it and pass it to the decision block, or pass nil to drop the event.
- Objective-C
- Swift
[Bugsee setNetworkEventFilter:^(BugseeNetworkEvent *event,
BugseeNetworkFilterDecisionBlock decision) {
// Keep the built-in redaction
[Bugsee.defaultNetworkSanitizer sanitize:event];
// Drop the traffic of an internal host altogether
if ([event.url containsString:@"://telemetry.example.com"]) {
decision(nil);
return;
}
// Your own redaction
NSMutableDictionary *headers = [event.headers mutableCopy];
if (headers[@"X-Session-Id"]) {
headers[@"X-Session-Id"] = @"<redacted>";
event.headers = headers;
}
decision(event);
}];
// Remove the filter
[Bugsee setNetworkEventFilter:nil];
Bugsee.setNetworkEventFilter { event, decision in
// Keep the built-in redaction
Bugsee.defaultNetworkSanitizer.sanitize(event)
// Drop the traffic of an internal host altogether
if event.url?.contains("://telemetry.example.com") == true {
decision(nil)
return
}
// Your own redaction
if var headers = event.headers, headers["X-Session-Id"] != nil {
headers["X-Session-Id"] = "<redacted>"
event.headers = headers
}
decision(event)
}
// Remove the filter
Bugsee.setNetworkEventFilter(nil)
The same filter can be a BugseeDelegate method instead:
- Objective-C
- Swift
- (void)bugseeFilterNetworkEvent:(BugseeNetworkEvent *)event
completionHandler:(BugseeNetworkFilterDecisionBlock)decisionBlock {
[Bugsee.defaultNetworkSanitizer sanitize:event];
// ...your own redaction...
decisionBlock(event);
}
// ...somewhere within the class
[Bugsee sharedInstance].delegate = self;
class BugseeHandler: NSObject, BugseeDelegate {
func bugsee(filterNetworkEvent event: BugseeNetworkEvent,
completionHandler decisionBlock: @escaping BugseeNetworkFilterDecisionBlock) {
Bugsee.defaultNetworkSanitizer.sanitize(event)
// ...your own redaction...
decisionBlock(event)
}
}
// ...somewhere in your setup code
Bugsee.sharedInstance()?.delegate = bugseeHandler
- If both are set, the block filter is used and the delegate method is not called.
- Call the decision block once, within 10 seconds. Past that the event is dropped, and a later call is ignored. The filter may finish on any thread.
defaultNetworkSanitizerchanges the event in place and returns once it is done, parsing a JSON body on the calling thread. It is safe to use from any thread, and works before launch and after stop.- Events your code records with
addNetworkEvent:are recorded as they are, without the filter and without the built-in redaction. Record them withaddNetworkEvent:requiresFiltering:andYESto run them through your filter, or through the built-in redaction when no filter is set. See Network events.
Network events
The filter is called several times for one request: usually once for the request
(BugseeNetworkEventBegin) and once when it ends (BugseeNetworkEventComplete, or
BugseeNetworkEventCancel / BugseeNetworkEventError). WebSocket events carry the
BugseeWebSocketEvent* types.
| Property | Type | Notes |
|---|---|---|
bugseeNetworkEventType | NSString | The stage, one of the constants above. Read it to tell the events apart. |
method | NSString | The HTTP method: GET, POST… |
responseCode | NSInteger | The HTTP status; 0 for the request event. |
url | NSString | The request URL. Change it to redact. |
redirectedFromURL | NSString | The URL the request was redirected from, if any. |
headers | NSDictionary | The request or response headers. Assign a new dictionary to change them. |
body | NSData | The raw request or response body, where it was captured. |
noBodyReason | NSString | Why there is no body: BugseeNetworkBodySizeTooLarge, BugseeNetworkBodyUnsupportedContentType, BugseeNetworkBodyNoContentType or BugseeNetworkBodyCantReadData. |
error | NSDictionary | The error of a failed request. |
Limiting bodies
Two options decide which bodies are kept. Both apply after your filter: the filter sees the body as it was captured.
| Option | Default | Effect |
|---|---|---|
BugseeOptionCaptureNetworkBodySizeLimit (maxNetworkBodySize) | 20480 | Largest body kept, in bytes. A larger body is left out whole, not cut. 0 keeps no bodies. |
BugseeOptionCaptureNetworkBodyWithoutType | NO | Whether to keep a body that has no Content-Type header. A filter that removes Content-Type therefore also removes the body. WebSocket frames are kept either way. |
Related
- Breadcrumbs privacy: network filters do not reach the HTTP breadcrumbs. The built-in query parameter redaction does.
- HTTP errors: with a network filter set, the URL in an HTTP-error report also loses its user info, and path segments that look like identifiers are replaced with placeholders.