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

Redact request url #117

Merged
merged 6 commits into from
May 17, 2019
Merged

Redact request url #117

merged 6 commits into from
May 17, 2019

Conversation

tgwizard
Copy link
Contributor

@tgwizard tgwizard commented Apr 18, 2019

Goal

Currently, when the Bugsnag client extracts the URL from the request, it includes the full query parameters, without any filtering/redaction. This will leak any sensitive keys sent as query parameters, like access tokens.

This PR changes that so that we go through each query parameter and filter out sensitive ones (similar to how we do for request headers).

This PR also adds access_token as a default sensitive parameter, since it's very unlikely users want to include those in Bugsnag reports.

Changeset

Changed

extractRequestInfoFromReq

Tests

I've added tests for the function.

Discussion

Alternative Approaches

Outstanding Questions

One drawback of this change is that the URL query parameters sent to Bugsnag will no longer be in the order that the client sent them, but sorted alphabetically by key. This is because url.ParseQuery returns a (type-aliased) map[string][]string, and the corresponding Encode sorts on key.

We could attempt a custom implementation of the Encode function to sort according to the original order, but I'm not sure it's worth it.

Linked issues

Review

For the submitter, initial self-review:

  • Commented on code changes inline explain the reasoning behind the approach
  • Reviewed the test cases added for completeness and possible points for discussion
  • A changelog entry was added for the goal of this pull request
  • Check the scope of the changeset - is everything in the diff required for the pull request?
  • This pull request is ready for:
    • Initial review of the intended approach, not yet feature complete
    • Structural review of the classes, functions, and properties modified
    • Final review

For the pull request reviewer(s), this changeset has been reviewed for:

  • Consistency across platforms for structures or concepts added or modified
  • Consistency between the changeset and the goal stated above
  • Internal consistency with the rest of the library - is there any overlap between existing interfaces and any which have been added?
  • Usage friction - is the proposed change in usage cumbersome or complicated?
  • Performance and complexity - are there any cases of unexpected O(n^3) when iterating, recursing, flat mapping, etc?
  • Concurrency concerns - if components are accessed asynchronously, what issues will arise
  • Thoroughness of added tests and any missing edge cases
  • Idiomatic use of the language

@tgwizard tgwizard force-pushed the redact-request-url branch from 463ffdc to 935774f Compare April 23, 2019 07:22
@tgwizard tgwizard force-pushed the redact-request-url branch from 935774f to 7b8ef0c Compare April 23, 2019 07:32
@tgwizard
Copy link
Contributor Author

Please review :)

Copy link
Contributor

@kinbiko kinbiko left a comment

Choose a reason for hiding this comment

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

Hi @tgwizard,

Thanks for submitting the PR. I've discussed with the team and this seems like something we should support. The code looks mostly good, my comments are mainly stylistic. I think we can live with the URL looking different in the dashboard, but it would be good to limit this discrepancy as much as possible. See the inline comments for a suggested approach that hopefully won't require us to rewrite Encode.

var rawQuery string
parsedQuery, err := url.ParseQuery(req.URL.RawQuery)
if err != nil {
rawQuery = req.URL.RawQuery
Copy link
Contributor

Choose a reason for hiding this comment

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

Once the sanitizeURL func is extracted, we can return here, and avoid a level of indentation when doing the parameter filtering below (no need for the else).

request_extractor.go Outdated Show resolved Hide resolved
request_extractor.go Show resolved Hide resolved
request_extractor.go Outdated Show resolved Hide resolved
request_extractor_test.go Outdated Show resolved Hide resolved
request_extractor_test.go Outdated Show resolved Hide resolved
request_extractor_test.go Outdated Show resolved Hide resolved
request_extractor.go Outdated Show resolved Hide resolved
request_extractor.go Show resolved Hide resolved
request_extractor.go Outdated Show resolved Hide resolved
@tgwizard
Copy link
Contributor Author

Thanks for the review @kinbiko! I've pushed a commit addressing most of your comments, please have another look. I'd be happy to squash the commits at merge time.

@tgwizard
Copy link
Contributor Author

@kinbiko please review again :)

@kinbiko kinbiko self-requested a review April 30, 2019 16:37
Copy link
Contributor

@kinbiko kinbiko left a comment

Choose a reason for hiding this comment

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

Hi @tgwizard,

Thank you for your patience. I think this is pretty close to being done, the main remaining point is on achieving the consistency of [FILTERED].
Your efforts are much appreciated, and we'll try and get this in a new release shortly.

request_extractor.go Outdated Show resolved Hide resolved
request_extractor_test.go Outdated Show resolved Hide resolved
request_extractor.go Outdated Show resolved Hide resolved
@tgwizard
Copy link
Contributor Author

tgwizard commented May 7, 2019

I've addressed all but one of your comments, which I commented on why. Please have another look @kinbiko.

@tgwizard tgwizard force-pushed the redact-request-url branch from e3ceac5 to 58d5e56 Compare May 7, 2019 09:01
@tgwizard
Copy link
Contributor Author

tgwizard commented May 7, 2019

The tests fail for some seemingly unrelated reason - a timeout in the Martini tests.

@tgwizard
Copy link
Contributor Author

@kinbiko please have another look, it should now all be fixed.

@kinbiko
Copy link
Contributor

kinbiko commented May 13, 2019

Hi @tgwizard,

Sorry about the wait -- I was struggling to find the time to come back and re-review this. I've taken this branch for a spin now, and it looks really good; only one minor issue.

Unfortunately, not filtering empty URL params leads to a pretty confusing Request tab; The URL displays an empty value but the params extracted from the built-in Bugsnag HTTP middleware show up as "[FILTERED]".

image

I've had a chat with another of the maintainers here and we believe it's best to be consistent and use "[FILTERED]" even for empty fields.

That being said, we do see the benefit of being able to tell if such fields are absent. If this is something you need for your particular use case you may use an OnBeforeNotify callback to extract this information, so all is not lost 🙂.

Other than this, I believe this change is good to go. Thank you ever so much for your patience. I realise I've been making you jump through a lot of hoops.

You are free to address this if you so wish, otherwise I'll merge and address myself as soon as I find the time.

@tgwizard
Copy link
Contributor Author

No worries @kinbiko, I'm happy to make this right. The code is much better now than in my initial PR, which also makes me happy 😸 .

I've added a commit to also add [FILTERED] for empty values for sensitive query string parameters.

@tgwizard
Copy link
Contributor Author

@kinbiko bump 😺

@snmaynard
Copy link
Contributor

@tgwizard I believe @kinbiko is fixing up our CI issues on older Go versions and then the plan is for this to be merged. Should be done in the next day or so I think (but correct me if I'm wrong @kinbiko!)

@kinbiko
Copy link
Contributor

kinbiko commented May 17, 2019

Just as @snmaynard mentioned, we were having some CI issues that I needed to fix before this could go in. This is why your latest build failed (nothing to do with your changes), but the PR looks good now so it's going in our next release (most likely shipping Monday). 🚢

Thanks again for your work on this @tgwizard!

@kinbiko kinbiko merged commit 8cb12b2 into bugsnag:next May 17, 2019
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.

3 participants