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

Guard against exceptions in to_s when cleaning objects #591

Merged
merged 4 commits into from
May 5, 2020

Conversation

imjoehaines
Copy link
Contributor

@imjoehaines imjoehaines commented May 1, 2020

Goal

When sending notifications we run through a "cleaning" stage which does things like filter out any keys that we shouldn't send in the error report (e.g. passwords). This calls to_s in a couple of different places, which can cause issues as objects are free to implement any logic and can therefore throw exceptions or infinitely recurse, which means we end up crashing while trying to cleanup the object

In this PR we'll now recover from exceptions and stack overflows by replacing the values with one of our existing replacement strings:

  1. [RECURSION] if we get a SystemStackError when stringifying a plain object
  2. [FILTERED] if we get an exception when attempting to filter keys in a hash map — if an exception happens we can't tell if we should filter the key, so we have to assume we need to

This means the error report will have less information that intended, but this should be rare and if it does happen then the alternative is no report at all

Changeset

Changed

  • Rescue SystemStackError as well as other exceptions when calling to_s on an object
  • Rescue StandardError and SystemStackError when calling to_s on a key when filtering a hash map

Tests

Tests have been added for:

  • hash keys that throw during to_s
  • hash values that throw during to_s
  • custom objects that infinitely recurse during to_s

Discussion

Alternative Approaches

Outstanding Questions

Linked issues

Related to #577

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

We can't recover from stack overflows so there's not much we can do
here other than skip these tests
@imjoehaines imjoehaines marked this pull request as ready for review May 1, 2020 14:55
lib/bugsnag/cleaner.rb Outdated Show resolved Hide resolved
@imjoehaines imjoehaines merged commit 9398a1b into next May 5, 2020
@imjoehaines imjoehaines deleted the guard-against-exceptions-in-to-s branch May 5, 2020 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.

2 participants