Skip to content

Default rack-protection reaction drop_session harmful? #2012

Open

Description

@dentarg

Sinatra has the some protections enabled by default

# On by default, unless skipped
use ::Rack::Protection::FrameOptions, options unless except.include? :frame_options
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::XSSHeader, options unless except.include? :xss_header

but the reaction is set to drop_session

options[:reaction] ||= :drop_session

which renders many protections useless? If you want them to actually stop the request from reaching your application


def call(env)
unless accepts? env
instrument env
result = react env
end
result or app.call(env)
end

def drop_session(env)
return unless session? env
session(env).clear
return if ["1", "true"].include?(ENV["RACK_PROTECTION_SILENCE_DROP_SESSION_WARNING"])
warn env, "session dropped by #{self.class}"
end

Activity

  1. osbre commented on Aug 1, 2024

    @osbre

    I wonder if #2037 is related to this bug?

  2. dentarg commented on Aug 2, 2024

    @dentarg
    MemberAuthor

    I don't think so

  3. dentarg commented on Aug 8, 2024

    @dentarg
    MemberAuthor

    @osbre Ah, yes "it is", in terms that is hard to see that a protection is working when you have a very small/simple app

    EDIT: If you enable logging in Sinatra, enable :logging, Rack::Protection will log "attack prevented ..." lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions