Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not implicitly query for _spf.DOMAIN.EXT record #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions lib/spf/query/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ module Query
# @api semipublic
#
def self.query(domain,resolver=Resolv::DNS.new)
# check for SPF in the TXT records
["_spf.#{domain}", domain].each do |host|
begin
records = resolver.getresources(host, Resolv::DNS::Resource::IN::TXT)
begin
records = resolver.getresources(domain, Resolv::DNS::Resource::IN::TXT)

records.each do |record|
txt = record.strings.join
records.each do |record|
txt = record.strings.join

if txt.include?('v=spf1')
return txt
end
if txt.include?('v=spf1')
return txt
end
rescue Resolv::ResolvError
end
rescue Resolv::ResolvError
end

# check for an SPF record on the domain
Expand Down
3 changes: 1 addition & 2 deletions spec/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let(:domain) { 'google.com' }

it "should return the first SPF record" do
expect(subject.query(domain)).to be == %{v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all}
expect(subject.query(domain)).to be == %{v=spf1 include:_spf.google.com ~all}
end
end

Expand All @@ -41,7 +41,6 @@
it "should prefer the TXT type record over other SPF records" do
expect_any_instance_of(Resolv::DNS).to_not receive(:getresource).with("getlua.com", Resolv::DNS::Resource::IN::SPF)
expect_any_instance_of(Resolv::DNS).to receive(:getresources).with("getlua.com", Resolv::DNS::Resource::IN::TXT).at_least(:once).and_call_original
expect_any_instance_of(Resolv::DNS).to receive(:getresources).with("_spf.getlua.com", Resolv::DNS::Resource::IN::TXT).at_least(:once).and_call_original

expect(subject.query(domain)).to be == %{v=spf1 include:_spf.google.com include:mail.zendesk.com include:servers.mcsv.net include:aspmx.pardot.com -all}
end
Expand Down