File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616- Don't start ` Sentry::SendEventJob ` 's transaction [ #1547 ] ( https://github.com/getsentry/sentry-ruby/pull/1547 )
1717 - Fixes [ #1539 ] ( https://github.com/getsentry/sentry-ruby/issues/1539 )
1818- Don't record breadcrumbs in disabled environments [ #1549 ] ( https://github.com/getsentry/sentry-ruby/pull/1549 )
19+ - Scrub header values with invalid encoding [ #1552 ] ( https://github.com/getsentry/sentry-ruby/pull/1552 )
20+ - Fixes [ #1551 ] ( https://github.com/getsentry/sentry-ruby/issues/1551 )
1921
2022## 4.6.5
2123
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ def read_data_from(request)
5757 request . POST
5858 elsif request . body # JSON requests, etc
5959 data = request . body . read ( MAX_BODY_LIMIT )
60- data = data . force_encoding ( Encoding :: UTF_8 ) if data . respond_to? ( :force_encoding )
60+ data = encode_to_utf_8 ( data . to_s )
6161 request . body . rewind
6262 data
6363 end
@@ -76,7 +76,8 @@ def filter_and_format_headers(env)
7676 # Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
7777 key = key . sub ( /^HTTP_/ , "" )
7878 key = key . split ( '_' ) . map ( &:capitalize ) . join ( '-' )
79- memo [ key ] = value . to_s
79+
80+ memo [ key ] = encode_to_utf_8 ( value . to_s )
8081 rescue StandardError => e
8182 # Rails adds objects to the Rack env that can sometimes raise exceptions
8283 # when `to_s` is called.
@@ -87,6 +88,18 @@ def filter_and_format_headers(env)
8788 end
8889 end
8990
91+ def encode_to_utf_8 ( value )
92+ if value . encoding != Encoding ::UTF_8 && value . respond_to? ( :force_encoding )
93+ value = value . dup . force_encoding ( Encoding ::UTF_8 )
94+ end
95+
96+ if !value . valid_encoding?
97+ value = value . scrub
98+ end
99+
100+ value
101+ end
102+
90103 def is_skippable_header? ( key )
91104 key . upcase != key || # lower-case envs aren't real http headers
92105 key == "HTTP_COOKIE" || # Cookies don't go here, they go somewhere else
Original file line number Diff line number Diff line change 5959 end
6060 end
6161
62+ context 'with special characters' do
63+ let ( :additional_headers ) { { "HTTP_FOO" => "Tekirda\xC4 " } }
64+
65+ it "doesn't cause any issue" do
66+ interface = described_class . build ( env : env )
67+ json = JSON . generate ( interface . to_hash )
68+
69+ expect ( JSON . parse ( json ) [ "headers" ] ) . to eq ( { "Content-Length" => "0" , "Foo" => "Tekirda�" } )
70+ end
71+ end
72+
6273 context 'with additional env variables' do
6374 let ( :mock ) { double }
6475 let ( :env ) { { "some.variable" => mock } }
You can’t perform that action at this time.
0 commit comments