From 53a8b08cc61a2fe1e767714c88afcf9fb0a8822a Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 20 Sep 2021 22:28:51 +0800 Subject: [PATCH 1/2] Hub#capture_message should check the argument's type as well --- sentry-ruby/lib/sentry/hub.rb | 10 ++++++---- sentry-ruby/spec/sentry/hub_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sentry-ruby/lib/sentry/hub.rb b/sentry-ruby/lib/sentry/hub.rb index 19500b07e..805d7a3e8 100644 --- a/sentry-ruby/lib/sentry/hub.rb +++ b/sentry-ruby/lib/sentry/hub.rb @@ -90,10 +90,10 @@ def start_transaction(transaction: nil, custom_sampling_context: {}, **options) end def capture_exception(exception, **options, &block) - return unless current_client - check_argument_type!(exception, ::Exception) + return unless current_client + options[:hint] ||= {} options[:hint][:exception] = exception event = current_client.event_from_exception(exception, options[:hint]) @@ -104,6 +104,8 @@ def capture_exception(exception, **options, &block) end def capture_message(message, **options, &block) + check_argument_type!(message, ::String) + return unless current_client options[:hint] ||= {} @@ -114,10 +116,10 @@ def capture_message(message, **options, &block) end def capture_event(event, **options, &block) - return unless current_client - check_argument_type!(event, Sentry::Event) + return unless current_client + hint = options.delete(:hint) || {} scope = current_scope.dup diff --git a/sentry-ruby/spec/sentry/hub_spec.rb b/sentry-ruby/spec/sentry/hub_spec.rb index 554c60f85..d1ae8117b 100644 --- a/sentry-ruby/spec/sentry/hub_spec.rb +++ b/sentry-ruby/spec/sentry/hub_spec.rb @@ -149,6 +149,12 @@ expect(event_hash.dig(:threads, :values, 0, :stacktrace, :frames, 0, :function)).to eq("foo") end + it "raises error when passing a non-string object" do + expect do + subject.capture_message(1) + end.to raise_error(ArgumentError, 'expect the argument to be a String, got Integer (1)') + end + it "assigns default backtrace with caller" do event = subject.capture_message(message) event_hash = event.to_hash From cd74404690b754e5350c6937549b4f2c17aefd4d Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 20 Sep 2021 22:33:30 +0800 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0a56ca95..f76538bb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -## Unreleased +## 4.7.3 - Avoid leaking tracing timestamp to breadcrumbs [#1575](https://github.com/getsentry/sentry-ruby/pull/1575) - Avoid injecting tracing timestamp to all ActiveSupport instrument events [#1576](https://github.com/getsentry/sentry-ruby/pull/1576) + - Fixes [#1573](https://github.com/getsentry/sentry-ruby/issues/1574) +- `Hub#capture_message` should check its argument's type [#1577](https://github.com/getsentry/sentry-ruby/pull/1577) - Fixes [#1574](https://github.com/getsentry/sentry-ruby/issues/1574) ## 4.7.2