Commit 659b641c authored by Ryan Cobb's avatar Ryan Cobb

Use tracing external_url for frame_src csp

parent 53047ee0
...@@ -4,7 +4,9 @@ class Projects::TracingsController < Projects::ApplicationController ...@@ -4,7 +4,9 @@ class Projects::TracingsController < Projects::ApplicationController
content_security_policy do |p| content_security_policy do |p|
next if p.directives.blank? next if p.directives.blank?
p.frame_src("*") global_frame_src = p.frame_src
p.frame_src -> { frame_src_csp_policy(global_frame_src) }
end end
before_action :check_license before_action :check_license
...@@ -18,4 +20,10 @@ class Projects::TracingsController < Projects::ApplicationController ...@@ -18,4 +20,10 @@ class Projects::TracingsController < Projects::ApplicationController
def check_license def check_license
render_404 unless @project.feature_available?(:tracing, current_user) render_404 unless @project.feature_available?(:tracing, current_user)
end end
def frame_src_csp_policy(global_frame_src)
external_url = @project&.tracing_setting&.external_url
external_url.presence || global_frame_src
end
end end
...@@ -31,7 +31,7 @@ describe 'Tracings Content Security Policy' do ...@@ -31,7 +31,7 @@ describe 'Tracings Content Security Policy' do
context 'when a global CSP config exists' do context 'when a global CSP config exists' do
before do before do
csp = ActionDispatch::ContentSecurityPolicy.new do |p| csp = ActionDispatch::ContentSecurityPolicy.new do |p|
p.frame_src :self, 'https://should-get-overwritten.com' p.frame_src 'https://global-policy.com'
end end
expect_next_instance_of(Projects::TracingsController) do |controller| expect_next_instance_of(Projects::TracingsController) do |controller|
...@@ -39,10 +39,22 @@ describe 'Tracings Content Security Policy' do ...@@ -39,10 +39,22 @@ describe 'Tracings Content Security Policy' do
end end
end end
it 'overwrites frame-src' do context 'when external_url is set' do
visit project_tracing_path(project) let!(:project_tracing_setting) { create(:project_tracing_setting, project: project) }
it 'overwrites frame-src' do
visit project_tracing_path(project)
is_expected.to eq("frame-src *") is_expected.to eq("frame-src https://example.com")
end
end
context 'when external_url is not set' do
it 'uses global policy' do
visit project_tracing_path(project)
is_expected.to eq("frame-src https://global-policy.com")
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment