Commit 30886a18 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC

Check access to instance-level vulnerability export APIs

We restrict access to these endpoints if the `security_dashboard`
feature is not available.
parent f1d253c1
# frozen_string_literal: true # frozen_string_literal: true
class InstanceSecurityDashboardPolicy < BasePolicy class InstanceSecurityDashboardPolicy < BasePolicy
rule { ~anonymous }.policy do with_scope :global
enable :read_instance_security_dashboard condition(:security_dashboard_enabled) do
enable :create_vulnerability_export License.feature_available?(:security_dashboard)
end end
rule { ~anonymous }.enable :read_instance_security_dashboard
rule { security_dashboard_enabled & can?(:read_instance_security_dashboard) }.enable :create_vulnerability_export
end end
...@@ -53,18 +53,24 @@ module API ...@@ -53,18 +53,24 @@ module API
end end
end end
params do namespace do
optional :export_format, type: String, desc: 'The format of export to be generated', before do
default: ::Vulnerabilities::Export.formats.each_key.first, not_found! unless Feature.enabled?(:first_class_vulnerabilities)
values: ::Vulnerabilities::Export.formats.keys end
end
desc 'Generate an instance level export' do params do
success EE::API::Entities::VulnerabilityExport optional :export_format, type: String, desc: 'The format of export to be generated',
end default: ::Vulnerabilities::Export.formats.each_key.first,
post 'vulnerability_exports' do values: ::Vulnerabilities::Export.formats.keys
authorize! :create_vulnerability_export, current_user.security_dashboard end
desc 'Generate an instance level export' do
success EE::API::Entities::VulnerabilityExport
end
post 'vulnerability_exports' do
authorize! :create_vulnerability_export, current_user.security_dashboard
process_create_request_for(current_user.security_dashboard) process_create_request_for(current_user.security_dashboard)
end
end end
desc 'Get single project vulnerability export' do desc 'Get single project vulnerability export' do
......
...@@ -118,6 +118,8 @@ describe API::VulnerabilityExports do ...@@ -118,6 +118,8 @@ describe API::VulnerabilityExports do
end end
end end
end end
it_behaves_like 'forbids access to vulnerability API endpoint in case of disabled features'
end end
describe 'GET /security/vulnerability_exports/:id' do describe 'GET /security/vulnerability_exports/:id' do
......
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