Skip to content
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

Add new 'redacted keys' config option to replace 'filters' #623

Merged
merged 7 commits into from Feb 8, 2021

Conversation

imjoehaines
Copy link
Member

Goal

This PR adds a 'redacted keys' option, to replace the existing 'filters' option. Filters is problematic because it works with a case-insensitive string contains, which can easily cause false positives

Redacted keys has different semantics but can still express everything that filters could (and more!). Redacted keys can contain both strings and regexes, where string comparisons are case-insensitive and exact — i.e. a matches a and A but not ab. Regexes can be used to emulate filters, e.g. /a/i will match a, A and ab

Redacted keys also attempts to match multi-byte strings by normalising strings and using multi-byte comparisons. This relies on the intl and mbstring extensions, so we fallback to strcasecmp if they are missing (we also try strcasecmp first as it's quicker than normalising + MB comparisons)

Changeset

  • New config option redactedKeys with getters & setters in Client & Configuration
  • Existing filters option is now marked as deprecated
  • Report::shouldFilter also uses redactedKeys to check if keys should be filtered/redacted
  • A new Utils::stringCaseEquals method has been added. This does a unicode-aware, case-insensitive string match
  • Tests

@@ -5,24 +5,24 @@ Bugsnag\Handler should increase the memory limit by the configured amount when a
$client = require __DIR__ . '/_prelude.php';
$client->setMemoryLimitIncrease(1024 * 1024 * 10);

ini_set('memory_limit', '2M');
Bugsnag\Handler::register($client);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test could run OOM before installing the handler, so I've moved this to before we reduce the memory limit and bumped the limit a bit

@@ -29,6 +29,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
coverage: none
extensions: intl, mbstring
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPUnit requires mbstring so we can't run the tests without it ☹️

@imjoehaines imjoehaines marked this pull request as ready for review February 5, 2021 11:26
@imjoehaines imjoehaines merged commit 4cc4bf9 into next Feb 8, 2021
@imjoehaines imjoehaines mentioned this pull request Feb 9, 2021
@imjoehaines imjoehaines deleted the redacted-keys branch August 24, 2021 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants