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

Adding Redacted Keys #217

Open
wants to merge 24 commits into
base: next
Choose a base branch
from
Open

Adding Redacted Keys #217

wants to merge 24 commits into from

Conversation

clr182
Copy link
Contributor

@clr182 clr182 commented Jul 1, 2024

Goal

Filtering config option is case sensitive and is no longer in line with our notifier spec; as such it should be deprecated in favour of redactedKeys.

Design

Added redactedKeys configuration option, which is case insensitive, as a replacement for the filters configuration option. Additionally due to conflictions the default filters parameters were changed.

Changeset

  • Added redactedKeys config option.

  • Made redactedKeys case insensitive.

  • Changed filters config default parameters from
    {"password", "secret", "Authorization", "Cookie"};
    to
    {"ipAddress", "logLevel"};

  • Set refactedKeys config default parameters to
    {"password", "secret", "Authorization", "Cookie"};

Testing

Added and updated tests for filtering mechanism and redactedKeys mechanism.

@clr182 clr182 marked this pull request as draft July 1, 2024 15:25
@clr182 clr182 self-assigned this Jul 4, 2024
@clr182 clr182 marked this pull request as ready for review July 4, 2024 16:39
@clr182 clr182 requested review from lemnik and tomlongridge and removed request for lemnik and tomlongridge July 4, 2024 16:39
@clr182 clr182 marked this pull request as draft July 4, 2024 20:36
@clr182 clr182 marked this pull request as ready for review July 12, 2024 19:11
@clr182 clr182 requested review from lemnik and tomlongridge July 12, 2024 20:40
@clr182 clr182 requested a review from tomlongridge July 18, 2024 12:44
bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java Outdated Show resolved Hide resolved
* @param redactedKeys a list of String keys to be redacted from metaData
*/
public void setRedactedKeys(String... redactedKeys) {
config.redactedKeys = redactedKeys;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately we're stuck with Configuration.filters being public, so we probably want to keep filters and redactedKeys synchronised otherwise things could get confusing if both are used for any reason. Suggest also setting config.filters here and removing the line from setFilters above?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the changes, I wonder if in fact this change is more risky as a non-breaking change than I thought as we'll need to compile the filter strings as regexes (L249). At very least we need a try-catch for a PatternSyntaxException, but it makes me a bit nervous even if 99.9% of users will have pretty straightforward key names with an occasional . which will still match a literal ..

@lemnik - thoughts here? The alternative is that we go back to running the two config options independently alongside each other (which I think was @clr182's first take).

Comment on lines 41 to 42
public String[] redactedKeys = new String[]{"password", "secret", "Authorization", "Cookie"};
public String[] filters = new String[]{"password", "secret", "Authorization", "Cookie"};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be appropriate to set this to the same instance rather than a different array with the same content. Just in case anyone is amending elements in the array.

Suggested change
public String[] redactedKeys = new String[]{"password", "secret", "Authorization", "Cookie"};
public String[] filters = new String[]{"password", "secret", "Authorization", "Cookie"};
public String[] redactedKeys = new String[]{"password", "secret", "Authorization", "Cookie"};
public String[] filters = redactedKeys;

Comment on lines 147 to 150
assertEquals(2, config.redactedKeys.length);
ArrayList<String> redactedKeys = new ArrayList<String>(Arrays.asList(config.redactedKeys));
assertTrue(redactedKeys.contains("password"));
assertTrue(redactedKeys.contains("credit_card_number"));
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be worth adding a few tests to verify the expected interplay between filters and redactedKeys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added functionality so that when both are called, setRedactedKeys creates a temp array to append the filters to the redactedKeys config option to avoid overwriting.

features/redactedKeys.feature Outdated Show resolved Hide resolved
@clr182 clr182 marked this pull request as draft July 23, 2024 14:24
@clr182 clr182 requested a review from tomlongridge July 25, 2024 09:53
@clr182 clr182 marked this pull request as ready for review July 25, 2024 09:53
bugsnag/src/main/java/com/bugsnag/Bugsnag.java Outdated Show resolved Hide resolved
* @param redactedKeys a list of String keys to be redacted from metaData
*/
public void setRedactedKeys(String... redactedKeys) {
config.redactedKeys = redactedKeys;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the changes, I wonder if in fact this change is more risky as a non-breaking change than I thought as we'll need to compile the filter strings as regexes (L249). At very least we need a try-catch for a PatternSyntaxException, but it makes me a bit nervous even if 99.9% of users will have pretty straightforward key names with an occasional . which will still match a literal ..

@lemnik - thoughts here? The alternative is that we go back to running the two config options independently alongside each other (which I think was @clr182's first take).

@clr182 clr182 requested a review from tomlongridge August 8, 2024 14:40
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.

2 participants