Skip to content

Commit 54acb0d

Browse files
authored
Release v6.27.1
2 parents cf63309 + b19ea1a commit 54acb0d

24 files changed

+171
-72
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
## v6.27.1 (18 June 2024)
5+
6+
### Fixes
7+
8+
* Only read Rack request body if it's rewindable
9+
| [#829](https://github.com/bugsnag/bugsnag-ruby/pull/829)
10+
* Fix circular require warning
11+
| [#828](https://github.com/bugsnag/bugsnag-ruby/pull/828)
12+
413
## v6.27.0 (23 May 2024)
514

615
### Enhancements

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.27.0
1+
6.27.1

features/fixtures/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ services:
8888
- BUGSNAG_API_KEY
8989
- BUGSNAG_ENDPOINT
9090
- BUGSNAG_METADATA_FILTERS
91+
- BUGSNAG_RACK_NO_REWIND
9192
restart: "no"
9293
ports:
9394
- target: 3000

features/fixtures/rack/app/Gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ gem 'webrick' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('3.0.0')
66

77
# Some functionality provided by Rack was moved to the 'rackup' gem in Rack v3
88
# Specifically the test app uses Rack::Server, which is now Rackup::Server
9-
if ENV['RACK_VERSION'] == '3'
10-
gem 'rackup', '~> 0.2.3'
11-
end
9+
gem 'rackup' if ENV['RACK_VERSION'] >= '3'

features/fixtures/rack/app/app.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,17 @@ def call(env)
7171
end
7272
end
7373

74+
app = Bugsnag::Rack.new(BugsnagTests.new)
75+
7476
Server =
7577
if defined?(Rack::Server)
7678
Rack::Server
7779
else
7880
require 'rackup'
81+
82+
app = Rack::RewindableInput::Middleware.new(app) unless ENV["BUGSNAG_RACK_NO_REWIND"] == "true"
83+
7984
Rackup::Server
8085
end
8186

82-
Server.start(app: Bugsnag::Rack.new(BugsnagTests.new), Host: '0.0.0.0', Port: 3000)
87+
Server.start(app: app, Host: '0.0.0.0', Port: 3000)

features/rack.feature

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Scenario: A POST request with form data sends a report with the parsed request b
6464
And the event "metaData.request.httpVersion" matches "^HTTP/\d\.\d$"
6565
And the event "metaData.request.params.a" equals "123"
6666
And the event "metaData.request.params.b" equals "456"
67+
And the event "metaData.request.params.name" equals "baba"
68+
And the event "metaData.request.params.favourite_letter" equals "z"
69+
And the event "metaData.request.params.password" equals "[FILTERED]"
6770
And the event "metaData.request.referer" is null
6871
And the event "metaData.request.url" ends with "/unhandled?a=123&b=456"
6972

@@ -86,6 +89,9 @@ Scenario: A POST request with JSON sends a report with the parsed request body a
8689
And the event "metaData.request.httpVersion" matches "^HTTP/\d\.\d$"
8790
And the event "metaData.request.params.a" equals "123"
8891
And the event "metaData.request.params.b" equals "456"
92+
And the event "metaData.request.params.name" is null
93+
And the event "metaData.request.params.favourite_letter" is null
94+
And the event "metaData.request.params.password" is null
8995
And the event "metaData.request.referer" is null
9096
And the event "metaData.request.url" ends with "/unhandled?a=123&b=456"
9197

@@ -172,3 +178,55 @@ Scenario: clearing feature flags for an unhandled error
172178
And I wait to receive an error
173179
Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier
174180
And the event has no feature flags
181+
182+
@not-rack-1
183+
@not-rack-2
184+
Scenario: An unrewindable POST request with form data does not attach request body
185+
Given I set environment variable "BUGSNAG_RACK_NO_REWIND" to "true"
186+
And I start the rack service
187+
When I send a POST request to "/unhandled?a=123&b=456" in the rack app with the following form data:
188+
| name | baba |
189+
| favourite_letter | z |
190+
| password | password1 |
191+
And I wait to receive an error
192+
Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier
193+
And the event "metaData.request.body" is null
194+
And the event "metaData.request.clientIp" is not null
195+
And the event "metaData.request.cookies" is null
196+
And the event "metaData.request.headers.Host" is not null
197+
And the event "metaData.request.headers.User-Agent" is not null
198+
And the event "metaData.request.httpMethod" equals "POST"
199+
And the event "metaData.request.httpVersion" matches "^HTTP/\d\.\d$"
200+
And the event "metaData.request.params.a" equals "123"
201+
And the event "metaData.request.params.b" equals "456"
202+
And the event "metaData.request.params.name" is null
203+
And the event "metaData.request.params.favourite_letter" is null
204+
And the event "metaData.request.params.password" is null
205+
And the event "metaData.request.referer" is null
206+
And the event "metaData.request.url" ends with "/unhandled?a=123&b=456"
207+
208+
@not-rack-1
209+
@not-rack-2
210+
Scenario: An unrewindable POST request with JSON does not attach request body
211+
Given I set environment variable "BUGSNAG_RACK_NO_REWIND" to "true"
212+
And I start the rack service
213+
When I send a POST request to "/unhandled?a=123&b=456" in the rack app with the following JSON:
214+
| name | baba |
215+
| favourite_letter | z |
216+
| password | password1 |
217+
And I wait to receive an error
218+
Then the error is valid for the error reporting API version "4.0" for the "Ruby Bugsnag Notifier" notifier
219+
And the event "metaData.request.body" is null
220+
And the event "metaData.request.clientIp" is not null
221+
And the event "metaData.request.cookies" is null
222+
And the event "metaData.request.headers.Host" is not null
223+
And the event "metaData.request.headers.User-Agent" is not null
224+
And the event "metaData.request.httpMethod" equals "POST"
225+
And the event "metaData.request.httpVersion" matches "^HTTP/\d\.\d$"
226+
And the event "metaData.request.params.a" equals "123"
227+
And the event "metaData.request.params.b" equals "456"
228+
And the event "metaData.request.params.name" is null
229+
And the event "metaData.request.params.favourite_letter" is null
230+
And the event "metaData.request.params.password" is null
231+
And the event "metaData.request.referer" is null
232+
And the event "metaData.request.url" ends with "/unhandled?a=123&b=456"

features/support/env.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ def current_ip
6363
Maze::Runner.environment["BUGSNAG_ENDPOINT"] = "http://#{host}:#{Maze.config.port}/notify"
6464
Maze::Runner.environment["BUGSNAG_SESSION_ENDPOINT"] = "http://#{host}:#{Maze.config.port}/sessions"
6565
end
66+
67+
Before("@not-rack-1") do
68+
skip_this_scenario if ENV["RACK_VERSION"] == "1"
69+
end
70+
71+
Before("@not-rack-2") do
72+
skip_this_scenario if ENV["RACK_VERSION"] == "2"
73+
end

lib/bugsnag.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
require "rubygems"
22
require "thread"
3+
require "set"
4+
require "json"
5+
require "uri"
6+
require "socket"
7+
require "logger"
38

49
require "bugsnag/version"
510
require "bugsnag/utility/feature_data_store"
@@ -21,21 +26,9 @@
2126
# as it doesn't auto-configure when loaded
2227
require "bugsnag/integrations/rack"
2328

24-
require "bugsnag/middleware/rack_request"
25-
require "bugsnag/middleware/warden_user"
26-
require "bugsnag/middleware/clearance_user"
27-
require "bugsnag/middleware/callbacks"
28-
require "bugsnag/middleware/rails3_request"
29-
require "bugsnag/middleware/sidekiq"
30-
require "bugsnag/middleware/mailman"
31-
require "bugsnag/middleware/rake"
32-
require "bugsnag/middleware/classify_error"
33-
require "bugsnag/middleware/delayed_job"
34-
3529
require "bugsnag/breadcrumb_type"
3630
require "bugsnag/breadcrumbs/validator"
3731
require "bugsnag/breadcrumbs/breadcrumb"
38-
require "bugsnag/breadcrumbs/breadcrumbs"
3932

4033
require "bugsnag/utility/duplicator"
4134
require "bugsnag/utility/metadata_delegate"

lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "set"
2-
31
module Bugsnag::Breadcrumbs
42
class OnBreadcrumbCallbackList
53
def initialize(configuration)

lib/bugsnag/breadcrumbs/validator.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'bugsnag/breadcrumbs/breadcrumbs'
2-
31
module Bugsnag::Breadcrumbs
42
##
53
# Validates a given breadcrumb before it is stored

lib/bugsnag/cleaner.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'uri'
2-
31
module Bugsnag
42
# @api private
53
class Cleaner

lib/bugsnag/configuration.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
require "set"
2-
require "socket"
3-
require "logger"
4-
require "bugsnag/middleware_stack"
1+
require "bugsnag/breadcrumbs/on_breadcrumb_callback_list"
2+
3+
require "bugsnag/endpoint_configuration"
4+
require "bugsnag/endpoint_validator"
5+
6+
require "bugsnag/middleware/breadcrumbs"
57
require "bugsnag/middleware/callbacks"
8+
require "bugsnag/middleware/classify_error"
9+
require "bugsnag/middleware/clearance_user"
10+
require "bugsnag/middleware/delayed_job"
611
require "bugsnag/middleware/discard_error_class"
712
require "bugsnag/middleware/exception_meta_data"
813
require "bugsnag/middleware/ignore_error_class"
9-
require "bugsnag/middleware/suggestion_data"
10-
require "bugsnag/middleware/classify_error"
14+
require "bugsnag/middleware/mailman"
15+
require "bugsnag/middleware/rack_request"
16+
require "bugsnag/middleware/rails3_request"
17+
require "bugsnag/middleware/rake"
1118
require "bugsnag/middleware/session_data"
12-
require "bugsnag/middleware/breadcrumbs"
19+
require "bugsnag/middleware/sidekiq"
20+
require "bugsnag/middleware/suggestion_data"
21+
require "bugsnag/middleware/warden_user"
22+
23+
require "bugsnag/middleware_stack"
24+
1325
require "bugsnag/utility/circular_buffer"
14-
require "bugsnag/breadcrumbs/breadcrumbs"
15-
require "bugsnag/breadcrumbs/on_breadcrumb_callback_list"
16-
require "bugsnag/endpoint_configuration"
17-
require "bugsnag/endpoint_validator"
1826

1927
module Bugsnag
2028
class Configuration

lib/bugsnag/delivery/synchronous.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "net/https"
2-
require "uri"
32

43
module Bugsnag
54
module Delivery

lib/bugsnag/delivery/thread_queue.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "thread"
2-
31
module Bugsnag
42
module Delivery
53
class ThreadQueue < Synchronous

lib/bugsnag/event.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "bugsnag/report"
2-
31
module Bugsnag
42
# For now Event is just an alias of Report. This points to the same object so
53
# any changes to Report will also affect Event

lib/bugsnag/helpers.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
require 'uri'
2-
require 'set'
3-
require 'json'
4-
5-
61
module Bugsnag
72
module Helpers # rubocop:todo Metrics/ModuleLength
83
MAX_STRING_LENGTH = 3072

lib/bugsnag/integrations/mongo.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'mongo'
2-
require 'bugsnag/breadcrumbs/breadcrumbs'
32

43
module Bugsnag
54
##

lib/bugsnag/integrations/rails/active_job.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'set'
2-
31
module Bugsnag::Rails
42
module ActiveJob
53
SEVERITY = 'error'

lib/bugsnag/integrations/rails/rails_breadcrumbs.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "bugsnag/breadcrumbs/breadcrumbs"
2-
31
module Bugsnag::Rails
42
DEFAULT_RAILS_BREADCRUMBS = [
53
{

lib/bugsnag/integrations/railtie.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Rails 3.x hooks
22

3-
require "json"
43
require "rails"
5-
require "bugsnag"
6-
require "bugsnag/middleware/rails3_request"
7-
require "bugsnag/middleware/rack_request"
84
require "bugsnag/integrations/rails/rails_breadcrumbs"
95

106
module Bugsnag

lib/bugsnag/integrations/rake.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
require 'bugsnag'
1+
# this file can either be required manually by a user, in which case 'bugsnag'
2+
# needs to be required, or it can be required automatically in the railtie,
3+
# in which case 'bugsnag' has already been required
4+
require 'bugsnag' unless defined?(Bugsnag)
25

36
Rake::TaskManager.record_task_metadata = true
47

lib/bugsnag/middleware/rack_request.rb

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "json"
2-
31
module Bugsnag::Middleware
42
##
53
# Extracts and attaches rack data to an error report
@@ -17,7 +15,15 @@ def call(report)
1715

1816
request = ::Rack::Request.new(env)
1917

20-
params = request.params rescue {}
18+
params =
19+
# if the request body isn't rewindable then we can't read request.POST
20+
# which is used internally by request.params
21+
if request.body.respond_to?(:rewind)
22+
request.params rescue {}
23+
else
24+
request.GET rescue {}
25+
end
26+
2127
client_ip = request.ip.to_s rescue SPOOF
2228
session = env["rack.session"]
2329

@@ -106,7 +112,11 @@ def format_headers(env, referer)
106112
end
107113

108114
def add_request_body(report, request, env)
109-
body = parsed_request_body(request, env)
115+
begin
116+
body = parsed_request_body(request, env)
117+
rescue StandardError
118+
return nil
119+
end
110120

111121
# this request may not have a body
112122
return unless body.is_a?(Hash) && !body.empty?
@@ -115,26 +125,34 @@ def add_request_body(report, request, env)
115125
end
116126

117127
def parsed_request_body(request, env)
118-
return request.POST rescue nil if request.form_data?
128+
# if the request is not rewindable then either:
129+
# - it's been read already and so is impossible to read
130+
# - it hasn't been read yet and us reading it will prevent the user from
131+
# reading it themselves
132+
# in either case we should avoid attempting to
133+
return nil unless request.body.respond_to?(:rewind)
134+
135+
if request.form_data?
136+
begin
137+
return request.POST
138+
ensure
139+
request.body.rewind
140+
end
141+
end
119142

120143
content_type = env["CONTENT_TYPE"]
121144

122145
return nil if content_type.nil?
146+
return nil unless content_type.include?('/json') || content_type.include?('+json')
123147

124-
if content_type.include?('/json') || content_type.include?('+json')
125-
begin
126-
body = request.body
148+
begin
149+
body = request.body
127150

128-
return JSON.parse(body.read)
129-
rescue StandardError
130-
return nil
131-
ensure
132-
# the body must be rewound so other things can read it after we do
133-
body.rewind
134-
end
151+
JSON.parse(body.read)
152+
ensure
153+
# the body must be rewound so other things can read it after we do
154+
body.rewind
135155
end
136-
137-
nil
138156
end
139157

140158
def add_cookies(report, request)

lib/bugsnag/report.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require "json"
21
require "pathname"
32
require "bugsnag/error"
43
require "bugsnag/stacktrace"

0 commit comments

Comments
 (0)