diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /config/initializers/rack_multipart_patch.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'config/initializers/rack_multipart_patch.rb')
-rw-r--r-- | config/initializers/rack_multipart_patch.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/config/initializers/rack_multipart_patch.rb b/config/initializers/rack_multipart_patch.rb new file mode 100644 index 00000000000..78cf6244814 --- /dev/null +++ b/config/initializers/rack_multipart_patch.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Rack + module Multipart + class << self + module MultipartPatch + def extract_multipart(req, params = Rack::Utils.default_query_parser) + log_multipart_warning(req) if log_large_multipart? + + super + end + + def log_multipart_warning(req) + content_length = req.content_length.to_i + + return unless content_length > log_threshold + + message = { + message: "Large multipart body detected", + path: req.path, + content_length: content_length, + correlation_id: ::Labkit::Context.correlation_id + } + + log_warn(message) + end + + def log_warn(message) + warn message.to_json + end + + def log_large_multipart? + Gitlab::Utils.to_boolean(ENV['ENABLE_RACK_MULTIPART_LOGGING'], default: true) && Gitlab.com? + end + + def log_threshold + ENV.fetch('RACK_MULTIPART_LOGGING_BYTES', 100_000_000).to_i + end + end + + prepend MultipartPatch + end + end +end |