Skip to content

Commit

Permalink
Make rack_protection key work again for flipper ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Mar 3, 2025
1 parent fc88d91 commit abf3595
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/flipper/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,26 @@ def self.root

def self.app(flipper = nil, options = {})
env_key = options.fetch(:env_key, 'flipper')

if options.key?(:rack_protection)
warn "[DEPRECATION] `rack_protection` option is deprecated. " +
"Flipper::UI now only includes Rack::Protection::AuthenticityToken middleware. " +
"If you need additional protection, you can add it yourself."
rack_protection_options = if options.key?(:rack_protection)
options[:rack_protection]
else
{}
end

app = ->(_) { [200, { Rack::CONTENT_TYPE => 'text/html' }, ['']] }
builder = Rack::Builder.new
yield builder if block_given?
builder.use Rack::Protection::AuthenticityToken

# Only use Rack::Protection::AuthenticityToken if no other options are
# provided. Should avoid some pain for some people. If any options are
# provided then go whole hog and include all of Rack::Protection for
# backwards compatibility.
if rack_protection_options.empty?
builder.use Rack::Protection::AuthenticityToken
else
builder.use Rack::Protection, rack_protection_options
end

builder.use Rack::MethodOverride
builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
builder.use Flipper::UI::Middleware, flipper: flipper, env_key: env_key
Expand Down

0 comments on commit abf3595

Please sign in to comment.