Skip to content
Snippets Groups Projects
Commit 537eb0bb authored by Francisco Javier López's avatar Francisco Javier López Committed by Thong Kuah
Browse files

Avoid checking dns rebind protection in validation

parent 8d93ec2e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -42,6 +42,11 @@
class AddressableUrlValidator < ActiveModel::EachValidator
attr_reader :record
 
# By default, we avoid checking the dns rebinding protection
# when saving/updating a record. Sometimes, the url
# is not resolvable at that point, and some automated
# tasks that uses that url won't work.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/66723
BLOCKER_VALIDATE_OPTIONS = {
schemes: %w(http https),
ports: [],
Loading
Loading
@@ -49,7 +54,8 @@ class AddressableUrlValidator < ActiveModel::EachValidator
allow_local_network: true,
ascii_only: false,
enforce_user: false,
enforce_sanitization: false
enforce_sanitization: false,
dns_rebind_protection: false
}.freeze
 
DEFAULT_OPTIONS = BLOCKER_VALIDATE_OPTIONS.merge({
Loading
Loading
---
title: Avoid checking dns rebind protection when validating
merge_request: 32577
author:
type: fixed
Loading
Loading
@@ -92,6 +92,15 @@
expect(badge.errors).to be_empty
expect(badge.link_url).to eq('https://127.0.0.1')
end
it 'allows urls that cannot be resolved' do
stub_env('RSPEC_ALLOW_INVALID_URLS', 'false')
badge.link_url = 'http://foobar.x'
subject
expect(badge.errors).to be_empty
end
end
 
context 'when message is set' do
Loading
Loading
@@ -312,4 +321,32 @@
end
end
end
context 'when dns_rebind_protection is' do
let(:not_resolvable_url) { 'http://foobar.x' }
let(:validator) { described_class.new(attributes: [:link_url], dns_rebind_protection: dns_value) }
before do
stub_env('RSPEC_ALLOW_INVALID_URLS', 'false')
badge.link_url = not_resolvable_url
subject
end
context 'true' do
let(:dns_value) { true }
it 'raises error' do
expect(badge.errors).to be_present
end
end
context 'false' do
let(:dns_value) { false }
it 'allows urls that cannot be resolved' do
expect(badge.errors).to be_empty
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment