Bas-Man / rust-decon-spf

A Rust library to deconstruct DNS SPF records
MIT License
16 stars 1 forks source link

Unable to parse long SPF record strings (>255 characters) #2

Open phyber opened 6 months ago

phyber commented 6 months ago

Hi,

I'm attempting to parse an SPF record that is longer than 255 characters which results which in a SourceLengthExceeded error.

I'm not sure this error should be triggered here. RFC 7208 section 3.3 says:

   TXT records containing multiple strings are useful in constructing
   records that would exceed the 255-octet maximum length of a
   character-string within a single TXT record.

I'm guessing that the TXT record length limit is where the 255 number comes from, but section 3.4 says:

3.4  Record Size

   The published SPF record for a given domain name SHOULD remain small
   enough that the results of a query for it will fit within 512 octets.
   Otherwise, there is a possibility of exceeding a DNS protocol limit.

It feels like the string length here should be increased to at least 512 characters, even then, it's only a SHOULD and some DNS implementations could be returning more characters.

Does a length check need to exist here at all? Perhaps a warning about the potential record lengths in the documentation is enough, with links to what the RFC has to say on the matter.

Bas-Man commented 6 months ago

Hi,

Yes. I think you are correct. I have been thinking this needed to be changed. Take a look at the dev branch if you want to submit a pull request.

Note that there are big changes coming.

I am in the process of moving through current SPF Struct to SpfBuilder and a leaner simpler Spf Struct is being added.

Will have support to iterate over the mechanism types. As well as covert Spf into a Spfbuilder.

Current away. So I will look at the change in a day or two.

Bas-Man commented 6 months ago

Also if you could leave the sample sod record. I will add it as a test case.

Bas-Man commented 6 months ago

@phyber I have pushed a possible v0.2.7 version to github. Please test with this code and let me know how it goes.

https://github.com/Bas-Man/rust-decon-spf/tree/v0.2.7.candidate

Bas-Man commented 6 months ago

You might be right. Might be worth relaxing the rule. I will see if I can do something along these lines with version 0.3.0.