Skip to content

Commit

Permalink
Merge pull request #267 from castle/CAS-12693/do-not-pass-non-string-…
Browse files Browse the repository at this point in the history
…header-values

Filter out non string header values
  • Loading branch information
zuchmanski authored Aug 12, 2024
2 parents 6d1ccac + de47d9c commit f6274cd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
source 'https://rubygems.org'

gem 'rack'
gem 'rails', '~> 7.0'
gem 'rails', '~> 7.1'
gem 'rake'

group :development, :test do
Expand Down
2 changes: 1 addition & 1 deletion lib/castle/headers/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call
next unless header_name.match(VALUABLE_HEADERS)

formatted_name = @header_format.call(header_name)
acc[formatted_name] = @request_env[header_name]
acc[formatted_name] = @request_env[header_name].to_s
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/rails/support/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require 'action_controller/railtie'

class TestApp < Rails::Application
secrets.secret_token = 'secret_token'
secrets.secret_key_base = 'secret_key_base'
credentials.secret_token = 'secret_token'
credentials.secret_key_base = 'secret_key_base'

config.logger = Logger.new($stdout)
Rails.logger = config.logger
Expand Down
8 changes: 5 additions & 3 deletions spec/lib/castle/headers/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'HTTP_USER_AGENT' => 'Mozilla 1234',
'TEST' => '1',
'REMOTE_ADDR' => '1.2.3.4',
'HTTP_CONTENT_LENGTH' => '0'
'HTTP_CONTENT_LENGTH' => '0',
'http_accept_language.parser' => -> { 'noop' }
)
result[:HTTP_OK] = 'OK'
result
Expand All @@ -29,12 +30,13 @@
'Ok' => 'OK',
'User-Agent' => 'Mozilla 1234',
'Remote-Addr' => '1.2.3.4',
'X-Forwarded-For' => '1.2.3.4'
'X-Forwarded-For' => '1.2.3.4',
'Accept-Language.parser' => start_with('#<Proc')
}
end
let(:request) { Rack::Request.new(env) }

context 'with list of header' do
it { expect(filter_call).to eq(filtered) }
it { expect(filter_call).to match(filtered) }
end
end

0 comments on commit f6274cd

Please sign in to comment.