rack-filter-param 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rack/filter_param.rb +66 -0
- data/lib/rack/filter_param/version.rb +5 -0
- data/rack-filter-param.gemspec +29 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e90f42cf5877e784de5126dc00f1ee59f6d78ab4
|
4
|
+
data.tar.gz: 50293c18b6b72b49329208bfbbe8e28d8e83855e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15b44d865dd742febb1b203ad9a453effc39cd4c51b75afb1ad60cadbadf6b7fb57c09ed12afa8375fd7e4a41d956f78700b28c4544639aab170c7f47ab2ac24
|
7
|
+
data.tar.gz: 44674e64b057061e6b82622d69a453da0bd46cfb2a49ccf82f9b6a86dccc64f6baa88cff82e6a23bdaa08af2ebafe436de0dd24135f158a9d92e87801dd17906
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Rob Watson
|
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,58 @@
|
|
1
|
+
# rack-filter-param
|
2
|
+
|
3
|
+
Refactoring something behind an API? Plagued by extraneous HTTP params? `rack-filter-param` might be for you.
|
4
|
+
|
5
|
+
## What is it?
|
6
|
+
|
7
|
+
[Rack](https://github.com/rack/rack) middleware to remove specific params from HTTP requests.
|
8
|
+
|
9
|
+
## What does it do?
|
10
|
+
|
11
|
+
Given a set of params and optional constraints, `rack-filter-param` will remove those params, then pass the request downstream.
|
12
|
+
|
13
|
+
Removes params from:
|
14
|
+
|
15
|
+
* GET querystring
|
16
|
+
* POST params (x-www-form-urlencoded)
|
17
|
+
* JSON or other params hitherto processed by [`ActionDispatch::ParamsParser`](http://api.rubyonrails.org/classes/ActionDispatch/ParamsParser.html)
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
|
23
|
+
gem 'rack-filter-param', require: 'rack/filter_param'
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
In rackup file or `application.rb`, initialize `rack-filter-param` with a list of HTTP params you want filtered from requests.
|
29
|
+
|
30
|
+
Strip a parameter named `client_id`:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
use Rack::FilterParam, :client_id
|
34
|
+
```
|
35
|
+
|
36
|
+
Strip a parameter named `client_id` from a specific path only:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
use Rack::FilterParam, { param: :client_id, path: '/oauth/tokens' }
|
40
|
+
```
|
41
|
+
|
42
|
+
Strip a parameter named `client_id` from a fuzzy path:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
use Rack::FilterParam, { param: :client_id, path: /\A\/oauth/ }
|
46
|
+
```
|
47
|
+
|
48
|
+
To filter multiple parameters, an array of parameters or options hashes can also be passed.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rfwatson/rack-filter-param
|
53
|
+
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
58
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/filter_param"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require "rack/filter_param/version"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class FilterParam
|
5
|
+
ACTION_DISPATCH_KEY = 'action_dispatch.request.request_parameters'.freeze
|
6
|
+
FILTERED_PARAMS_KEY = 'rack.filtered_params'.freeze
|
7
|
+
|
8
|
+
def initialize(app, *params)
|
9
|
+
@app = app
|
10
|
+
@params = params.flatten
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
@request = Rack::Request.new(env)
|
15
|
+
@params.each { |param| process_param(param) }
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :request
|
23
|
+
|
24
|
+
def process_param(param)
|
25
|
+
return unless path_matches?(param)
|
26
|
+
|
27
|
+
param = param[:param] if param.is_a?(Hash)
|
28
|
+
|
29
|
+
if delete_from_action_dispatch(param) || delete_from_request(param)
|
30
|
+
filtered_params << [ param.to_s, nil ]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def path_matches?(param)
|
35
|
+
return true unless param.is_a?(Hash)
|
36
|
+
|
37
|
+
path = param[:path]
|
38
|
+
return true unless path = param[:path]
|
39
|
+
|
40
|
+
return request.env['PATH_INFO'] == path if path.is_a?(String)
|
41
|
+
return request.env['PATH_INFO'] =~ path if path.is_a?(Regexp)
|
42
|
+
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_from_action_dispatch(param)
|
47
|
+
action_dispatch_parsed? && !!action_dispatch_params.delete(param.to_s)
|
48
|
+
end
|
49
|
+
|
50
|
+
def delete_from_request(param)
|
51
|
+
!!request.delete_param(param.to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
def action_dispatch_params
|
55
|
+
request.env[ACTION_DISPATCH_KEY]
|
56
|
+
end
|
57
|
+
|
58
|
+
def action_dispatch_parsed?
|
59
|
+
!action_dispatch_params.nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
def filtered_params
|
63
|
+
request.env[FILTERED_PARAMS_KEY] ||= []
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/filter_param/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-filter-param"
|
8
|
+
spec.version = Rack::FilterParam::VERSION
|
9
|
+
spec.authors = ["Rob Watson"]
|
10
|
+
spec.email = ["rob@mixlr.com"]
|
11
|
+
|
12
|
+
spec.summary = "Rack middleware to filter params from HTTP requests"
|
13
|
+
spec.homepage = "https://github.com/rfwatson"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'rack-test', '~> 0.6'
|
27
|
+
spec.add_development_dependency 'json', '~> 2'
|
28
|
+
spec.add_development_dependency 'byebug', '~> 9'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-filter-param
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Watson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-10 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '9'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- rob@mixlr.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/rack/filter_param.rb
|
114
|
+
- lib/rack/filter_param/version.rb
|
115
|
+
- rack-filter-param.gemspec
|
116
|
+
homepage: https://github.com/rfwatson
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.6.12
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Rack middleware to filter params from HTTP requests
|
140
|
+
test_files: []
|