redirectr 1.0.2 → 1.0.3
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 +4 -8
- data/lib/redirectr/referrer_token/active_record_storage.rb +28 -0
- data/lib/redirectr/referrer_token/global_var_storage.rb +26 -0
- data/lib/redirectr/referrer_token.rb +73 -0
- data/lib/redirectr/version.rb +1 -1
- data/lib/redirectr.rb +3 -115
- metadata +9 -13
- data/app/assets/config/redirectr_manifest.js +0 -2
- data/app/assets/javascripts/redirectr/application.js +0 -13
- data/app/assets/stylesheets/redirectr/application.css +0 -15
- data/app/controllers/redirectr/application_controller.rb +0 -5
- data/app/jobs/redirectr/application_job.rb +0 -4
- data/app/models/redirectr/application_record.rb +0 -5
- data/app/views/layouts/redirectr/application.html.erb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aab12433022382d5fc61e4964d815430d39cf08aec7b6bbc32672065fdf7d115
|
4
|
+
data.tar.gz: 54b286ec8bc69898564184f1d2488189b3523f0da279d8d61b0ac3cd7444176a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96332b3a061883e9b49881d74d1a54475f2850f4b9952404c5bf7bc2e478fc698c3e0097b5ea2cc53075274632249f34d80e390b2692ff95936c309065c04eb1
|
7
|
+
data.tar.gz: 582e0f5a9a7175068924b6d5dec1d7ef2044b14b6c935861d35dc555302cfd461317425ea69e913fa92c46be903d185753e2f925fe2130247da156008c8cba25
|
data/README.md
CHANGED
@@ -123,6 +123,9 @@ By default, Redirectr checks the protocol, hostname and port of the referrer aga
|
|
123
123
|
|
124
124
|
Instead of using a URL in the referrer token, redirectr can act as an URL shortener that maps random tokens to URLs. This requires a storage_implementation to be defined:
|
125
125
|
|
126
|
+
|
127
|
+
require 'redirectr/referrer_token/active_record_storage'
|
128
|
+
|
126
129
|
YourApp::Application.configure do
|
127
130
|
config.x.redirectr.use_referrer_token = true
|
128
131
|
config.x.redirectr.reuse_tokens = true # set to false to generate a new token for each and every link
|
@@ -145,13 +148,6 @@ Thanks so far to:
|
|
145
148
|
* Falk Hoppe for Rails 2.3.x interoperability
|
146
149
|
* Dimitar Haralanov for Rails 3.0.x interoperability
|
147
150
|
* Raffael Schmid for spotting a typo in the gemspec description ;)
|
148
|
-
|
149
|
-
## Changelog
|
150
|
-
|
151
|
-
* 1.0.0: Validate Redirect urls against whitelist; Allow Token instead of URL referrer param
|
152
|
-
* 0.1.1: deprecate *_path methods; improve Rails 5 compatibility by removing `alias` in view helpers
|
153
|
-
* 0.1.0: Use absolute URI instead of path in current_path method
|
154
|
-
* 0.0.8: Use ActiveSupport::Concern (Thanks to Dimitar Haralanov)
|
155
|
-
* 0.0.7: Add Rails 3.0 compatibility (Thanks to Falk Hoppe)
|
151
|
+
* Till Schulte-Coerne for removing implicit dependencies and cleaning up unused code
|
156
152
|
|
157
153
|
Copyright (c) 2010 Willem van Kerkhof <wvk@consolving.de>, released under the MIT license
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Redirectr
|
2
|
+
class ReferrerToken
|
3
|
+
|
4
|
+
# this is a stora implementation for activerecord-
|
5
|
+
class ActiveRecordStorage < ActiveRecord::Base
|
6
|
+
validates_presence_of :url, :token
|
7
|
+
|
8
|
+
self.table_name = :redirectr_referrer_tokens
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def store(record)
|
12
|
+
self.find_or_create_by url: record.url, token: record.token
|
13
|
+
record.url
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch(token)
|
17
|
+
url = self.find_by(token: token)&.url
|
18
|
+
ReferrerToken(url) if url
|
19
|
+
end
|
20
|
+
|
21
|
+
def token_for_url(url)
|
22
|
+
self.find_by(url: url)&.token
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Redirectr
|
2
|
+
class ReferrerToken
|
3
|
+
|
4
|
+
class GlobalVarStorage
|
5
|
+
|
6
|
+
def persisted?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def store(record)
|
12
|
+
$referrer_lookup[record.token] = record.url
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch(token)
|
16
|
+
ReferrerToken($referrer_lookup[token])
|
17
|
+
end
|
18
|
+
|
19
|
+
def token_for_url(url)
|
20
|
+
$referrer_lookup.key(url)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module Redirectr
|
4
|
+
class ReferrerToken
|
5
|
+
|
6
|
+
extend ActiveModel::Naming
|
7
|
+
|
8
|
+
attr_reader :url, :token
|
9
|
+
|
10
|
+
def initialize(url, token=nil)
|
11
|
+
@url = url
|
12
|
+
@token = token
|
13
|
+
|
14
|
+
if Redirectr.config.use_referrer_token
|
15
|
+
if Redirectr.config.storage_implementation.nil?
|
16
|
+
raise "Missing storage implementation for referrer tokens! please define config.x.redirectr.storage_implementation"
|
17
|
+
end
|
18
|
+
|
19
|
+
if Redirectr.config.reuse_tokens
|
20
|
+
@token ||= Redirectr.config.storage_implementation.token_for_url(url)
|
21
|
+
end
|
22
|
+
@token ||= SecureRandom.hex(16)
|
23
|
+
elsif Redirectr.config.encrypt_referrer
|
24
|
+
@token ||= self.class.cryptr.encrypt_and_sign url
|
25
|
+
else
|
26
|
+
@token ||= url
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_param
|
31
|
+
@token
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_model
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
@url
|
40
|
+
end
|
41
|
+
|
42
|
+
def persisted?
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
def save
|
47
|
+
if Redirectr.config.use_referrer_token
|
48
|
+
Redirectr.config.storage_implementation.store self
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.from_param(param)
|
53
|
+
if Redirectr.config.encrypt_referrer
|
54
|
+
ReferrerToken.new self.class.cryptr.decrypt_and_verify param
|
55
|
+
elsif Redirectr.config.use_referrer_token
|
56
|
+
self.lookup(param)
|
57
|
+
else
|
58
|
+
ReferrerToken.new param
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.lookup(token)
|
63
|
+
Redirectr.config.storage_implementation.fetch token
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def self.cryptr
|
69
|
+
@cryptr ||= ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/lib/redirectr/version.rb
CHANGED
data/lib/redirectr.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require 'redirectr/engine'
|
2
1
|
require 'securerandom'
|
3
2
|
|
3
|
+
require 'redirectr/engine'
|
4
|
+
require 'redirectr/referrer_token'
|
5
|
+
|
4
6
|
def ReferrerToken(url, token=nil)
|
5
7
|
case url
|
6
8
|
when Redirectr::ReferrerToken
|
@@ -30,120 +32,6 @@ module Redirectr
|
|
30
32
|
Rails.configuration.x.redirectr
|
31
33
|
end
|
32
34
|
|
33
|
-
class ReferrerToken
|
34
|
-
extend ActiveModel::Naming
|
35
|
-
|
36
|
-
# this is a stora implementation for activerecord-
|
37
|
-
class ActiveRecordStorage < ActiveRecord::Base
|
38
|
-
validates_presence_of :url, :token
|
39
|
-
|
40
|
-
self.table_name = :redirectr_referrer_tokens
|
41
|
-
|
42
|
-
class << self
|
43
|
-
def store(record)
|
44
|
-
self.find_or_create_by url: record.url, token: record.token
|
45
|
-
record.url
|
46
|
-
end
|
47
|
-
|
48
|
-
def fetch(token)
|
49
|
-
url = self.find_by(token: token)&.url
|
50
|
-
ReferrerToken(url) if url
|
51
|
-
end
|
52
|
-
|
53
|
-
def token_for_url(url)
|
54
|
-
self.find_by(url: url)&.token
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class GlobalVarStorage
|
60
|
-
extend ActiveModel::Naming
|
61
|
-
|
62
|
-
def persisted?
|
63
|
-
false
|
64
|
-
end
|
65
|
-
|
66
|
-
class << self
|
67
|
-
def store(record)
|
68
|
-
$referrer_lookup[record.token] = record.url
|
69
|
-
end
|
70
|
-
|
71
|
-
def fetch(token)
|
72
|
-
ReferrerToken($referrer_lookup[token])
|
73
|
-
end
|
74
|
-
|
75
|
-
def token_for_url(url)
|
76
|
-
$referrer_lookup.key(url)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
attr_reader :url, :token
|
82
|
-
|
83
|
-
def initialize(url, token=nil)
|
84
|
-
@url = url
|
85
|
-
@token = token
|
86
|
-
|
87
|
-
if Redirectr.config.use_referrer_token
|
88
|
-
if Redirectr.config.storage_implementation.nil?
|
89
|
-
raise "Missing storage implementation for referrer tokens! please define config.x.redirectr.storage_implementation"
|
90
|
-
end
|
91
|
-
|
92
|
-
if Redirectr.config.reuse_tokens
|
93
|
-
@token ||= Redirectr.config.storage_implementation.token_for_url(url)
|
94
|
-
end
|
95
|
-
@token ||= SecureRandom.hex(16)
|
96
|
-
elsif Redirectr.config.encrypt_referrer
|
97
|
-
@token ||= self.class.cryptr.encrypt_and_sign url
|
98
|
-
else
|
99
|
-
@token ||= url
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def to_param
|
104
|
-
@token
|
105
|
-
end
|
106
|
-
|
107
|
-
def to_model
|
108
|
-
self
|
109
|
-
end
|
110
|
-
|
111
|
-
def to_s
|
112
|
-
@url
|
113
|
-
end
|
114
|
-
|
115
|
-
def persisted?
|
116
|
-
true
|
117
|
-
end
|
118
|
-
|
119
|
-
def save
|
120
|
-
if Redirectr.config.use_referrer_token
|
121
|
-
Redirectr.config.storage_implementation.store self
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.from_param(param)
|
126
|
-
if Redirectr.config.encrypt_referrer
|
127
|
-
ReferrerToken.new self.class.cryptr.decrypt_and_verify param
|
128
|
-
elsif Redirectr.config.use_referrer_token
|
129
|
-
self.lookup(param)
|
130
|
-
else
|
131
|
-
ReferrerToken.new param
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def self.lookup(token)
|
136
|
-
Redirectr.config.storage_implementation.fetch token
|
137
|
-
end
|
138
|
-
|
139
|
-
private
|
140
|
-
|
141
|
-
def self.cryptr
|
142
|
-
@cryptr ||= ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
35
|
module ControllerMethods
|
148
36
|
extend ActiveSupport::Concern
|
149
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Kerkhof
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -49,25 +49,21 @@ files:
|
|
49
49
|
- MIT-LICENSE
|
50
50
|
- README.md
|
51
51
|
- Rakefile
|
52
|
-
- app/assets/config/redirectr_manifest.js
|
53
|
-
- app/assets/javascripts/redirectr/application.js
|
54
|
-
- app/assets/stylesheets/redirectr/application.css
|
55
|
-
- app/controllers/redirectr/application_controller.rb
|
56
52
|
- app/helpers/redirectr/application_helper.rb
|
57
|
-
- app/jobs/redirectr/application_job.rb
|
58
|
-
- app/models/redirectr/application_record.rb
|
59
|
-
- app/views/layouts/redirectr/application.html.erb
|
60
53
|
- config/routes.rb
|
61
54
|
- db/migrate/20201120110532_create_redirectr_referrer_tokens.rb
|
62
55
|
- lib/redirectr.rb
|
63
56
|
- lib/redirectr/engine.rb
|
57
|
+
- lib/redirectr/referrer_token.rb
|
58
|
+
- lib/redirectr/referrer_token/active_record_storage.rb
|
59
|
+
- lib/redirectr/referrer_token/global_var_storage.rb
|
64
60
|
- lib/redirectr/version.rb
|
65
61
|
- lib/tasks/redirectr_tasks.rake
|
66
62
|
homepage: http://github.com/wvk/redirectr
|
67
63
|
licenses:
|
68
64
|
- MIT
|
69
65
|
metadata: {}
|
70
|
-
post_install_message:
|
66
|
+
post_install_message:
|
71
67
|
rdoc_options: []
|
72
68
|
require_paths:
|
73
69
|
- lib
|
@@ -82,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
78
|
- !ruby/object:Gem::Version
|
83
79
|
version: '0'
|
84
80
|
requirements: []
|
85
|
-
rubygems_version: 3.
|
86
|
-
signing_key:
|
81
|
+
rubygems_version: 3.3.15
|
82
|
+
signing_key:
|
87
83
|
specification_version: 4
|
88
84
|
summary: Rails referrer-URL handling done right
|
89
85
|
test_files: []
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
-
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
-
* It is generally better to create a new file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,16 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Redirectr</title>
|
5
|
-
<%= csrf_meta_tags %>
|
6
|
-
<%= csp_meta_tag %>
|
7
|
-
|
8
|
-
<%= stylesheet_link_tag "redirectr/application", media: "all" %>
|
9
|
-
<%= javascript_include_tag "redirectr/application" %>
|
10
|
-
</head>
|
11
|
-
<body>
|
12
|
-
|
13
|
-
<%= yield %>
|
14
|
-
|
15
|
-
</body>
|
16
|
-
</html>
|