Class: Packages::SsrfProtection

Inherits:
Object
  • Object
show all
Defined in:
lib/packages/ssrf_protection.rb

Class Method Summary collapse

Class Method Details

.allow_localhost?Boolean



16
17
18
# File 'lib/packages/ssrf_protection.rb', line 16

def self.allow_localhost?
  Gitlab.dev_or_test_env? || Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end

.package_feature_enabled?(package) ⇒ Boolean



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/packages/ssrf_protection.rb', line 20

def self.package_feature_enabled?(package)
  case package.package_type.to_sym
  when :generic
    Feature.enabled?(:generic_package_registry_ssrf_protection, package.project)
  # Future package types can be added here
  # when :npm
  #   Feature.enabled?(:npm_package_registry_ssrf_protection, package.project)
  else
    false
  end
end

.params_for(package) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/packages/ssrf_protection.rb', line 5

def self.params_for(package)
  return {} unless package
  return {} unless package_feature_enabled?(package)

  {
    ssrf_filter: true,
    allow_localhost: allow_localhost?,
    allowed_endpoints: ObjectStoreSettings.enabled_endpoint_uris
  }
end