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
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

## TBD

### Changed

- Renamed the configuration option `filters` to `redactedKeys`. `filters` is now marked as deprecated and will be removed in the next major release. [#217](https://github.com/bugsnag/bugsnag-java/pull/217)

### Bug Fixes

* Update `BugsnagImportSelector` to allow major versions that do not have a minor version.
fixes [issue #211](https://github.com/bugsnag/bugsnag-java/issues/211).
[#213](https://github.com/bugsnag/bugsnag-java/pull/213)

* Add a null check for `Severity` to the notify override method. [#214](https://github.com/bugsnag/bugsnag-java/pull/214)


## 3.7.1 (2023-10-25)

* Restore `BugsnagServletContainerInitializer` and `BugsnagServletRequestListener` to the `com.bugsnag.servlet` package.
Expand Down
20 changes: 19 additions & 1 deletion bugsnag/src/main/java/com/bugsnag/Bugsnag.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,32 @@ public void setEndpoint(String endpoint) {
* Use this when you want to ensure sensitive information, such as passwords
* or credit card information is stripped from metaData you send to Bugsnag.
* Any keys in metaData which contain these strings will be marked as
* [FILTERED] when send to Bugsnag.
* [REDACTED] when send to Bugsnag.
* @deprecated to be removed and replaced with setRedactedKeys
*
* @param filters a list of String keys to filter from metaData
*/
@Deprecated
public void setFilters(String... filters) {
config.filters = filters;
setRedactedKeys(filters);
}

/**
* Set which keys should be redacted when sending metaData to Bugsnag.
* Use this when you want to ensure sensitive information, such as passwords
* or credit card information is stripped from metaData you send to Bugsnag.
* Any keys in metaData which contain these strings will be marked as
* [REDACTED] when send to Bugsnag.
*
* @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).

}



/**
* Set which exception classes should be ignored (not sent) by Bugsnag.
*
Expand Down
42 changes: 34 additions & 8 deletions bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class BugsnagAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
/** Bugsnag error server endpoint. */
private String endpoint;

/** Property names that should be filtered out before sending to Bugsnag servers. */
private Set<String> filteredProperties = new HashSet<String>();
/** Property names that should be redacted out before sending to Bugsnag servers. */
private Set<String> redactedKeys = new HashSet<String>();

/** Exception classes to be ignored. */
private Set<String> ignoredClasses = new HashSet<String>();
Expand Down Expand Up @@ -254,8 +254,8 @@ private Bugsnag createBugsnag() {
bugsnag.setTimeout(timeout);
}

if (filteredProperties.size() > 0) {
bugsnag.setFilters(filteredProperties.toArray(new String[0]));
if (redactedKeys.size() > 0) {
bugsnag.setRedactedKeys(redactedKeys.toArray(new String[0]));
}

bugsnag.setIgnoreClasses(ignoredClasses.toArray(new String[0]));
Expand Down Expand Up @@ -375,23 +375,49 @@ public void setEndpoint(String endpoint) {

/**
* @see Bugsnag#setFilters(String...)
* @deprecated use #setRedactedKey(String) instead
*/
@Deprecated
public void setFilteredProperty(String filter) {
this.filteredProperties.add(filter);
this.redactedKeys.add(filter);

if (bugsnag != null) {
bugsnag.setFilters(this.filteredProperties.toArray(new String[0]));
bugsnag.setRedactedKeys(this.redactedKeys.toArray(new String[0]));
}
}

/**
* @see Bugsnag#setFilters(String...)
* @deprecated use #setRedactedKeys(String) instead
*/
@Deprecated
public void setFilteredProperties(String filters) {
this.filteredProperties.addAll(split(filters));
this.redactedKeys.addAll(split(filters));

if (bugsnag != null) {
bugsnag.setFilters(this.filteredProperties.toArray(new String[0]));
bugsnag.setRedactedKeys(this.redactedKeys.toArray(new String[0]));
}
}

/**
* @see Bugsnag#setRedactedKeys(String...)
*/
public void setRedactedKey(String redactedKey) {
this.redactedKeys.add(redactedKey);

if (bugsnag != null) {
bugsnag.setRedactedKeys(this.redactedKeys.toArray(new String[0]));
}
}

/**
* @see Bugsnag#setRedactedKeys(String...)
*/
public void setRedactedKeys(String redactedKeys) {
this.redactedKeys.addAll(split(redactedKeys));

if (bugsnag != null) {
bugsnag.setRedactedKeys(this.redactedKeys.toArray(new String[0]));
}
}

Expand Down
1 change: 1 addition & 0 deletions bugsnag/src/main/java/com/bugsnag/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Configuration {
public Delivery delivery = new AsyncHttpDelivery(SyncHttpDelivery.DEFAULT_NOTIFY_ENDPOINT);
public Delivery sessionDelivery =
new AsyncHttpDelivery(SyncHttpDelivery.DEFAULT_SESSION_ENDPOINT);
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;

public String[] ignoreClasses;
public String[] notifyReleaseStages = null;
Expand Down
4 changes: 2 additions & 2 deletions bugsnag/src/main/java/com/bugsnag/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.bugsnag.serialization.Expose;

import com.bugsnag.util.FilteredMap;
import com.bugsnag.util.RedactedKeysMap;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -126,7 +126,7 @@ public Map<String, String> getUser() {

@Expose
public Map<String, Object> getMetaData() {
return new FilteredMap(diagnostics.metaData, Arrays.asList(config.filters));
return new RedactedKeysMap(diagnostics.metaData, Arrays.asList(config.redactedKeys));
}

@Expose
Expand Down
122 changes: 0 additions & 122 deletions bugsnag/src/main/java/com/bugsnag/util/FilteredMap.java

This file was deleted.

Loading