1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/rack-protection/lib/rack/protection.rb

41 lines
2.2 KiB
Ruby
Raw Normal View History

2011-05-23 10:07:54 +02:00
require 'rack/protection/version'
require 'rack'
module Rack
module Protection
autoload :AuthenticityToken, 'rack/protection/authenticity_token'
autoload :Base, 'rack/protection/base'
autoload :EscapedParams, 'rack/protection/escaped_params'
autoload :FormToken, 'rack/protection/form_token'
autoload :FrameOptions, 'rack/protection/frame_options'
2012-01-30 15:57:25 +07:00
autoload :HttpOrigin, 'rack/protection/http_origin'
2011-06-20 09:16:03 +02:00
autoload :IPSpoofing, 'rack/protection/ip_spoofing'
2011-06-19 15:26:39 +02:00
autoload :JsonCsrf, 'rack/protection/json_csrf'
2011-05-23 10:07:54 +02:00
autoload :PathTraversal, 'rack/protection/path_traversal'
autoload :RemoteReferrer, 'rack/protection/remote_referrer'
autoload :RemoteToken, 'rack/protection/remote_token'
2011-05-25 11:57:25 +02:00
autoload :SessionHijacking, 'rack/protection/session_hijacking'
2011-05-23 10:07:54 +02:00
autoload :XSSHeader, 'rack/protection/xss_header'
def self.new(app, options = {})
# does not include: RemoteReferrer, AuthenticityToken and FormToken
2011-05-23 10:07:54 +02:00
except = Array options[:except]
2013-01-21 18:16:28 +07:00
use_these = Array options[:use]
2011-05-23 10:07:54 +02:00
Rack::Builder.new do
2013-01-21 18:16:28 +07:00
use ::Rack::Protection::RemoteReferrer, options if use_these.include? :remote_referrer
use ::Rack::Protection::AuthenticityToken,options if use_these.include? :authenticity_token
use ::Rack::Protection::FormToken, options if use_these.include? :form_token
use ::Rack::Protection::FrameOptions, options unless except.include? :frame_options
2012-01-30 15:57:25 +07:00
use ::Rack::Protection::HttpOrigin, options unless except.include? :http_origin
use ::Rack::Protection::IPSpoofing, options unless except.include? :ip_spoofing
use ::Rack::Protection::JsonCsrf, options unless except.include? :json_csrf
use ::Rack::Protection::PathTraversal, options unless except.include? :path_traversal
use ::Rack::Protection::RemoteToken, options unless except.include? :remote_token
use ::Rack::Protection::SessionHijacking, options unless except.include? :session_hijacking
use ::Rack::Protection::XSSHeader, options unless except.include? :xss_header
2011-05-23 10:07:54 +02:00
run app
end.to_app
end
end
end