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

[SVCS-334] Sentry captures dataverse API tokens on certain error types #313

Closed
wants to merge 4 commits into from
Closed

Conversation

TomBaxter
Copy link
Member

@TomBaxter TomBaxter commented Dec 27, 2017

This PR includes merge of #297 plus refactor of sub-classed raven processor.

TODO

  • Move self.FIELDS.union to WBSanitizer init

Ticket

SVCS-334

Purpose

Sanitize and censor tokens we get back from Dataverse that show up in local variables

Changes

Added a sanitizer based that inherits from the default raven one. It has increased functionality to parse through dictionaries, look for dataverse keys, and a larger scope of variable names to sanitize (key, token)

NOTE: sanitize.py and test_sanitize.py's location in waterbutler are pretty variable. I put them in server just because that was the easiest place at the time. if they should live somewhere else, that is an easy change, and something that might need to be considered.

Side effects

Some sentry things that we don't want to sanitize may end up being sanitized.

QA Notes

To test, you need to trigger an error that will log a Dataverse API token in a local variable or request some how.
An easy way to do this is if locally testing, upgrade your furl to 1.0.1 in Waterbutler with Dataverse attached to your project. You will also need to add a personal sentry account to your Waterbutler (through your raven.config file, or by manually putting it in your settings).

One thing to note: If an API key shows up in the actual error message, this is currently not censored (not sure best way to go about this, but the only time I ever encountered this was with the error :Bad API token.. so the token is not valid anymore anyway.

To trigger the above "Bad API token" functionality, attach a dataverse account. Then on dataverse, go refresh your token and refresh the page. This error will trigger until the OSF has to revalidate (Or something like that. This only happened to me once or twice).

There are other manual ways to test locally, such as raising errors in odd places with variables named things like 'key' or having a variable value that looks like a dataverse token etc.

@coveralls
Copy link

coveralls commented Dec 27, 2017

Coverage Status

Coverage increased (+0.03%) to 89.942% when pulling 66bb8a0 on TomBaxter:feature/SVCS-334 into 1b60f40 on CenterForOpenScience:develop.

Copy link
Contributor

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

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

LGTM except one question on where to update .FIELDS. Move to PCR or send back for additional development after this.

"""Subclass the sanitize function of the `SanitizePasswordsProcessor'."""

# As of raven version 6.4 this attribute name has been changed from FIELDS to KEYS.
# Will need to be updated when we upgrade.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


# As of raven version 6.4 this attribute name has been changed from FIELDS to KEYS.
# Will need to be updated when we upgrade.
self.FIELDS = self.FIELDS.union(['key', 'token', 'refresh_token'])
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for using .union on frozenset. I had thought this doesn't work but then I learned that .union on frozenset updates the set and returns a frozenset.

Is there a specific reason why we don't do this in __init__()? The side-effect of doing it insanitize() is that the .union is called every time the function is called. (Note that we have recursion here).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, no, no good reason. I will move when ticket next goes to additional development

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Back to Add'l Dev and you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Completed.

@@ -44,7 +44,13 @@ def make_app(debug):
[(r'/status', handlers.StatusHandler)],
debug=debug,
)
app.sentry_client = AsyncSentryClient(settings.SENTRY_DSN, release=__version__)

app.sentry_client = AsyncSentryClient(
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, I fixed merge conflicts when updating the PR directly on GitHub.

@coveralls
Copy link

coveralls commented Jan 3, 2018

Coverage Status

Coverage increased (+0.03%) to 89.9% when pulling 43c1f8c on TomBaxter:feature/SVCS-334 into cae41fc on CenterForOpenScience:develop.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 89.91% when pulling 55b871e on TomBaxter:feature/SVCS-334 into f17d276 on CenterForOpenScience:develop.

Copy link
Contributor

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

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

LGTM. Move to PCR! 🎆 🎆

@@ -44,7 +44,8 @@ def make_app(debug):
[(r'/status', handlers.StatusHandler)],
debug=debug,
)
app.sentry_client = AsyncSentryClient(settings.SENTRY_DSN, release=__version__)
app.sentry_client = AsyncSentryClient(settings.SENTRY_DSN, release=__version__,
Copy link
Contributor

Choose a reason for hiding this comment

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

@felliott If you prefer, you can update the style during merge. Thanks.

@NyanHelsing
Copy link
Contributor

#331

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.

6 participants