Class: Gitlab::Middleware::HandleMalformedStrings

Inherits:
Object
  • Object
show all
Includes:
ActionController::HttpAuthentication::Basic
Defined in:
lib/gitlab/middleware/handle_malformed_strings.rb

Overview

There is no valid reason for a request to contain a malformed string so just return HTTP 400 (Bad Request) if we receive one

Constant Summary collapse

NULL_BYTE_REGEX =
Regexp.new(Regexp.escape("\u0000")).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ HandleMalformedStrings

Returns a new instance of HandleMalformedStrings.


14
15
16
# File 'lib/gitlab/middleware/handle_malformed_strings.rb', line 14

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.


12
13
14
# File 'lib/gitlab/middleware/handle_malformed_strings.rb', line 12

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object


18
19
20
21
22
# File 'lib/gitlab/middleware/handle_malformed_strings.rb', line 18

def call(env)
  return [400, { 'Content-Type' => 'text/plain' }, ['Bad Request']] if request_contains_malformed_string?(env)

  app.call(env)
end