lib/bugsnag/cleaner.rb in bugsnag-6.23.0 vs lib/bugsnag/cleaner.rb in bugsnag-6.24.0
- old
+ new
@@ -23,11 +23,11 @@
##
# @param url [String]
# @return [String]
def clean_url(url)
- return url if @configuration.meta_data_filters.empty?
+ return url if @configuration.meta_data_filters.empty? && @configuration.redacted_keys.empty?
uri = URI(url)
return url unless uri.query
query_params = uri.query.split('&').map { |pair| pair.split('=') }
@@ -41,10 +41,37 @@
uri.query = query_params.join('&')
uri.to_s
end
+ ##
+ # @param key [String, #to_s]
+ # @return [Boolean]
+ def filters_match?(key)
+ str = key.to_s
+
+ matched = @configuration.meta_data_filters.any? do |filter|
+ case filter
+ when Regexp
+ str.match(filter)
+ else
+ str.include?(filter.to_s)
+ end
+ end
+
+ return true if matched
+
+ @configuration.redacted_keys.any? do |redaction_pattern|
+ case redaction_pattern
+ when Regexp
+ str.match(redaction_pattern)
+ when String
+ str.downcase == redaction_pattern.downcase
+ end
+ end
+ end
+
private
##
# This method calculates whether we need to filter deeply or not; i.e. whether
# we should match both with and without 'request.params'
@@ -52,13 +79,15 @@
# This is cached on the instance variable '@deep_filters' for performance
# reasons
#
# @return [Boolean]
def deep_filters?
- @configuration.meta_data_filters.any? do |filter|
+ is_deep_filter = proc do |filter|
filter.is_a?(Regexp) && filter.to_s.include?("\\.".freeze)
end
+
+ @configuration.meta_data_filters.any?(&is_deep_filter) || @configuration.redacted_keys.any?(&is_deep_filter)
end
def clean_string(str)
if defined?(str.encoding) && defined?(Encoding::UTF_8)
if str.encoding == Encoding::UTF_8
@@ -133,25 +162,9 @@
end
end
seen[obj] = value if protection
value
- end
-
- ##
- # @param key [String, #to_s]
- # @return [Boolean]
- def filters_match?(key)
- str = key.to_s
-
- @configuration.meta_data_filters.any? do |filter|
- case filter
- when Regexp
- str.match(filter)
- else
- str.include?(filter.to_s)
- end
- end
end
##
# If someone has a Rails filter like /^stuff\.secret/, it won't match
# "request.params.stuff.secret", so we try it both with and without the