Skip to content

Commit

Permalink
Merge pull request #1663 from 18F/margolis-correct-host
Browse files Browse the repository at this point in the history
Filter headers via Middleware
  • Loading branch information
zachmargolis authored Sep 8, 2017
2 parents e973ca9 + ea4f619 commit 073261f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ gem 'phony_rails'
gem 'premailer-rails'
gem 'proofer', github: '18F/identity-proofer-gem', branch: 'master'
gem 'rack-cors', require: 'rack/cors'
gem 'rack-headers_filter'
gem 'rack-timeout'
gem 'readthis'
gem 'redis-session-store', github: '18F/redis-session-store', branch: 'master'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ GEM
rack-attack (5.0.1)
rack
rack-cors (0.4.1)
rack-headers_filter (0.0.1)
rack-mini-profiler (0.10.5)
rack (>= 1.2.0)
rack-protection (2.0.0)
Expand Down Expand Up @@ -714,6 +715,7 @@ DEPENDENCIES
proofer!
pry-byebug
rack-cors
rack-headers_filter
rack-mini-profiler
rack-test
rack-timeout
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Application < Rails::Application
event.payload.except(:params, :headers)
end

config.middleware.insert_before 0, Rack::HeadersFilter

config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
Expand Down
9 changes: 9 additions & 0 deletions spec/requests/headers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rails_helper'

RSpec.describe 'Headers' do
it 'does not reflect header host values' do
get root_path, headers: { 'X-Forwarded-Host' => 'evil.com' }

expect(response.body).to_not include('evil.com')
end
end

0 comments on commit 073261f

Please sign in to comment.