Project

dmarcator

0.0
Low commit activity in last 3 years
A hardened DMARC record parser and query client, forked from the Trail of Bits 'dmarc' gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 1.10
>= 1.0.0, < 3.0.0
 Project Readme

DMARCator

Gem Version YARD Docs

DMARCator is a Ruby library for parsing and querying DMARC records.

DMARCator is a fork of the dmarc gem, originally created by Davis Gallinghouse at Trail of Bits. It keeps the original MIT license and credits its authors, but ships under a new name with additional hardening and a stricter parser. See Acknowledgments below.

DMARC policies are published as DNS TXT records at _dmarc.<domain>. This library parses those records into a structured DMARCator::Record, queries them directly through Ruby's Resolv DNS client, and parses the XML aggregate reports those policies generate.

Installation

Add this line to your application's Gemfile:

gem "dmarcator"

And then execute:

bundle install

Or install it yourself:

gem install dmarcator

The gem is loaded via:

require "dmarcator"

Example

Parse a DMARC record:

require "dmarcator"

record = DMARCator::Record.parse(
  "v=DMARC1; p=reject; rua=mailto:d@rua.agari.com; ruf=mailto:d@ruf.agari.com; fo=1"
)

record.v
# => :DMARC1

record.p
# => :reject

record.adkim
# => :r

record.aspf
# => :r

record.fo
# => ["0"]

record.pct
# => 100

record.rf
# => :afrf

record.ri
# => 86400

record.rua
# => [#<DMARCator::Uri ... @uri=#<URI::MailTo mailto:d@rua.agari.com>, @size=nil, @unit=nil>]

record.ruf
# => [#<DMARCator::Uri ... @uri=#<URI::MailTo mailto:d@ruf.agari.com>, @size=nil, @unit=nil>]

record.sp
# => :reject

Query the DMARC record for a domain:

record = DMARCator::Record.query("twitter.com")
# => #<DMARCator::Record ... @p=:reject, @rua=[...], ...>

Parsing XML reports

Parse a DMARC aggregate/forensic report:

report = DMARCator::Report.new(xml_string)

report.version
# => 0.1e0

report.metadata.org_name
# => "google.com"

report.policy.domain
# => "opserv.io"

report.records.first.source_ip
# => "209.85.220.69"

Requirements

Testing

To run the RSpec tests:

rake spec

To test the parser against the bundled Alexa Top 500 fixture:

rake spec:gauntlet

License

This project is released under the MIT License. See the LICENSE.txt file for details.

Acknowledgments

DMARCator is a fork of dmarc, a DMARC record parser created by Davis Gallinghouse at Trail of Bits and released under the MIT License.

This fork renames the DMARC module to DMARCator (loaded via require "dmarcator") while keeping the original API shape, and adds:

  • strict mailto:-only handling for rua/ruf report URIs,
  • validation for required and ranged tags (p, pct, ri) and duplicate tags,
  • a DNS query path that selects the v=DMARC1 TXT record per RFC 7489,
  • hardened packaging and test fixtures.

The DMARC XML report parser is ported from dmarc_parser, created by D Salko and released under the MIT License.