Git Product home page Git Product logo

Comments (3)

kyrylo avatar kyrylo commented on August 15, 2024

Hi, @micred! Thanks for opening this issue.

I expected to have the passwords filtered in any object,

Where does this expectation come from? Do other error tracking tools do that?

I know that the user should cast the data to hash before calling Airbrake.notify

From what I remember, I think our docs don't make this clear. But the behavior you demonstrated serves as proof of your statement. I think we should make this clearer in the docs as well.

from airbrake-ruby.

micred avatar micred commented on August 15, 2024

Where does this expectation come from? Do other error tracking tools do?

This expectation comes from the README:

blocklist_keys - Specifies which keys in the payload (parameters, session data, environment data, etc) should be filtered.

Ok, no worries if you don't want to merge the PR, makes sense.

from airbrake-ruby.

micred avatar micred commented on August 15, 2024

I leave here a filter for Rails users that filter pretty much everything.

You can specify this filter in your config/initializers/airbrake.rb.

Airbrake.add_filter do |notice|
  unless notice.ignored
    # Sanitize and explicitly cast any notification parameter to a hash.
    # Airbrake otherwise doesn't blocklist parameters in a non-hash (i.e. ApplicationRecord, ActiveRecord::Relation,
    # ActionController::Parameters, OpenStruct...).
    notice[:params].deep_transform_values! do |object|
      # Convert an ApplicationRecord object into its hash.
      object = object.attributes if object.is_a? ApplicationRecord
      # Convert an ApplicationRecord object into an array of hashes.
      object = object.to_a.map(&:attributes) if object.is_a? ActiveRecord::Relation
      # Sets the ActionController::Parameters to true and avoids ActionController::UnfilteredParameters when
      # converted to hash.
      object = object.permit! if object.is_a? ActionController::Parameters

      # rubocop:disable Lint/RescueException
      # Either way, try to cast it to a hash when the object is not a Hash but responds to a casting method.
      object = begin
                 if !object.is_a?(Array) && object.respond_to?(:to_h)
                   object.to_h
                 elsif object.respond_to? :to_hash
                   object.to_hash
                 else
                   object
                 end
               rescue Exception => e
                 # If the cast fails for any reason, be conservative and hide everything, but say it
                 "[The cast to hash of an object of type #{object.class} failed"\
                 "with an exception of type #{e.class}: #{e.message}]"
               end
      # rubocop:enable Lint/RescueException

      object
    end
  end
end

from airbrake-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.