How specify redacted keys as regular expressions for Bugsnag in objective-c

102 views Asked by At

I am trying to configure bugsnag in my react-native app and I am currently stuck with specifying redacted keys. The following guide mentions that I can use regular expressions:

https://docs.bugsnag.com/platforms/ios/configuration-options/#redactedkeys

But the example there only specified strings:

BugsnagConfiguration *config = [BugsnagConfiguration loadConfig];
config.redactedKeys = [NSSet setWithArray:@[@"password", @"credit_card_number"]];
[Bugsnag startWithConfiguration:config];

However, I have no knowledge of objective-c. I have the following two regular expressions that I would like to use:

[/\w*password\w*/i, /\w*sessiontoken\w*/i]

How can I add them to bugsnag's configuration?

1

There are 1 answers

0
sheriff_paul On

Here is how I have done it:

BugsnagConfiguration *config = [BugsnagConfiguration loadConfig];

NSRegularExpressionOptions opts = NSRegularExpressionCaseInsensitive;
NSRegularExpression *tokenRegExp = [NSRegularExpression regularExpressionWithPattern:@"\w*sessiontoken\w*" options: opts error:nil];
NSRegularExpression *passwordRegExp = [NSRegularExpression regularExpressionWithPattern:@"\w*password\w*" options: opts error:nil];

config.redactedKeys = [NSSet setWithArray:@[tokenRegExp, passwordRegExp]];
[Bugsnag startWithConfiguration:config];