Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

use validate_url gem to fully validate host url

Christophe Bliard69d54397aa88
diff --git a/Gemfile b/Gemfile
index befdfc6264f..b6bc6007311 100644
--- a/Gemfile
+++ b/Gemfile
@@ -186,6 +186,8 @@ gem 'ruby-progressbar', '~> 1.11.0', require: false
gem 'mini_magick', '~> 4.11.0', require: false
+gem 'validate_url'
+
# Sentry error reporting, loaded on demand
group :sentry do
gem "sentry-delayed_job", '~> 5.1.0', require: false
diff --git a/Gemfile.lock b/Gemfile.lock
index 7517e10840c..667f0b7cff2 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1137,6 +1137,7 @@ DEPENDENCIES
timecop (~> 0.9.0)
typed_dag (~> 2.0.2)
tzinfo-data (~> 1.2021.1)
+ validate_url
warden (~> 1.2)
warden-basic_auth (~> 0.2.1)
webdrivers (~> 5.0.0)
diff --git a/modules/storages/app/contracts/storages/storages/base_contract.rb b/modules/storages/app/contracts/storages/storages/base_contract.rb
index 81d2f52ec64..e85aa889381 100644
--- a/modules/storages/app/contracts/storages/storages/base_contract.rb
+++ b/modules/storages/app/contracts/storages/storages/base_contract.rb
@@ -51,12 +51,11 @@ module Storages::Storages
end
attribute :host
- validates :host, length: { minimum: 1, maximum: 255 }, allow_nil: false
- validates_url :host
+ validates :host, url: true
# Check that a host actually is a storage server.
# But only do so if the validations above for URL were successful.
- validate :validate_host_reachable, if: -> { errors[:host].empty? }
+ validate :validate_host_reachable, unless: -> { errors.include?(:host) }
def validate_creator_is_user
unless creator == user