0
0
Fork 0

Check Content-Length in ResponseWithLimitAdapter (#31285)

This commit is contained in:
Christian Schmidt 2024-08-06 10:23:48 +02:00 committed by GitHub
parent 103e544cfa
commit 9d0cafd06b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 107 additions and 9 deletions

View file

@ -234,13 +234,17 @@ class Request
end
def body_with_limit(limit = 1.megabyte)
raise Mastodon::LengthValidationError if content_length.present? && content_length > limit
require_limit_not_exceeded!(limit)
contents = truncated_body(limit)
raise Mastodon::LengthValidationError if contents.bytesize > limit
raise Mastodon::LengthValidationError, "Body size exceeds limit of #{limit}" if contents.bytesize > limit
contents
end
def require_limit_not_exceeded!(limit)
raise Mastodon::LengthValidationError, "Content-Length #{content_length} exceeds limit of #{limit}" if content_length.present? && content_length > limit
end
end
if ::HTTP::Response.methods.include?(:body_with_limit) && !Rails.env.production?