redirectr 1.0.5 → 1.0.6
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/README.md +26 -0
- data/app/helpers/redirectr/application_helper.rb +1 -1
- data/lib/redirectr/version.rb +1 -1
- data/lib/redirectr.rb +18 -7
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79b2022bb7a4aff997edf0f04e89276a17377b3a28c2fd33b071ce1314b13a9e
|
|
4
|
+
data.tar.gz: 4d271d1e980abeb41ef64cce2c227a1a31cb9bbd4f0e6e87859dc25c2606f55b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8bdcf8567203138565fbd36c2a991053b2f1b643a91e459d9df88185fb0719ecc20755001b0005841fbc258c33800eb9b8547776fab3c92d6ba11834786c67f
|
|
7
|
+
data.tar.gz: 7b7533058f982773d7431d337a64a1efb9aa69072fe065aa02b35629765d620d7cec936aa2dd1bf7742d4ebfdff8560b28ae6effd1c3d184b498ca646068948d
|
data/README.md
CHANGED
|
@@ -117,6 +117,20 @@ Referrer params can be nested, which is helpful if your workflow involves branch
|
|
|
117
117
|
|
|
118
118
|
NOTE: If your URLs include lots of params, it is very advisable to use Referrer Tokens instead of plain URLs to avoid "URI too long" errors. See next section.
|
|
119
119
|
|
|
120
|
+
### `current_url(anchor: ...)`
|
|
121
|
+
|
|
122
|
+
You can now pass an `anchor:` keyword to `current_url` to override the URL fragment.
|
|
123
|
+
This is useful when linking back to a specific position in a long list (e.g., after editing an item).
|
|
124
|
+
|
|
125
|
+
**Example:**
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
current_url(anchor: "item-42")
|
|
129
|
+
# => "/projects/7/tasks?filter=done#item-42"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
If no anchor is given, the current fragment is preserved (if any).
|
|
133
|
+
|
|
120
134
|
## Unvalidated Redirect Mitigation
|
|
121
135
|
|
|
122
136
|
Simply redirecting to an URI provided by HTTP params is considered a security vulnerability (see OWASP cheat sheet https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html). Earlier versions of redirectr did not take any potential issues into account, allowing all kinds of phishing attacs.
|
|
@@ -160,6 +174,18 @@ bundle exec rails db:migrate
|
|
|
160
174
|
|
|
161
175
|
Redirectr::ReferrerToken has two representations: #to_s displays the URL and #to_param its tokenized form. Depending on your config, this can be either a random token, an encrypted URL or the plaintext URL.
|
|
162
176
|
|
|
177
|
+
### Graceful Handling of Invalid Referrer Origins
|
|
178
|
+
|
|
179
|
+
Redirectr normally raises `Redirectr::InvalidReferrerToken` when the referrer’s origin (host/protocol/port) is not allowed. If you prefer to **treat such cases as if no referrer was provided**, enable:
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
YourApp::Application.configure do
|
|
183
|
+
config.x.redirectr.discard_referrer_on_invalid_origin = true
|
|
184
|
+
end
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
With this option, `referrer_url` returns `nil` for invalid origins rather than raising an exception, so any code using it naturally falls back to its own default handling.
|
|
188
|
+
|
|
163
189
|
## Contributions
|
|
164
190
|
|
|
165
191
|
Contributions like bugfixes and new ideas are more than welcome. Please just fork this project on github (https://github.com/wvk/redirectr) and send me a pull request with your changes.
|
|
@@ -12,7 +12,7 @@ module Redirectr
|
|
|
12
12
|
# Handy for use in forms that are called with a referrer param which
|
|
13
13
|
# has to be passed on and respected by the form processing action.
|
|
14
14
|
def hidden_referrer_input_tag(options = {})
|
|
15
|
-
hidden_field_tag :referrer,
|
|
15
|
+
hidden_field_tag :referrer, referrer_url.to_param, options
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
end
|
data/lib/redirectr/version.rb
CHANGED
data/lib/redirectr.rb
CHANGED
|
@@ -92,14 +92,23 @@ module Redirectr
|
|
|
92
92
|
#
|
|
93
93
|
# <%= link_to my_messages_url referrer_param => current_url %>
|
|
94
94
|
#
|
|
95
|
-
def current_url
|
|
96
|
-
if request.respond_to? :url # for rack >= 2.0.0
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
def current_url(anchor: nil)
|
|
96
|
+
url = if request.respond_to? :url # for rack >= 2.0.0
|
|
97
|
+
request.url
|
|
98
|
+
elsif request.respond_to? :original_url # for rails >= 4.0.0
|
|
99
|
+
request.original_url
|
|
100
|
+
else
|
|
101
|
+
request.env['REQUEST_URI']
|
|
102
|
+
end
|
|
103
|
+
if anchor
|
|
104
|
+
if anchor.is_a?(ActiveRecord::Base)
|
|
105
|
+
anchor = ActionView::RecordIdentifier.dom_id(anchor)
|
|
106
|
+
end
|
|
107
|
+
url = URI.parse(url.to_s)
|
|
108
|
+
url.fragment = anchor
|
|
109
|
+
url = url.to_s
|
|
102
110
|
end
|
|
111
|
+
ReferrerToken(url)
|
|
103
112
|
end
|
|
104
113
|
|
|
105
114
|
# Return the referrer or the current path, it the former is not set.
|
|
@@ -176,6 +185,8 @@ module Redirectr
|
|
|
176
185
|
referrer_token
|
|
177
186
|
elsif parsed_url.relative?
|
|
178
187
|
referrer_token
|
|
188
|
+
elsif Redirectr.config.discard_referrer_on_invalid_origin
|
|
189
|
+
nil
|
|
179
190
|
else
|
|
180
191
|
raise Redirectr::UrlNotInWhitelist, "#{parsed_url.inspect} - #{redirect_whitelist.inspect}"
|
|
181
192
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: redirectr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Willem van Kerkhof
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: rails
|
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
76
76
|
- !ruby/object:Gem::Version
|
|
77
77
|
version: '0'
|
|
78
78
|
requirements: []
|
|
79
|
-
rubygems_version: 3.6.
|
|
79
|
+
rubygems_version: 3.6.7
|
|
80
80
|
specification_version: 4
|
|
81
81
|
summary: Rails referrer-URL handling done right
|
|
82
82
|
test_files: []
|