devise_masquerade 2.1.5 → 2.1.7
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/.github/workflows/brakeman-analysis.yml +17 -11
- data/.github/workflows/rubocop-analysis.yml +35 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +1 -5
- data/lib/devise_masquerade/controllers/helpers.rb +29 -1
- data/lib/devise_masquerade/controllers/url_helpers.rb +14 -2
- data/lib/devise_masquerade/version.rb +1 -1
- data/spec/controllers/devise/masquerades_controller_spec.rb +42 -0
- data/spec/controllers/engine_url_helpers_spec.rb +38 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eed85ebd580e23aae13dd5fc8c1e39a8db73ea0dd0f2db8f89f227d30c5bd235
|
|
4
|
+
data.tar.gz: 8450c4c81e00d46a65a4c476e71a6fa0541adfde1cbaf8141c865e91ea103c2a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b49879aecc4794eb2fad2490a0a05e0b796d54fe1cc2874132688b35d263b7775d3c2b37cac813dbd4891e9c14573a25f064e0d2e7ac043b72787c518119c8d
|
|
7
|
+
data.tar.gz: e3fad85b45ac353dd6efc4cedcd38fca66ffbbb0beb2f1c37b89e137cbc47e9a1c480349209dbd1940f9d2632717123c18cdc7e0035ee8c1cad12d824a7543e5
|
|
@@ -3,42 +3,48 @@
|
|
|
3
3
|
|
|
4
4
|
name: Brakeman Scan
|
|
5
5
|
|
|
6
|
-
# This section configures the trigger for the workflow. Feel free to customize depending on your convention
|
|
7
6
|
on:
|
|
8
7
|
push:
|
|
9
8
|
branches: [ "master", "main" ]
|
|
10
9
|
pull_request:
|
|
11
10
|
branches: [ "master", "main" ]
|
|
12
11
|
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
13
15
|
jobs:
|
|
14
16
|
brakeman-scan:
|
|
15
17
|
name: Brakeman Scan
|
|
16
18
|
runs-on: ubuntu-latest
|
|
19
|
+
permissions:
|
|
20
|
+
contents: read
|
|
21
|
+
security-events: write
|
|
22
|
+
actions: read
|
|
17
23
|
steps:
|
|
18
|
-
# Checkout the repository to the GitHub Actions runner
|
|
19
24
|
- name: Checkout
|
|
20
25
|
uses: actions/checkout@v4
|
|
21
26
|
|
|
22
|
-
# Customize the ruby version depending on your needs
|
|
23
27
|
- name: Setup Ruby
|
|
24
28
|
uses: ruby/setup-ruby@v1
|
|
25
29
|
with:
|
|
26
30
|
ruby-version: '3.2'
|
|
27
31
|
|
|
28
32
|
- name: Setup Brakeman
|
|
29
|
-
|
|
30
|
-
BRAKEMAN_VERSION: '4.10' # SARIF support is provided in Brakeman version 4.10+
|
|
31
|
-
run: |
|
|
32
|
-
gem install brakeman --version $BRAKEMAN_VERSION
|
|
33
|
+
run: gem install brakeman
|
|
33
34
|
|
|
34
|
-
#
|
|
35
|
+
# Scan the dummy Rails app. The gem root is not a Rails application, so
|
|
36
|
+
# `brakeman .` exits before writing SARIF. --no-exit-on-warn/error keeps
|
|
37
|
+
# findings in the report instead of failing the job.
|
|
35
38
|
- name: Scan
|
|
36
|
-
continue-on-error: true
|
|
37
39
|
run: |
|
|
38
|
-
brakeman
|
|
40
|
+
brakeman --path spec/dummy \
|
|
41
|
+
-f sarif \
|
|
42
|
+
-o output.sarif.json \
|
|
43
|
+
--no-exit-on-warn \
|
|
44
|
+
--no-exit-on-error
|
|
39
45
|
|
|
40
|
-
# Upload the SARIF file generated in the previous step
|
|
41
46
|
- name: Upload SARIF
|
|
42
47
|
uses: github/codeql-action/upload-sarif@v4
|
|
43
48
|
with:
|
|
44
49
|
sarif_file: output.sarif.json
|
|
50
|
+
category: brakeman
|
|
@@ -2,9 +2,16 @@ name: "Rubocop"
|
|
|
2
2
|
|
|
3
3
|
on: push
|
|
4
4
|
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read
|
|
7
|
+
|
|
5
8
|
jobs:
|
|
6
9
|
rubocop:
|
|
7
10
|
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
security-events: write
|
|
14
|
+
actions: read
|
|
8
15
|
strategy:
|
|
9
16
|
fail-fast: false
|
|
10
17
|
|
|
@@ -12,16 +19,15 @@ jobs:
|
|
|
12
19
|
- name: Checkout repository
|
|
13
20
|
uses: actions/checkout@v4
|
|
14
21
|
|
|
15
|
-
# If running on a self-hosted runner, check it meets the requirements
|
|
16
|
-
# listed at https://github.com/ruby/setup-ruby#using-self-hosted-runners
|
|
17
22
|
- name: Set up Ruby
|
|
18
23
|
uses: ruby/setup-ruby@v1
|
|
19
24
|
with:
|
|
20
25
|
ruby-version: 3.2
|
|
21
26
|
|
|
22
|
-
#
|
|
27
|
+
# 0.6.1 maps last_column 0 to real_column; 0.3.0 emitted endColumn 0
|
|
28
|
+
# which github/codeql-action/upload-sarif@v4 rejects (must be >= 1).
|
|
23
29
|
- name: Install Code Scanning integration
|
|
24
|
-
run: bundle add code-scanning-rubocop --version 0.
|
|
30
|
+
run: bundle add code-scanning-rubocop --version 0.6.1 --skip-install
|
|
25
31
|
|
|
26
32
|
- name: Install dependencies
|
|
27
33
|
run: bundle install
|
|
@@ -33,7 +39,32 @@ jobs:
|
|
|
33
39
|
[[ $? -ne 2 ]]
|
|
34
40
|
"
|
|
35
41
|
|
|
42
|
+
- name: Normalize SARIF columns
|
|
43
|
+
run: |
|
|
44
|
+
python3 - <<'PY'
|
|
45
|
+
import json
|
|
46
|
+
from pathlib import Path
|
|
47
|
+
path = Path("rubocop.sarif")
|
|
48
|
+
data = json.loads(path.read_text())
|
|
49
|
+
|
|
50
|
+
def fix(node):
|
|
51
|
+
if isinstance(node, dict):
|
|
52
|
+
for key in ("startColumn", "endColumn"):
|
|
53
|
+
value = node.get(key)
|
|
54
|
+
if isinstance(value, int) and value < 1:
|
|
55
|
+
node[key] = 1
|
|
56
|
+
for value in node.values():
|
|
57
|
+
fix(value)
|
|
58
|
+
elif isinstance(node, list):
|
|
59
|
+
for item in node:
|
|
60
|
+
fix(item)
|
|
61
|
+
|
|
62
|
+
fix(data)
|
|
63
|
+
path.write_text(json.dumps(data))
|
|
64
|
+
PY
|
|
65
|
+
|
|
36
66
|
- name: Upload Sarif output
|
|
37
67
|
uses: github/codeql-action/upload-sarif@v4
|
|
38
68
|
with:
|
|
39
69
|
sarif_file: rubocop.sarif
|
|
70
|
+
category: rubocop
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
devise_masquerade (2.1.
|
|
4
|
+
devise_masquerade (2.1.7)
|
|
5
5
|
devise (>= 4.7.0)
|
|
6
6
|
globalid (>= 0.3.6)
|
|
7
7
|
railties (>= 5.2.0)
|
|
@@ -61,9 +61,6 @@ GEM
|
|
|
61
61
|
base64 (0.3.0)
|
|
62
62
|
bcrypt (3.1.22)
|
|
63
63
|
bigdecimal (4.1.3)
|
|
64
|
-
bson (1.12.5)
|
|
65
|
-
bson_ext (1.12.5)
|
|
66
|
-
bson (~> 1.12.5)
|
|
67
64
|
builder (3.3.0)
|
|
68
65
|
byebug (13.0.0)
|
|
69
66
|
reline (>= 0.6.0)
|
|
@@ -349,7 +346,6 @@ DEPENDENCIES
|
|
|
349
346
|
activerecord (>= 8.0.5.1)
|
|
350
347
|
addressable (>= 2.9.0)
|
|
351
348
|
bcrypt (>= 3.1.22)
|
|
352
|
-
bson_ext (~> 1.3)
|
|
353
349
|
bundler (>= 2.0.0)
|
|
354
350
|
capybara (>= 3.38.0)
|
|
355
351
|
chromedriver-helper
|
|
@@ -56,7 +56,7 @@ module DeviseMasquerade
|
|
|
56
56
|
if Devise.masquerade_storage_method_session?
|
|
57
57
|
resource_id = session[#{name}_helper_session_key]
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
masquerade_owner_class.find(resource_id)
|
|
60
60
|
else
|
|
61
61
|
sgid = ::Rails.cache.read(#{name}_helper_session_key)
|
|
62
62
|
|
|
@@ -130,6 +130,34 @@ module DeviseMasquerade
|
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
end
|
|
133
|
+
|
|
134
|
+
# The session stores the owner's id. Resolve that id against the owner
|
|
135
|
+
# model saved at masquerade time, not the model currently signed in.
|
|
136
|
+
# Only classes registered with Devise are accepted from the session.
|
|
137
|
+
def masquerade_owner_class
|
|
138
|
+
from_session = devise_class_for(session[session_key_masquerading_resource_class])
|
|
139
|
+
return from_session if from_session
|
|
140
|
+
|
|
141
|
+
if Devise.masquerading_resource_class_name.present?
|
|
142
|
+
devise_class_for(Devise.masquerading_resource_class_name) ||
|
|
143
|
+
Devise.masquerading_resource_class_name.constantize
|
|
144
|
+
elsif Devise.masquerading_resource_class
|
|
145
|
+
Devise.masquerading_resource_class
|
|
146
|
+
else
|
|
147
|
+
resource_class
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def devise_class_for(class_name)
|
|
152
|
+
return if class_name.blank?
|
|
153
|
+
|
|
154
|
+
Devise.mappings.each_value do |mapping|
|
|
155
|
+
return mapping.to if mapping.class_name == class_name.to_s
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
nil
|
|
159
|
+
end
|
|
160
|
+
private :masquerade_owner_class, :devise_class_for
|
|
133
161
|
end
|
|
134
162
|
end
|
|
135
163
|
end
|
|
@@ -12,7 +12,7 @@ module DeviseMasquerade
|
|
|
12
12
|
|
|
13
13
|
opts[Devise.masquerade_param] = resource.masquerade_key
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
masquerade_route_helper("#{scope}_masquerade_index_path", opts, *args)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def back_masquerade_path(resource, *args)
|
|
@@ -21,7 +21,19 @@ module DeviseMasquerade
|
|
|
21
21
|
opts = args.first || {}
|
|
22
22
|
opts[:masqueraded_resource_class] = resource.class.name
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
masquerade_route_helper("back_#{scope}_masquerade_index_path", opts, *args)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# Inside a mounted engine the route helpers are the engine's, not the
|
|
30
|
+
# host app's where the masquerade routes live. Fall back to main_app.
|
|
31
|
+
def masquerade_route_helper(name, *args)
|
|
32
|
+
if !respond_to?(name, true) && respond_to?(:main_app)
|
|
33
|
+
main_app.public_send(name, *args)
|
|
34
|
+
else
|
|
35
|
+
send(name, *args)
|
|
36
|
+
end
|
|
25
37
|
end
|
|
26
38
|
end
|
|
27
39
|
|
|
@@ -109,6 +109,48 @@ describe Devise::MasqueradesController, type: :controller do
|
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
describe 'masquerade owner across different models' do
|
|
113
|
+
let(:owner) { create(:user) }
|
|
114
|
+
let(:mask) do
|
|
115
|
+
student = create(:student)
|
|
116
|
+
student.update_column(:id, owner.id)
|
|
117
|
+
Student.find(owner.id)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
before do
|
|
121
|
+
@request.env['devise.mapping'] = Devise.mappings[:user]
|
|
122
|
+
sign_in(owner)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def masquerade_as_student
|
|
126
|
+
get :show, params: {
|
|
127
|
+
id: mask.id,
|
|
128
|
+
masqueraded_resource_class: 'Student',
|
|
129
|
+
masquerade: mask.masquerade_key
|
|
130
|
+
}
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'with session storage' do
|
|
134
|
+
before { Devise.masquerade_storage_method = :session }
|
|
135
|
+
|
|
136
|
+
it 'returns the masquerading user instead of the masqueraded record that shares the id' do
|
|
137
|
+
masquerade_as_student
|
|
138
|
+
|
|
139
|
+
expect(controller.send(:student_masquerade_owner)).to eq(owner)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
context 'with cache storage' do
|
|
144
|
+
before { Devise.masquerade_storage_method = :cache }
|
|
145
|
+
|
|
146
|
+
it 'returns the masquerading user from the signed global id' do
|
|
147
|
+
masquerade_as_student
|
|
148
|
+
|
|
149
|
+
expect(controller.send(:student_masquerade_owner)).to eq(owner)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
112
154
|
# it's a page with masquerade button ("Login As")
|
|
113
155
|
def masquerade_page
|
|
114
156
|
"/"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module EngineUrlHelpersSpec
|
|
4
|
+
class Engine < ::Rails::Engine
|
|
5
|
+
isolate_namespace EngineUrlHelpersSpec
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class PagesController < ActionController::Base
|
|
9
|
+
def show
|
|
10
|
+
render inline: '<%= raw masquerade_path(User.first) %>|<%= raw back_masquerade_path(User.first) %>'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
EngineUrlHelpersSpec::Engine.routes.draw { get '/page', to: 'pages#show' }
|
|
16
|
+
|
|
17
|
+
describe EngineUrlHelpersSpec::PagesController, type: :controller do
|
|
18
|
+
routes { EngineUrlHelpersSpec::Engine.routes }
|
|
19
|
+
render_views
|
|
20
|
+
|
|
21
|
+
let!(:user) { create(:user) }
|
|
22
|
+
|
|
23
|
+
it 'builds masquerade paths from inside a mounted engine' do
|
|
24
|
+
get :show
|
|
25
|
+
|
|
26
|
+
masquerade, back = response.body.split('|')
|
|
27
|
+
routes = Rails.application.routes.url_helpers
|
|
28
|
+
|
|
29
|
+
# The masquerade key is signed with an expiry, so compare the path and params, not the token.
|
|
30
|
+
uri = URI.parse(masquerade)
|
|
31
|
+
params = Rack::Utils.parse_query(uri.query)
|
|
32
|
+
expect(uri.path).to eq(routes.user_masquerade_index_path)
|
|
33
|
+
expect(params['masquerade']).to be_present
|
|
34
|
+
expect(params['masqueraded_resource_class']).to eq('User')
|
|
35
|
+
|
|
36
|
+
expect(back).to eq(routes.back_user_masquerade_index_path(masqueraded_resource_class: 'User'))
|
|
37
|
+
end
|
|
38
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: devise_masquerade
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexandr Korsak
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -113,6 +113,7 @@ files:
|
|
|
113
113
|
- spec/controllers/admin/dashboard_controller_spec.rb
|
|
114
114
|
- spec/controllers/dashboard_controller_spec.rb
|
|
115
115
|
- spec/controllers/devise/masquerades_controller_spec.rb
|
|
116
|
+
- spec/controllers/engine_url_helpers_spec.rb
|
|
116
117
|
- spec/controllers/masquerades_tests_controller_spec.rb
|
|
117
118
|
- spec/dummy/Rakefile
|
|
118
119
|
- spec/dummy/app/controllers/admin/dashboard_controller.rb
|
|
@@ -198,6 +199,7 @@ test_files:
|
|
|
198
199
|
- spec/controllers/admin/dashboard_controller_spec.rb
|
|
199
200
|
- spec/controllers/dashboard_controller_spec.rb
|
|
200
201
|
- spec/controllers/devise/masquerades_controller_spec.rb
|
|
202
|
+
- spec/controllers/engine_url_helpers_spec.rb
|
|
201
203
|
- spec/controllers/masquerades_tests_controller_spec.rb
|
|
202
204
|
- spec/dummy/Rakefile
|
|
203
205
|
- spec/dummy/app/controllers/admin/dashboard_controller.rb
|