trailofbits / spf-query

Ruby SPF Parser
MIT License
29 stars 15 forks source link

Parsing issue for a and mx mechinism #8

Closed adamlc closed 11 months ago

adamlc commented 8 years ago

I've noticed an issue when parsing a particular record. In my client's DNS his current SPF record is (with blanked out IP):

v=spf1 a mx ip4:0.0.0.0 ~all

But for some reason spf-query is returning the following:

SPF record search for *******
  - found SPF record for *******
    v=spf1
    a:
    mx:
    ip4:0.0.0.0
    ~all

It appears to be adding a semi colon after the a and mx parts, which is actually an invalid record!

postmodern commented 8 years ago

Interesting. It appears the parser is parsing the missing value as a "".

pp SPF::Query::Parser.new.parse("v=spf1 a mx ip4:0.0.0.0 ~all")
{:version=>"spf1"@2,
 :rules=>
  [{:directive=>{:name=>"a"@7, :value=>""}},
   {:directive=>{:name=>"mx"@9, :value=>""}},
   {:directive=>{:name=>"ip4"@12, :value=>{:ip=>"0.0.0.0"@16}}},
   {:directive=>{:qualifier=>"~"@24, :name=>"all"@25}}]}
adamlc commented 8 years ago

I guess that could be the issue! Is it easy to resolve?

postmodern commented 8 years ago

Appears to be in the dual_cidr_length rule:

  rule(:dual_cidr_length) do
    ipv4_cidr_length.maybe >> (str('/') >> ipv6_cidr_length).maybe
  end
  rule(:ipv4_cidr_length) { str('/') >> digit.repeat(1).as(:cidr_length) }
  rule(:ipv6_cidr_length) { str('/') >> digit.repeat(1).as(:cidr_length) }

parser.dual_cidr_length.parse("")
# => ""
postmodern commented 8 years ago

https://github.com/kschiess/parslet/issues/155