From f38fc52a8a1a13daf6047600740574c482b7a557 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Fri, 2 Sep 2011 15:01:03 -0600 Subject: [PATCH] remove Sinatra::Protection (part of Sinatra now) --- sinatra-contrib/README.md | 7 +-- sinatra-contrib/lib/sinatra/contrib.rb | 1 - sinatra-contrib/lib/sinatra/protection.rb | 53 ----------------------- sinatra-contrib/spec/protection_spec.rb | 45 ------------------- 4 files changed, 2 insertions(+), 104 deletions(-) delete mode 100644 sinatra-contrib/lib/sinatra/protection.rb delete mode 100644 sinatra-contrib/spec/protection_spec.rb diff --git a/sinatra-contrib/README.md b/sinatra-contrib/README.md index f4870efc..4fb5b5e5 100644 --- a/sinatra-contrib/README.md +++ b/sinatra-contrib/README.md @@ -41,9 +41,6 @@ Currently included: * `sinatra/namespace`: Adds namespace support to Sinatra. -* `sinatra/protection`: Sets up rack-protection to protect common attacks - against your application. - * `sinatra/respond_with`: Choose action and/or template depending automatically depending on the incoming request. Adds helpers `respond_to` and `respond_with`. @@ -100,13 +97,13 @@ A single extension (example: sinatra-content-for): ``` ruby require 'sinatra/base' require 'sinatra/content_for' -require 'sinatra/protection' +require 'sinatra/namespace' class MyApp < Sinatra::Base # Note: Some modules are extensions, some helpers, see the specific # documentation or the source helpers Sinatra::ContentFor - register Sinatra::Protection + register Sinatra::Namespace end ``` diff --git a/sinatra-contrib/lib/sinatra/contrib.rb b/sinatra-contrib/lib/sinatra/contrib.rb index 14057a04..47a8e305 100644 --- a/sinatra-contrib/lib/sinatra/contrib.rb +++ b/sinatra-contrib/lib/sinatra/contrib.rb @@ -9,7 +9,6 @@ module Sinatra module Common register :ConfigFile register :Namespace - register :Protection register :RespondWith helpers :Capture diff --git a/sinatra-contrib/lib/sinatra/protection.rb b/sinatra-contrib/lib/sinatra/protection.rb deleted file mode 100644 index a36e1d97..00000000 --- a/sinatra-contrib/lib/sinatra/protection.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'sinatra/base' -require 'rack/protection' - -module Sinatra - - # = Sinatra::Protection - # - # Sets up {rack-protection}[https://github.com/rkh/rack-protection] to - # prevent common attacks against your application. - # - # == Usage - # The protection modes used can be configured by the +protection+ setting: - # - # require 'sinatra' - # require 'sinatra/protection' - # - # set :protection, :except => :path_traversal - # - # There are a few, partly protection specific options you can set, too: - # - # set :protection, - # :reaction => :deny, # block malicious requests, alternative: :drop_session - # :frame_options => :deny # do not allow any embedding in frames (default: :sameorigin) - # - # For more information, see rack-protection. - # - # === Classic Application - # - # As with any other extension, you have to register this one manually in a - # classic application: - # - # require 'sinatra/base' - # require 'sinatra/protection' - # - # class MyApp < Sinatra::Base - # register Sinatra::Protection - # end - module Protection - def setup_default_middleware(builder) - super - if protection - options = protection == true ? {} : protection - builder.use Rack::Protection, options - end - end - - def self.registered(base) - base.enable :protection - end - end - - register Sinatra::Namespace -end diff --git a/sinatra-contrib/spec/protection_spec.rb b/sinatra-contrib/spec/protection_spec.rb deleted file mode 100644 index 0cc36d82..00000000 --- a/sinatra-contrib/spec/protection_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'backports' -require_relative 'spec_helper' - -class MiddlewareTracker < Rack::Builder - def self.used - @used ||= [] - end - - def use(middleware, *) - MiddlewareTracker.used << middleware - super - end -end - -describe Sinatra::Protection do - before do - Rack.send :remove_const, :Builder - Rack.const_set :Builder, MiddlewareTracker - MiddlewareTracker.used.clear - end - - after do - Rack.send :remove_const, :Builder - Rack.const_set :Builder, MiddlewareTracker.superclass - end - - it 'sets up Rack::Protection' do - Sinatra.new { register Sinatra::Protection }.new - MiddlewareTracker.used.should include(Rack::Protection) - end - - it 'sets up Rack::Protection::PathTraversal by default' do - Sinatra.new { register Sinatra::Protection }.new - MiddlewareTracker.used.should include(Rack::Protection::PathTraversal) - end - - - it 'does not set up Rack::Protection::PathTraversal when disabling it' do - Sinatra.new do - register Sinatra::Protection - set :protection, :except => :path_traversal - end.new - MiddlewareTracker.used.should_not include(Rack::Protection::PathTraversal) - end -end