rack-headers-filter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6560d4cfe0e5ed1d9f65a64488c0bda563440d65c864f03805ff5c1fefec95c7
4
+ data.tar.gz: a275de9d0440a0d9baac2954cc457ea9e0967ce32293ca8f1deb87dea142eddf
5
+ SHA512:
6
+ metadata.gz: 44ad4bcecede0178c25e19dcec75dc55639b4072127dc5c2e7697a399f4e6b7dc7e61c29096c9bed1c847e5df10749b4ad4ab5017819484c1a9e454a92b8d078
7
+ data.tar.gz: d967fc8de6b6b0e5007669abde6d5981e40004156cf19884bce6aeeffa272fdf844e657f502689e99f531321c3c9684dceeffb144502939b6438b2a4c4f5099e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
1
+ # https://docs.travis-ci.com/user/languages/ruby/
2
+ # https://docs.travis-ci.com/user/deployment/rubygems/
3
+
4
+ language: ruby
5
+ sudo: false
6
+ cache: bundler
7
+ rvm:
8
+ - jruby
9
+ - 2.3.0
10
+ script: bundle exec rspec
11
+ deploy:
12
+ provider: rubygems
13
+ api_key: "YOUR API KEY"
14
+ on:
15
+ tags: true
16
+ branch!g : master
17
+ notifications:
18
+ email:
19
+ recipients:
20
+ - htmldrum@tutanota.com
21
+ on_failure: change
22
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-headers_filter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Pusher Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Rack::HeadersFilter
2
+
3
+ Sanitizes some of the "trusted" headers. Useful when you don't control your
4
+ frontend router like on Heroku. This is the next best thing.
5
+
6
+ The are some funky heuristics happening inside of Rack::Request. For example
7
+ `request.ip` and `request.host_with_port` use HTTP_X_FORWARDED_HOST which is
8
+ forgeable by the client on Heroku. This is then trusted by other code like
9
+ `ActionController::ForceSSL` as a canonical source of truth. The result is
10
+ that if something can set the `X-Forwarded-Host` header, and `config.force_ssl
11
+ = true` is set in rails, the user gets redirected to that random host.
12
+
13
+ This middleware creates a list of "dangerous" headers that are used by
14
+ `Rack::Request` and filters out the ones that are not controlled by the
15
+ router. By default it is configured to be deployed on Heroku.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'rack-headers_filter'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install rack-headers_filter
32
+
33
+ ## Usage
34
+
35
+ This middleware is designed to be installed first in the chain. Either add
36
+ this to the `config.ru`:
37
+
38
+ ```ruby
39
+ require 'rack/headers_filter'
40
+ use Rack::HeadersFilter
41
+ ```
42
+
43
+ Or in `config/environments/production.rb`:
44
+
45
+ ```ruby
46
+ # First thing, filter out bad headers (0 == first)
47
+ config.middleware.insert_before(0, Rack::HeadersFilter)
48
+ ```
49
+
50
+ By default it is configured with the Heroku router headers. It's also possible
51
+ to specify them manually:
52
+
53
+ ```ruby
54
+ require 'rack/headers_filter'
55
+ use Rack::HeadersFilter, trusted_headers: %[HTTP_HOST]
56
+ ```
57
+
58
+ ## Development
59
+
60
+ After checking out the repo, run `script/setup` to install dependencies. Then,
61
+ run `rake spec` to run the tests. You can also run `script/console` for an
62
+ interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`.
65
+ To release a new version, update the version number in `version.rb`, and then
66
+ run `bundle exec rake release`, which will create a git tag for the version,
67
+ push git commits and tags, and push the `.gem` file to
68
+ [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at
73
+ https://github.com/pusher/rack-headers_filter.
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the
78
+ [MIT License](http://opensource.org/licenses/MIT).
79
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,19 @@
1
+ module Rack
2
+ class HeadersFilter
3
+ BLACKLIST_HEADERS = %w[
4
+ HTTP_X_FORWARDED_HOST
5
+ ]
6
+
7
+ attr_reader :remove_headers
8
+
9
+ def initialize(app, blacklist_headers: BLACKLIST_HEADERS)
10
+ @remove_headers = blacklist_headers
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ @remove_headers.each { |header| env.delete(header) }
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "rack-headers-filter"
4
+ spec.version = '0.0.1'
5
+ spec.authors = ["htmldrum"]
6
+ spec.email = ["htmldrum@tutanota.com"]
7
+
8
+ spec.summary = %q{Removes sensitive untrusted headers from the request}
9
+ spec.description = %q{
10
+ The goal of this gem is to avoid depending on potentially forgeable
11
+ headers down the line by configuring the deploy target properly.
12
+
13
+ Forks https://github.com/pusher/rack-headers_filter to allow more configuration
14
+ options when initializing the headers. Personally disagree with the restrictive
15
+ list of headers in this component which is used here in a more general purpose
16
+ way
17
+ }
18
+ spec.homepage = "https://github.com/htmldrum/rack-headers-filter"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rack", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "rack-test"
29
+ end
data/script/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/headers_filter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/script/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-headers-filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - htmldrum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: "\n The goal of this gem is to avoid depending on potentially forgeable\n
84
+ \ headers down the line by configuring the deploy target properly.\n\n Forks
85
+ https://github.com/pusher/rack-headers_filter to allow more configuration\n options
86
+ when initializing the headers. Personally disagree with the restrictive\n list
87
+ of headers in this component which is used here in a more general purpose\n way\n
88
+ \ "
89
+ email:
90
+ - htmldrum@tutanota.com
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - ".gitignore"
96
+ - ".rspec"
97
+ - ".travis.yml"
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - lib/rack/headers_filter.rb
103
+ - rack-headers-filter.gemspec
104
+ - script/console
105
+ - script/setup
106
+ homepage: https://github.com/htmldrum/rack-headers-filter
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.7
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Removes sensitive untrusted headers from the request
130
+ test_files: []