A platform for community discussion. Free, open, simple.
SECURITY: fix loose hostname matching in spam host allowlist
Joffrey JAFFEUXf99099cfbc6b
diff --git a/app/models/post.rb b/app/models/post.rbindex 39f6161cd0e..a5e64d658fd 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -399,7 +399,7 @@ class Post < ActiveRecord::Basehosts = linked_hosts.cloneallowlisted = allowed_spam_hosts- hosts.reject! { |h| allowlisted.any? { |w| h.end_with?(w) } }+ hosts.reject! { |h| allowlisted.any? { |w| h == w || h.end_with?(".#{w}") } }return hosts if hosts.length == 0diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 116a8ae441c..5bf26ccda00 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1286,6 +1286,15 @@ RSpec.describe Post doFabricate(:post, raw: raw, user: user, topic: Fabricate(:private_message_topic, user: user))expect(post.has_host_spam?).to eq(false)end++ it "does not allowlist domains that merely end with an allowed domain" do+ SiteSetting.newuser_spam_host_threshold = 1+ SiteSetting.allowed_spam_host_domains = "example.com"+ user = Fabricate(:user, trust_level: 0)+ post = Fabricate(:post, raw: "check out http://attacker-example.com/page", user: user)+ post.acting_user.trust_level = 0+ expect(post.has_host_spam?).to eq(true)+ endendit "has custom fields" do