Class: Paraxial::PHPAttackMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/paraxial.rb

Overview

Your code goes hereā€¦

Constant Summary collapse

VALID_LENGTHS =
[:hour, :day, :week, :infinity]

Instance Method Summary collapse

Constructor Details

#initialize(app, length: :hour) ⇒ PHPAttackMiddleware

Returns a new instance of PHPAttackMiddleware.



27
28
29
30
31
32
33
34
35
# File 'lib/paraxial.rb', line 27

def initialize(app, length: :hour)
  @app = app
  if VALID_LENGTHS.include?(length)
    @ban_length = length
  else
    puts "[Paraxial] PHPAttackMiddleware invalid ban length: #{length}, using hour"
    @ban_length = :hour
  end
end

Instance Method Details

#call(env) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/paraxial.rb', line 37

def call(env)
  request = ActionDispatch::Request.new(env)

  if request.path.downcase.end_with?('.php')
    Paraxial.ban_ip_msg(request.remote_ip, @ban_length, "Sent request ending in .php")
    # Return a 404 response if the request path ends with '.php'
    [404, { 'Content-Type' => 'text/plain' }, ['Not Found']]
  else
    # Pass the request to the next middleware or the application
    @app.call(env)
  end
end