mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 17:01:09 +08:00
FIX: Set sane default for Net::HTTP
when processing a request (#28141)
This commit patches `Net::HTTP` to reduce the default timeouts of 60 seconds when we are processing a request. There are certain routes in Discourse which makes external requests and if the proper timeouts are not set, we risk having the Unicorn master process force restarting the Unicorn workers once the `30` seconds timeout is reached. This can potentially become a vector for DoS attacks and this commit is aimed at reducing the risk here.
This commit is contained in:

committed by
GitHub

parent
a333d71d4c
commit
2492fe7715
16
lib/middleware/processing_request.rb
Normal file
16
lib/middleware/processing_request.rb
Normal file
@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Middleware::ProcessingRequest
|
||||
PROCESSING_REQUEST_THREAD_KEY = "discourse.processing_request"
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
Thread.current[PROCESSING_REQUEST_THREAD_KEY] = true
|
||||
@app.call(env)
|
||||
ensure
|
||||
Thread.current[PROCESSING_REQUEST_THREAD_KEY] = nil
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user