go_to_param 1.1.2 → 2.0.0
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/go_to_param/version.rb +1 -1
- data/lib/go_to_param.rb +9 -3
- metadata +7 -58
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/Rakefile +0 -6
- data/go_to_param.gemspec +0 -22
- data/spec/go_to_param_spec.rb +0 -172
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ef3c76caad7dbf28335798a812644bfd00fc3609f6a59b601552e2d6f3f8915
|
|
4
|
+
data.tar.gz: eb54119400b07f9dd8bc1104aea81e0c08eed250461a4963f79d4c6e5c9ba113
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c00fa6dc82ce3b7f24802a16a726061e785da10e0b11fbb38acd66a230ae49261f73ef66ee06af926e7d38567408b3889bf8bd8ff2ba448f78b01cf3326ce94
|
|
7
|
+
data.tar.gz: 298750ed94c196b4b86368f889e41707223b2fd71e35f631b6b90c7cb7aac8ca615d3199b239380941aac191534c22be69d8244e259621df784bc7c844d08b4a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
- Remove `id` attribute for input tags generated by `hidden_go_to_tag` and `hidden_go_to_here_tag`, to avoid markup errors when using multiple on the same page.
|
|
6
|
+
- Disallow protocol-relative "//evil.com".
|
|
7
|
+
|
|
8
|
+
## 1.1.3
|
|
9
|
+
|
|
10
|
+
- Force MFA for privileged Rubygems actions.
|
|
11
|
+
|
|
3
12
|
## 1.1.2
|
|
4
13
|
|
|
5
14
|
- Fix keyword parameter warning. Thanks to @olleolleolle!
|
data/lib/go_to_param/version.rb
CHANGED
data/lib/go_to_param.rb
CHANGED
|
@@ -23,11 +23,11 @@ module GoToParam
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def hidden_go_to_tag
|
|
26
|
-
view_context.hidden_field_tag :go_to, go_to_path
|
|
26
|
+
view_context.hidden_field_tag :go_to, go_to_path, id: nil
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def hidden_go_to_here_tag(additional_query_params = {})
|
|
30
|
-
view_context.hidden_field_tag :go_to, go_to_here_params(additional_query_params)[:go_to]
|
|
30
|
+
view_context.hidden_field_tag :go_to, go_to_here_params(additional_query_params)[:go_to], id: nil
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def go_to_params(other_params = {})
|
|
@@ -62,7 +62,13 @@ module GoToParam
|
|
|
62
62
|
private
|
|
63
63
|
|
|
64
64
|
def matches_allowed_redirect_prefixes?
|
|
65
|
-
|
|
65
|
+
value = go_to_param_value
|
|
66
|
+
|
|
67
|
+
# Disallow protocol-relative "//evil.com".
|
|
68
|
+
# Also account for browsers normalizing `\` to `/`: https://github.com/advisories/GHSA-mqqf-5wvp-8fh8
|
|
69
|
+
return false if value.start_with?("//", "/\\", "\\/", "\\\\")
|
|
70
|
+
|
|
71
|
+
GoToParam.allowed_redirect_prefixes.any? { |prefix| value.start_with?(prefix) }
|
|
66
72
|
end
|
|
67
73
|
|
|
68
74
|
def go_to_here_path(anchor: nil, **additional_query_params)
|
metadata
CHANGED
|
@@ -1,78 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: go_to_param
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Henrik N
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
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.3'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.3'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rake
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '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: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
|
-
description:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
56
12
|
email:
|
|
57
13
|
- henrik@nyh.se
|
|
58
14
|
executables: []
|
|
59
15
|
extensions: []
|
|
60
16
|
extra_rdoc_files: []
|
|
61
17
|
files:
|
|
62
|
-
- ".gitignore"
|
|
63
18
|
- CHANGELOG.md
|
|
64
|
-
- Gemfile
|
|
65
19
|
- README.md
|
|
66
|
-
- Rakefile
|
|
67
|
-
- go_to_param.gemspec
|
|
68
20
|
- lib/go_to_param.rb
|
|
69
21
|
- lib/go_to_param/version.rb
|
|
70
|
-
- spec/go_to_param_spec.rb
|
|
71
22
|
homepage: ''
|
|
72
23
|
licenses:
|
|
73
24
|
- MIT
|
|
74
|
-
metadata:
|
|
75
|
-
|
|
25
|
+
metadata:
|
|
26
|
+
rubygems_mfa_required: 'true'
|
|
76
27
|
rdoc_options: []
|
|
77
28
|
require_paths:
|
|
78
29
|
- lib
|
|
@@ -87,9 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
38
|
- !ruby/object:Gem::Version
|
|
88
39
|
version: '0'
|
|
89
40
|
requirements: []
|
|
90
|
-
rubygems_version:
|
|
91
|
-
signing_key:
|
|
41
|
+
rubygems_version: 4.0.10
|
|
92
42
|
specification_version: 4
|
|
93
43
|
summary: Rails "go_to" redirection param utilities.
|
|
94
|
-
test_files:
|
|
95
|
-
- spec/go_to_param_spec.rb
|
|
44
|
+
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/go_to_param.gemspec
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require 'go_to_param/version'
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "go_to_param"
|
|
7
|
-
spec.version = GoToParam::VERSION
|
|
8
|
-
spec.authors = ["Henrik N"]
|
|
9
|
-
spec.email = ["henrik@nyh.se"]
|
|
10
|
-
spec.summary = %q{Rails "go_to" redirection param utilities.}
|
|
11
|
-
spec.homepage = ""
|
|
12
|
-
spec.license = "MIT"
|
|
13
|
-
|
|
14
|
-
spec.files = `git ls-files`.split($/)
|
|
15
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
16
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
17
|
-
spec.require_paths = ["lib"]
|
|
18
|
-
|
|
19
|
-
spec.add_development_dependency "bundler", ">= 1.3"
|
|
20
|
-
spec.add_development_dependency "rake"
|
|
21
|
-
spec.add_development_dependency "rspec"
|
|
22
|
-
end
|
data/spec/go_to_param_spec.rb
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
require_relative "../lib/go_to_param"
|
|
2
|
-
|
|
3
|
-
describe GoToParam do
|
|
4
|
-
let(:controller_klass) do
|
|
5
|
-
Class.new do
|
|
6
|
-
attr_accessor :params, :view_context, :request
|
|
7
|
-
|
|
8
|
-
def self.helper_method(*methods)
|
|
9
|
-
@helper_methods = methods
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.helper_methods
|
|
13
|
-
@helper_methods
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
include GoToParam
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
after { GoToParam.reset_allowed_redirect_prefixes }
|
|
21
|
-
|
|
22
|
-
let(:controller) { controller_klass.new }
|
|
23
|
-
|
|
24
|
-
describe "#hidden_go_to_tag" do
|
|
25
|
-
it "becomes a helper method" do
|
|
26
|
-
expect(controller_klass.helper_methods).to include :hidden_go_to_tag
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "adds a hidden field tag" do
|
|
30
|
-
controller.params = { go_to: "/example", id: "1" }
|
|
31
|
-
view = double
|
|
32
|
-
controller.view_context = view
|
|
33
|
-
|
|
34
|
-
expect(view).to receive(:hidden_field_tag).with(:go_to, "/example")
|
|
35
|
-
controller.hidden_go_to_tag
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe "#hidden_go_to_here_tag" do
|
|
40
|
-
it "becomes a helper method" do
|
|
41
|
-
expect(controller_klass.helper_methods).to include :hidden_go_to_here_tag
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "adds a hidden field tag" do
|
|
45
|
-
controller.request = double(get?: true, fullpath: "/example")
|
|
46
|
-
view = double
|
|
47
|
-
controller.view_context = view
|
|
48
|
-
|
|
49
|
-
expect(view).to receive(:hidden_field_tag).with(:go_to, "/example")
|
|
50
|
-
controller.hidden_go_to_here_tag
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Tested in more detail in #go_to_here_params.
|
|
54
|
-
it "accepts additional query parameters" do
|
|
55
|
-
controller.request = double(get?: true, fullpath: "/example?a=1")
|
|
56
|
-
view = double
|
|
57
|
-
controller.view_context = view
|
|
58
|
-
|
|
59
|
-
expect(view).to receive(:hidden_field_tag).with(:go_to, "/example?a=1&b=1+2")
|
|
60
|
-
controller.hidden_go_to_here_tag(b: "1 2")
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "#go_to_params" do
|
|
65
|
-
it "becomes a helper method" do
|
|
66
|
-
expect(controller_klass.helper_methods).to include :go_to_params
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "includes the go_to parameter" do
|
|
70
|
-
controller.params = { go_to: "/example", id: "1" }
|
|
71
|
-
|
|
72
|
-
expect(controller.go_to_params).to eq({ go_to: "/example" })
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "accepts additional parameters" do
|
|
76
|
-
controller.params = { go_to: "/example", id: "1" }
|
|
77
|
-
|
|
78
|
-
expect(controller.go_to_params(a: "b")).to eq({ go_to: "/example", a: "b" })
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
describe "#go_to_here_params" do
|
|
83
|
-
it "becomes a helper method" do
|
|
84
|
-
expect(controller_klass.helper_methods).to include :go_to_here_params
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "gets the request path as the go_to parameter" do
|
|
88
|
-
controller.request = double(get?: true, fullpath: "/example")
|
|
89
|
-
expect(controller.go_to_here_params).to eq({ go_to: "/example" })
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "returns an empty hash for a non-GET request" do
|
|
93
|
-
controller.request = double(get?: false, fullpath: "/example")
|
|
94
|
-
expect(controller.go_to_here_params).to eq({})
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "accepts additional query parameters" do
|
|
98
|
-
controller.request = double(get?: true, fullpath: "/example")
|
|
99
|
-
expect(controller.go_to_here_params(foo: "1 2", bar: 3)).to eq({ go_to: "/example?foo=1+2&bar=3" })
|
|
100
|
-
|
|
101
|
-
# Handles pre-existing "?"
|
|
102
|
-
controller.request = double(get?: true, fullpath: "/example?foo")
|
|
103
|
-
expect(controller.go_to_here_params(bar: 3)).to eq({ go_to: "/example?foo&bar=3" })
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "accepts an anchor parameter" do
|
|
107
|
-
controller.request = double(get?: true, fullpath: "/example")
|
|
108
|
-
expect(controller.go_to_here_params(foo: "foo", anchor: "bar")).to eq({ go_to: "/example?foo=foo#bar" })
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it "makes sure the go_to path is valid UTF-8" do
|
|
112
|
-
weird_path = "\xE0\x80\x80weird\330stuff".force_encoding("ASCII-8BIT")
|
|
113
|
-
replacement = "\uFFFD" # The Unicode "Replacement Character".
|
|
114
|
-
|
|
115
|
-
controller.request = double(get?: true, fullpath: weird_path)
|
|
116
|
-
|
|
117
|
-
go_to_value = controller.go_to_here_params[:go_to]
|
|
118
|
-
|
|
119
|
-
expect(go_to_value.encoding).to eq(Encoding::UTF_8)
|
|
120
|
-
expect(go_to_value).to eq("#{replacement}#{replacement}#{replacement}weird#{replacement}stuff")
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
describe "#go_to_path" do
|
|
125
|
-
it "becomes a helper method" do
|
|
126
|
-
expect(controller_klass.helper_methods).to include :go_to_path
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it "is the go_to parameter value" do
|
|
130
|
-
controller.params = { go_to: "/example", id: "1" }
|
|
131
|
-
expect(controller.go_to_path).to eq("/example")
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it "is nil if the parameter value is not a relative path" do
|
|
135
|
-
controller.params = { go_to: "http://evil.com", id: "1" }
|
|
136
|
-
expect(controller.go_to_path).to be_nil
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
it "is nil when given a hash" do
|
|
140
|
-
controller.params = { go_to: { evil: "true" }, id: "1" }
|
|
141
|
-
expect(controller.go_to_path).to be_nil
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
it "respects custom allowed redirect prefixes" do
|
|
145
|
-
GoToParam.allow_redirect_prefix("myapp://")
|
|
146
|
-
|
|
147
|
-
controller.params = { go_to: "myapp://", id: "1" }
|
|
148
|
-
expect(controller.go_to_path).to eq("myapp://")
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
describe "#go_to_path_or" do
|
|
153
|
-
it "becomes a helper method" do
|
|
154
|
-
expect(controller_klass.helper_methods).to include :go_to_path_or
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "is the go_to parameter value" do
|
|
158
|
-
controller.params = { go_to: "/example", id: "1" }
|
|
159
|
-
expect(controller.go_to_path_or("/default")).to eq("/example")
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
it "falls back if the go_to param is blank" do
|
|
163
|
-
controller.params = { go_to: "", id: "1" }
|
|
164
|
-
expect(controller.go_to_path_or("/default")).to eq("/default")
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it "falls back if the go_to param is not allowed" do
|
|
168
|
-
controller.params = { go_to: "http://evil.com", id: "1" }
|
|
169
|
-
expect(controller.go_to_path_or("/default")).to eq("/default")
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|