From ca42d5601330777e109f54683d4fc1a20444e82b Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 27 Aug 2026 10:42:07 -0400 Subject: [PATCH] feat: adds support for wildcard host validation --- .../authentication/allowed_hosts_validator.rb | 5 +++- .../spec/microsoft_kiota_abstractions_spec.rb | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb index f912e51..4438611 100644 --- a/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb +++ b/components/abstractions/lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb @@ -27,7 +27,10 @@ def url_host_valid?(url) return false unless parsed_url.is_a?(URI::HTTPS) - @allowed_hosts.key? parsed_url.host.downcase + hostname = parsed_url.host.downcase + return true if @allowed_hosts.key? hostname + + @allowed_hosts.any? { |allowed_host, _| allowed_host.start_with?('.') && hostname.end_with?(allowed_host) } rescue URI::InvalidURIError false end diff --git a/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb b/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb index 2a4e562..29af336 100644 --- a/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb +++ b/components/abstractions/spec/microsoft_kiota_abstractions_spec.rb @@ -153,6 +153,31 @@ expect(url6).to eq(false) end + it 'returns true for subdomain matching allowed suffix' do + ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['.fabric.microsoft.com']) + + expect(ahv.url_host_valid?('https://abc.123.graphql.fabric.microsoft.com/path')).to eq(true) + end + + it 'returns false for bare domain when allowed as suffix' do + ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['.fabric.microsoft.com']) + + expect(ahv.url_host_valid?('https://fabric.microsoft.com/path')).to eq(false) + end + + it 'matches suffix hosts case-insensitively' do + ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['.Fabric.Microsoft.COM']) + + expect(ahv.url_host_valid?('https://ABC.z2c.graphql.fabric.microsoft.com/path')).to eq(true) + end + + it 'allows suffix-based hosts after update' do + ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['example.com']) + ahv.allowed_hosts = ['.fabric.microsoft.com'] + + expect(ahv.url_host_valid?('https://abc.123.graphql.fabric.microsoft.com/path')).to eq(true) + end + it 'tests the default instance for ParseNodeFactoryRegistry is set' do expect(MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance).to_not be_nil end