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

Comcast sending stupid report #6

Closed
Biztactix-Ryan opened this issue Feb 10, 2025 · 3 comments
Closed

Comcast sending stupid report #6

Biztactix-Ryan opened this issue Feb 10, 2025 · 3 comments

Comments

@Biztactix-Ryan
Copy link
Contributor

I've just had a new failure started popping up, I thought it was a temporary one, so ignored it, but they've sent again... So, now I have to fix it.

Really just leaving it here in case someone has a better idea or even a good idea, as I'm struggling to find a way to clean it for all future ways it can break,

Essentially they are sending an aspf with a value of "r;"

I was thinking perhaps I could try this for the validation

<xs:simpleType name="AlignmentType">
  <xs:restriction base="xs:string">
    <!-- 
         \s* means “any whitespace, any number of times”
         [rs] means “literal ‘r’ or ‘s’”
         [^a-zA-Z0-9]* means “zero or more characters that are NOT letters or digits”
    -->
    <xs:pattern value="\s*[rs][^a-zA-Z0-9]*"/>
  </xs:restriction>
</xs:simpleType>

and then trim on the input, but I'm not sure that would work either.
I've had a quick 20 minute go at the bug, but it didn't play, I'll come back to it when it's a real problem, I'm just going to ignore it for now 😄

Example of Issue

<report_metadata>
	<org_name>example.com</org_name>
	<email>noreply-dmarc-support@example.com</email>
	<extra_contact_info>https://support.example.com/dmarc-info</extra_contact_info>
	<report_id>12345678901234567890</report_id>
	<date_range>
		<begin>1600000000</begin>
		<end>1600086399</end>
	</date_range>
</report_metadata>
<policy_published>
	<domain>test-domain.com</domain>
	<adkim>r</adkim>
	<aspf>r;</aspf>
	<p>none</p>
	<sp>none</sp>
	<pct>100</pct>
</policy_published>
@danielsen
Copy link
Owner

The only way I see this working is to change the adkim and aspf elements to the xs:string type in rua.xsd and add methods to rua.cs to convert the value of the field to the AlignmentType enumeration. Something like this:

    public class PolicyPublishedType {
        [XmlElement("adkim", Form = XmlSchemaForm.Unqualified)]
        public string Adkim { get; set; }
        ...
        public AlignmentType? GetAdkimAlignment() {
             doMagic();
        }
        ...
    }

The xs:pattern restriction won't pass capture groups from the regex, only the full match so the value can't be filtered there.

Is it possible that the DNS record for the domain has an extra semicolon in it and that's causing the problem?

@Biztactix-Ryan
Copy link
Contributor Author

I'd actually already written it that way, Which does work,
I just don't know if we should break the validation in xsd, as essentially the report is actually invalid.
So should just be dumped... but a quick clean and trim of the text makes it work

 [XmlElement("adkim", Form = XmlSchemaForm.Unqualified)]
 [JsonPropertyName("adkim")]
 public string AdkimRaw { get; set; }

 [XmlElement("aspf", Form = XmlSchemaForm.Unqualified)]
 [JsonPropertyName("aspf")]
 public string AspfRaw { get; set; }

 [XmlIgnore]
 public AlignmentType? Aspf
 {
     get
     {
         if (string.IsNullOrWhiteSpace(AspfRaw))
             return null;
         
         var cleaned = ValidationFunctions.CleanText(AspfRaw);
         return cleaned == "r" ? AlignmentType.Relaxed :
                cleaned == "s" ? AlignmentType.Strict :
                throw new InvalidOperationException($"Unexpected aspf value: {AspfRaw}");
     }
 }

 [XmlIgnore]
 public AlignmentType? Adkim
 {
     get
     {
         if (string.IsNullOrWhiteSpace(AdkimRaw))
             return null;
         // Remove non-alphanumeric characters
         var cleaned = ValidationFunctions.CleanText(AdkimRaw);
         return cleaned == "r" ? AlignmentType.Relaxed :
                cleaned == "s" ? AlignmentType.Strict :
                throw new InvalidOperationException($"Unexpected adkim value: {AdkimRaw}");
     }

@danielsen
Copy link
Owner

Closed in 5d2ab81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants