Class: Pakyow::Security::Base

Inherits:
Object
  • Object
show all
Includes:
Support::Hookable
Defined in:
lib/pakyow/security/base.rb

Constant Summary collapse

SAFE_HTTP_METHODS =
%i(get head options trace).freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



15
16
17
# File 'lib/pakyow/security/base.rb', line 15

def initialize(config)
  @config = config
end

Instance Method Details

#allowed?(_) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/pakyow/security/base.rb', line 42

def allowed?(_)
  false
end

#call(connection) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/pakyow/security/base.rb', line 19

def call(connection)
  unless safe?(connection) || allowed?(connection)
    reject(connection)
  end

  connection
end

#reject(connection) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/pakyow/security/base.rb', line 27

def reject(connection)
  performing :reject do
    connection.logger.warn "Request rejected by #{self.class}; connection: #{connection.inspect}"

    connection.status = 403
    connection.body = StringIO.new("Forbidden")

    raise InsecureRequest
  end
end

#safe?(connection) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/pakyow/security/base.rb', line 38

def safe?(connection)
  SAFE_HTTP_METHODS.include? connection.method
end