forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8365b87
commit b2703ab
Showing
26 changed files
with
303 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
class << self | ||
sig { params(_blk: T.proc.params(arg0: Sentry::Configuration).void).void } | ||
def init(&_blk); end | ||
|
||
sig { params(exception: Exception, options: T.untyped).void } | ||
def capture_exception(exception, **options); end | ||
end | ||
|
||
class Configuration | ||
sig { returns(T.nilable(::Logger)) } | ||
attr_accessor :logger | ||
|
||
sig { returns(T.nilable(String)) } | ||
attr_accessor :project_root | ||
|
||
sig { returns(T.nilable(::Regexp)) } | ||
attr_accessor :app_dirs_pattern | ||
|
||
sig { returns(T::Boolean) } | ||
attr_accessor :propagate_traces | ||
|
||
sig do | ||
params( | ||
value: T.proc | ||
.params( | ||
event: ::Sentry::Event, | ||
hint: T::Hash[Symbol, T.untyped] | ||
) | ||
.returns(::Sentry::Event) | ||
).void | ||
end | ||
def before_send=(value); end | ||
end | ||
|
||
class Event; end | ||
|
||
class ErrorEvent < ::Sentry::Event | ||
sig { returns(::Sentry::ExceptionInterface) } | ||
attr_reader :exception | ||
end | ||
|
||
class ExceptionInterface | ||
sig { returns(T::Array[::Sentry::SingleExceptionInterface]) } | ||
attr_reader :values | ||
end | ||
|
||
class SingleExceptionInterface | ||
sig { returns(String) } | ||
attr_accessor :value | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,21 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
require "raven" | ||
require "sorbet-runtime" | ||
require "dependabot/sentry/exception_sanitizer_processor" | ||
require "dependabot/sentry/sentry_context_processor" | ||
|
||
# ExceptionSanitizer filters potential secrets/PII from exception payloads | ||
class ExceptionSanitizer < Raven::Processor | ||
extend T::Sig | ||
module Dependabot | ||
module Sentry | ||
extend T::Sig | ||
|
||
REPO = %r{[\w.\-]+/([\w.\-]+)} | ||
PATTERNS = T.let( | ||
{ | ||
auth_token: /(?:authorization|bearer):? (\w+)/i, | ||
repo: %r{https://api\.github\.com/repos/#{REPO}|https://github\.com/#{REPO}|git@github\.com:#{REPO}} | ||
}.freeze, | ||
T::Hash[Symbol, Regexp] | ||
) | ||
|
||
sig do | ||
params(data: T::Hash[Symbol, T.nilable(T::Hash[Symbol, T::Array[T::Hash[Symbol, String]]])]) | ||
.returns(T::Hash[Symbol, T.untyped]) | ||
end | ||
def process(data) | ||
return data unless data.dig(:exception, :values) | ||
|
||
T.must(data[:exception])[:values] = T.must(data.dig(:exception, :values)).map do |e| | ||
PATTERNS.each do |key, regex| | ||
e[:value] = T.must(e[:value]).gsub(regex) do |match| | ||
match.sub(/#{T.must(Regexp.last_match).captures.compact.first}\z/, "[FILTERED_#{key.to_s.upcase}]") | ||
end | ||
# The default processor chain. | ||
# This chain is applied in the order of the array. | ||
sig { params(event: ::Sentry::Event, hint: T::Hash[Symbol, T.untyped]).returns(::Sentry::Event) } | ||
def self.process_chain(event, hint) | ||
[ExceptionSanitizer, SentryContext].each(&:new).reduce(event) do |acc, processor| | ||
processor.new.process(acc, hint) | ||
end | ||
e | ||
end | ||
|
||
data | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
updater/lib/dependabot/sentry/exception_sanitizer_processor.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
require "sentry-ruby" | ||
require "sorbet-runtime" | ||
|
||
require "dependabot/sentry/processor" | ||
|
||
# ExceptionSanitizer filters potential secrets/PII from exception payloads | ||
class ExceptionSanitizer < ::Dependabot::Sentry::Processor | ||
extend T::Sig | ||
|
||
REPO = %r{[\w.\-]+/([\w.\-]+)} | ||
PATTERNS = T.let( | ||
{ | ||
auth_token: /(?:authorization|bearer):? (\w+)/i, | ||
repo: %r{https://api\.github\.com/repos/#{REPO}|https://github\.com/#{REPO}|git@github\.com:#{REPO}} | ||
}.freeze, | ||
T::Hash[Symbol, Regexp] | ||
) | ||
|
||
sig do | ||
override | ||
.params( | ||
event: ::Sentry::Event, | ||
_hint: T::Hash[Symbol, T.untyped] | ||
) | ||
.returns(::Sentry::Event) | ||
end | ||
def process(event, _hint) | ||
return event unless event.is_a?(::Sentry::ErrorEvent) | ||
|
||
event.exception.values.each do |e| | ||
PATTERNS.each do |key, regex| | ||
e.value = e.value.gsub(regex) do |match| | ||
match.sub(/#{T.must(Regexp.last_match).captures.compact.first}\z/, "[FILTERED_#{key.to_s.upcase}]") | ||
end | ||
end | ||
end | ||
|
||
event | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
require "sorbet-runtime" | ||
|
||
module Dependabot | ||
module Sentry | ||
class Processor | ||
extend T::Sig | ||
extend T::Helpers | ||
|
||
abstract! | ||
|
||
# Process an event before it is sent to Sentry | ||
sig do | ||
abstract | ||
.params( | ||
event: ::Sentry::Event, | ||
hint: T::Hash[Symbol, T.untyped] | ||
) | ||
.returns(::Sentry::Event) | ||
end | ||
def process(event, hint); end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require "sentry-ruby" | ||
require "sorbet-runtime" | ||
|
||
require "dependabot/sentry/processor" | ||
|
||
class SentryContext < ::Dependabot::Sentry::Processor | ||
sig do | ||
override | ||
.params( | ||
event: ::Sentry::Event, | ||
hint: T::Hash[Symbol, T.untyped] | ||
) | ||
.returns(::Sentry::Event) | ||
end | ||
def process(event, hint) | ||
if (exception = hint[:exception]) && exception.respond_to?(:sentry_context) | ||
exception.sentry_context&.each do |key, value| | ||
event.send("#{key}=", value) | ||
end | ||
end | ||
event | ||
end | ||
end |
Oops, something went wrong.