2017-03-15 16:09:08 -04:00
|
|
|
# ImportableUrlValidator
|
|
|
|
#
|
|
|
|
# This validator blocks projects from using dangerous import_urls to help
|
|
|
|
# protect against Server-side Request Forgery (SSRF).
|
|
|
|
class ImportableUrlValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
2018-04-02 11:13:47 -04:00
|
|
|
Gitlab::UrlBlocker.validate!(value, valid_ports: Project::VALID_IMPORT_PORTS)
|
|
|
|
rescue Gitlab::UrlBlocker::BlockedUrlError => e
|
|
|
|
record.errors.add(attribute, "is blocked: #{e.message}")
|
2017-03-15 16:09:08 -04:00
|
|
|
end
|
|
|
|
end
|