Skip to content

Commit f311ab6

Browse files
authored
Merge pull request #3213 from AlchemyCMS/backport/7.4-stable/pr-3212
[7.4-stable] Allow is_safe_redirect_path to recognize customized admin path
2 parents 338fc73 + dfa13ee commit f311ab6

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

app/controllers/alchemy/admin/base_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def safe_redirect_path(path = params[:redirect_to], fallback: admin_path)
4343

4444
def is_safe_redirect_path?(path)
4545
mount_path = alchemy.root_path
46-
path.to_s.match? %r{^#{mount_path}admin/}
46+
path.to_s.match? %r{^#{mount_path}#{Alchemy.admin_path}/}
4747
end
4848

4949
def relative_referer_path(referer = request.referer)

spec/controllers/alchemy/admin/base_controller_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,57 @@ def index
338338
it { is_expected.to be(false) }
339339
end
340340
end
341+
342+
context "admin path is customized" do
343+
before(:all) do
344+
Alchemy.admin_path = "backend"
345+
Rails.application.reload_routes!
346+
end
347+
348+
context "path is not an external URL" do
349+
let(:path) { "/backend/pages" }
350+
351+
it { is_expected.to be(true) }
352+
end
353+
354+
context "path is an external URL" do
355+
let(:path) { "https://evil.com" }
356+
357+
it { is_expected.to be(false) }
358+
end
359+
360+
after(:all) do
361+
Alchemy.admin_path = "admin"
362+
Rails.application.reload_routes!
363+
end
364+
end
365+
366+
context "admin path is customized and alchemy is mounted under a path" do
367+
before do
368+
Alchemy.admin_path = "backend"
369+
Rails.application.reload_routes!
370+
371+
allow(controller).to receive(:alchemy) do
372+
double(root_path: "/cms/")
373+
end
374+
end
375+
376+
context "path is not an external URL" do
377+
let(:path) { "/cms/backend/pages" }
378+
379+
it { is_expected.to be(true) }
380+
end
381+
382+
context "path is an external URL" do
383+
let(:path) { "https://evil.com" }
384+
385+
it { is_expected.to be(false) }
386+
end
387+
388+
after do
389+
Alchemy.admin_path = "admin"
390+
Rails.application.reload_routes!
391+
end
392+
end
341393
end
342394
end

0 commit comments

Comments
 (0)