
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
        <title><![CDATA[ The Cloudflare Blog ]]></title>
        <description><![CDATA[ Get the latest news on how products at Cloudflare are built, technologies used, and join the teams helping to build a better Internet. ]]></description>
        <link>https://blog.cloudflare.com</link>
        <atom:link href="https://blog.cloudflare.com/" rel="self" type="application/rss+xml"/>
        <language>en-us</language>
        <image>
            <url>https://blog.cloudflare.com/favicon.png</url>
            <title>The Cloudflare Blog</title>
            <link>https://blog.cloudflare.com</link>
        </image>
        <lastBuildDate>Tue, 14 Apr 2026 23:03:44 GMT</lastBuildDate>
        <item>
            <title><![CDATA[Stop brand impersonation with Cloudflare DMARC Management]]></title>
            <link>https://blog.cloudflare.com/dmarc-management/</link>
            <pubDate>Fri, 17 Mar 2023 13:00:00 GMT</pubDate>
            <description><![CDATA[ Brand impersonation continues to be a big problem globally. Setting SPF, DKIM and DMARC policies is a great way to reduce that risk, and protect your domains from being used in spoofing emails. But maintaining a correct SPF configuration can be very costly and time consuming ]]></description>
            <content:encoded><![CDATA[ <p></p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4VDPUUYhG7ru1WvkSMQjEI/dc8c4470547b35874809bbc1c0486c07/Security-Center-now-includes-ZT--DLP-and-email-.png" />
            
            </figure><p>At the end of 2021 Cloudflare <a href="/security-center/">launched Security Center</a>, a unified solution that brings together our suite of security products and unique Internet intelligence. It enables security teams to quickly identify potential security risks and threats to their organizations, map their <a href="https://www.cloudflare.com/learning/security/what-is-an-attack-surface/">attack surface</a> and mitigate these risks with just a few clicks. While Security Center initially focused on <a href="https://www.cloudflare.com/application-services/solutions/">application security</a>, we are now adding crucial <a href="https://www.cloudflare.com/learning/security/glossary/what-is-zero-trust/">zero trust</a> insights to further enhance its capabilities.</p><p>When your brand is loved and trusted, customers and prospects are looking forward to the emails you send them. Now picture them receiving an email from you: it has your brand, the subject is exciting, it has a link to register for something unique — how can they resist that opportunity?</p><p>But what if that email didn’t come from you? What if clicking on that link is a scam that takes them down the path of <a href="https://www.cloudflare.com/learning/email-security/what-is-email-fraud/">fraud or identity theft</a>? And what if they think you did it? The truth is, even security minded people occasionally fall for well crafted spoof emails.</p><p>That poses a risk to your business and reputation. A risk you don’t want to take - no one does. Brand impersonation is a <a href="/2022-march-hackness-phishing-bracket/">significant problem for organizations globally</a>, and that’s why we’ve built DMARC Management - available in Beta today.</p><p>With DMARC Management you have full insight on who is sending emails on your behalf. You can one-click approve each source that is a legitimate sender for your domain, and then set your <a href="https://www.cloudflare.com/learning/email-security/dmarc-dkim-spf/">DMARC</a> policy to reject any emails sent from unapproved clients.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5V4jHlhrGCxkmpTmaEwd7Y/486d9851a7ad4ded33940bee10638200/DMARC-1.jpg" />
            
            </figure><p>When the survey platform your company uses is sending emails from your domain, there’s nothing to worry about - you configured it that way. But if an unknown mail service from a remote country is sending emails using your domain that can be quite scary, and something you’ll want to address. Let’s see how.</p>
    <div>
      <h3>Anti-spoofing mechanisms</h3>
      <a href="#anti-spoofing-mechanisms">
        
      </a>
    </div>
    <p>Sender Policy Framework (SPF), DomainKeys Identified Mail (DKIM) and Domain-based Message Authentication Reporting and Conformance (DMARC) are three common email authentication methods. Together, they help <a href="https://www.cloudflare.com/learning/email-security/how-to-prevent-phishing/">prevent</a> spammers, phishers, and other unauthorized parties from sending emails on behalf of a domain they do not own.</p><p><b>SPF</b> is a way for a domain to list all the servers the company sends emails from. Think of it like a publicly available employee directory that helps someone to confirm if an employee works for an organization. <a href="https://www.cloudflare.com/learning/dns/dns-records/dns-spf-record/">SPF records</a> list all the IP addresses of all the servers that are allowed to send emails from the domain.</p><p><b>DKIM</b> enables domain owners to automatically "sign" emails from their domain. Specifically, DKIM uses <a href="https://www.cloudflare.com/learning/ssl/how-does-public-key-encryption-work/">public key cryptography</a>:</p><ol><li><p>A <a href="https://www.cloudflare.com/learning/dns/dns-records/dns-dkim-record/">DKIM record</a> stores the domain's <i>public key</i>, and mail servers receiving emails from the domain can check this record to obtain the public <a href="https://www.cloudflare.com/learning/ssl/what-is-a-cryptographic-key/">key</a>.</p></li><li><p>The <i>private key</i> is kept secret by the sender, who signs the email's header with this key.</p></li><li><p>Mail servers receiving the email can verify that the sender's private key was used by applying the public key. This also guarantees that the email was not tampered with while in transit.</p></li></ol><p><b>DMARC</b> tells a receiving email server what to do after evaluating the SPF and DKIM results. A domain's DMARC policy can be set in a variety of ways — it can instruct mail servers to quarantine emails that fail SPF or DKIM (or both), to reject such emails, or to deliver them.</p><p>It’s not trivial to configure and maintain SPF and DMARC, though. If your configuration is too strict, legitimate emails will be dropped or marked as spam. If it’s too relaxed, your domain might be misused for email spoofing. The proof is that these authentication mechanisms (SPF / DKIM / DMARC) have existed for over 10 years and still, there are still <a href="https://dmarc.org/stats/dmarc/">less than 6 million active DMARC records</a>.</p><p>DMARC reports can help, and a full solution like DMARC Management reduces the burden of creating and maintaining a proper configuration.</p>
    <div>
      <h3>DMARC reports</h3>
      <a href="#dmarc-reports">
        
      </a>
    </div>
    <p>All DMARC-compliant mailbox providers support sending DMARC aggregated reports to an email address of your choice. Those reports list the services that have sent emails from your domain and the percentage of messages that passed DMARC, SPF and DKIM. They are extremely important because they give administrators the information they need to decide how to adjust their DMARC policies — for instance, that’s how administrators know if their legitimate emails are failing SPF and DKIM, or if a spammer is trying to send illegitimate emails.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2rbeRaBvxsO0xRukkFLRHs/4a648e0386f5568f0a83b55222d318c7/pasted-image-0--1--7.png" />
            
            </figure><p>But beware, you probably don’t want to send DMARC reports to a human-monitored email address, as these come in fast and furious from virtually every email provider your organization sends messages to, and are delivered in XML format. Typically, administrators set up reports to be sent to a service like our DMARC Management, that boils them down to a more digestible form. <i>Note: These reports do not contain personal identifiable information (PII).</i></p><p>DMARC Management automatically creates an email address for those reports to be sent to, and adds the corresponding <a href="https://www.cloudflare.com/learning/dns/dns-records/dns-dmarc-record/">RUA record</a> to your Cloudflare DNS to announce to mailbox providers where to send reports to. And yes, if you’re curious, these email addresses are being created using <a href="https://www.cloudflare.com/products/email-routing/">Cloudflare Email Routing</a>.</p><p><i>Note: Today, Cloudflare DNS is a requirement for DMARC Management.</i></p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/CQaK1cwJWRVbNseX4W5TV/9167d60ea6753e64eb00000abe42f49a/DMARC--1--1.jpg" />
            
            </figure><p>As reports are received in this dedicated email address, they are processed by a <a href="https://workers.cloudflare.com/">Worker</a> that extracts the relevant data, parses it and sends it over to our analytics solution. And you guessed again, that’s implemented using <a href="https://developers.cloudflare.com/email-routing/email-workers/">Email Workers</a>. You can read more about the technical implementation <a href="/how-we-built-dmarc-management/">here</a>.</p>
    <div>
      <h3>Taking action</h3>
      <a href="#taking-action">
        
      </a>
    </div>
    <p>Now that reports are coming in, you can review the data and take action.</p><p><i>Note: It may take up to 24 hours for mailbox providers to start sending reports and for these analytics to be available to you.</i></p><p>At the top of DMARC Management you have an at-a-glance view of the outbound security configuration for your domain, more specifically DMARC, DKIM, and SPF. DMARC Management will soon start reporting on inbound email security as well, which includes STARTTLS, MTA-STS, DANE, and TLS reporting.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3XFAP5YG8knRRkIj50zkJ8/00ef5789a08c69c3103b672b7521a9b4/1.jpg" />
            
            </figure><p>The middle section shows the email volume over time, with individual lines showing those that pass DMARC and those that fail.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4uciHpDAy18iUp1stqQugo/721ebb2f2f365220a86943e56ea4535a/1--1-.jpg" />
            
            </figure><p>Below, you have additional details that include the number of email messages sent by each source (per the DMARC reports), and the corresponding DMARC, SPF and DKIM statistics. You can approve (that is, include in SPF) any of these sources by clicking on “…”, and you can easily spot applications that may not have DKIM correctly configured.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4rO4J9bwiA9m0tHupExWhk/0ad0478984602bd8fcace328bdfe2681/Frame-4121.png" />
            
            </figure><p>Clicking on any source gives you the same DMARC, SPF and DKIM statistics per IP address of that source. This is how you identify if there’s an additional IP address you might need to include in your SPF record, for example.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/aItdZkn7WlVOiNtCQsXAp/9b6484590faa502e884308d2a6a65c11/DMARC--2-.jpg" />
            
            </figure><p>The ones that fail are the ones you’ll want to take action on, as they will need to either be approved (which technically means including in the <a href="https://www.cloudflare.com/learning/email-security/dmarc-dkim-spf/">SPF</a> record) if legitimate, or stay unapproved and be rejected by the receiving server when the DMARC policy is configured with p=reject.</p><p>Getting to a DMARC reject policy is the goal, but you don’t want to apply such a restrictive policy until you have high confidence that all legitimate sending services are accounted for in SPF (and DKIM, if appropriate). That may take a few weeks, depending on the number of services you have sending messages from your domain, but with DMARC Management you will quickly grasp when you’re ready to go.</p>
    <div>
      <h3>What else is needed</h3>
      <a href="#what-else-is-needed">
        
      </a>
    </div>
    <p>Once you have approved all your authorized email senders (sources) and configured DMARC to quarantine or reject, you should be confident that your brand and organization are much safer. From then on, keeping an eye on your approved sources list is a very lightweight operation that doesn’t take more than a few minutes per month from your team. Ideally, when new applications that send emails from your domain are deployed in your company, you would proactively include the corresponding IP addresses in your SPF record.</p><p>But even if you don’t, you will find new unapproved senders notices on your Security Center, under the Security Insights tab, alongside other important security issues you can review and manage.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/WUjs0E5i27cLGp1USdAgw/d12e33553da78ba00802dda73c6a610b/Screenshot-with-unapproved-senders.jpg" />
            
            </figure><p>Or you can check the unapproved list on DMARC Management every few weeks.</p><p>Whenever you see a legitimate sender source show up as unapproved, you know what to do — click “…” and mark them as approved!</p>
    <div>
      <h3>What’s coming next</h3>
      <a href="#whats-coming-next">
        
      </a>
    </div>
    <p>DMARC Management takes <a href="https://www.cloudflare.com/zero-trust/products/email-security/">email security</a> to the next level, and this is only the beginning.</p><p>We’re excited to demonstrate our investments in features that provide customers even more insight into their security. Up next we’ll be connecting security analytics from Cloudflare’s <a href="https://www.cloudflare.com/products/zero-trust/casb/">Cloud Access Security Broker</a> (CASB) into the <a href="https://www.cloudflare.com/securitycenter/">Security Center</a>.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/61fj6NVQkeRVMDzJYl0SmR/b632b4000dd7a47769a91d0fe5e025fe/pasted-image-0--2--4.png" />
            
            </figure><p>This product integration will provide customers a way to understand the status of their wider <a href="https://www.cloudflare.com/learning/access-management/what-is-a-casb/">SaaS security</a> at a glance. By surfacing the makeup of CASB Findings (or security issues identified in popular SaaS apps) by severity, health of the SaaS integration, and the number of hidden issues, IT and security administrators will have a way to understand the status of their wider security surface area from a single source.</p><p>Stay tuned for more news on CASB in Security Center. In the meantime you can <a href="https://dash.cloudflare.com/?to=/:account/:zone/email/dmarc-management">join the waitlist for DMARC Management beta</a> for free today and, if you haven’t yet, we recommend you also check out Cloudflare Area 1 and <a href="https://www.cloudflare.com/lp/emailsecurity/">request a Phishing Risk Assessment</a> to block phishing, spoof and spam emails from coming into your environment.</p> ]]></content:encoded>
            <category><![CDATA[Security Week]]></category>
            <category><![CDATA[Security]]></category>
            <category><![CDATA[Email Security]]></category>
            <category><![CDATA[DMARC]]></category>
            <guid isPermaLink="false">6HHCQW1DIHAljDbWNp8sPh</guid>
            <dc:creator>João Sousa Botto</dc:creator>
        </item>
        <item>
            <title><![CDATA[How we built DMARC Management using Cloudflare Workers]]></title>
            <link>https://blog.cloudflare.com/how-we-built-dmarc-management/</link>
            <pubDate>Fri, 17 Mar 2023 13:00:00 GMT</pubDate>
            <description><![CDATA[ At Cloudflare, we use the Workers platform and our product stack to build new services. Read how we made the new DMARC Management solution entirely on top of our APIs.
 ]]></description>
            <content:encoded><![CDATA[ <p></p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3P7EqcZydcPUKVhQNdVwkr/55e20a63d7ae1ce2ff638c2818d7da58/How-we-built-DMARC-Management.png" />
            
            </figure>
    <div>
      <h3>What are DMARC reports</h3>
      <a href="#what-are-dmarc-reports">
        
      </a>
    </div>
    <p><a href="https://www.cloudflare.com/en-gb/learning/dns/dns-records/dns-dmarc-record/">DMARC</a> stands for Domain-based Message Authentication, Reporting, and Conformance. It's an email authentication protocol that helps protect against email <a href="https://www.cloudflare.com/learning/access-management/phishing-attack/">phishing</a> and <a href="https://www.cloudflare.com/learning/email-security/what-is-email-spoofing/">spoofing</a>.</p><p>When an email is sent, DMARC allows the domain owner to set up a DNS record that specifies which authentication methods, such as <a href="https://www.cloudflare.com/learning/dns/dns-records/dns-spf-record/">SPF</a> (Sender Policy Framework) and <a href="https://www.cloudflare.com/learning/dns/dns-records/dns-dkim-record/">DKIM</a> (DomainKeys Identified Mail), are used to verify the email's authenticity. When the email fails these authentication checks DMARC instructs the recipient's email provider on how to handle the message, either by quarantining it or rejecting it outright.</p><p>DMARC has become increasingly important in today's Internet, where email phishing and spoofing attacks are becoming more sophisticated and prevalent. By implementing DMARC, domain owners can protect their brand and their customers from the negative impacts of these attacks, including loss of trust, reputation damage, and financial loss.</p><p>In addition to <a href="https://www.cloudflare.com/learning/dns/dns-records/protect-domains-without-email/">protecting</a> against phishing and spoofing attacks, DMARC also provides <a href="https://www.rfc-editor.org/rfc/rfc7489">reporting</a> capabilities. Domain owners can receive reports on email authentication activity, including which messages passed and failed DMARC checks, as well as where these messages originated from.</p><p>DMARC management involves the configuration and maintenance of DMARC policies for a domain. Effective DMARC management requires ongoing monitoring and analysis of email authentication activity, as well as the ability to make adjustments and updates to DMARC policies as needed.</p><p>Some key components of effective DMARC management include:</p><ul><li><p>Setting up DMARC policies: This involves configuring the domain's DMARC record to specify the appropriate authentication methods and policies for handling messages that fail authentication checks. Here’s what a DMARC DNS record looks like:</p></li></ul><p><code>v=DMARC1; p=reject; rua=mailto:dmarc@example.com</code></p><p>This specifies that we are going to use DMARC version 1, our policy is to reject emails if they fail the DMARC checks, and the email address to which providers should send DMARC reports.</p><ul><li><p>Monitoring email authentication activity: DMARC reports are an important tool for domain owners to ensure <a href="https://www.cloudflare.com/zero-trust/products/email-security/">email security</a> and deliverability, as well as compliance with industry standards and regulations. By regularly monitoring and analyzing DMARC reports, domain owners can <a href="https://www.cloudflare.com/learning/email-security/how-to-prevent-phishing/">identify email threats</a>, optimize email campaigns, and improve overall email authentication.</p></li><li><p>Making adjustments as needed: Based on analysis of DMARC reports, domain owners may need to make adjustments to DMARC policies or authentication methods to ensure that email messages are properly authenticated and protected from phishing and spoofing attacks.</p></li><li><p>Working with email providers and third-party vendors: Effective DMARC management may require collaboration with email providers and third-party vendors to ensure that DMARC policies are being properly implemented and enforced.</p></li></ul><p>Today we launched <a href="/dmarc-management">DMARC management</a>. This is how we built it.</p>
    <div>
      <h3>How we built it</h3>
      <a href="#how-we-built-it">
        
      </a>
    </div>
    <p>As a leading provider of cloud-based security and performance solutions, we at Cloudflare take a specific approach to test our products. We "dogfood" our own tools and services, which means we use them to run our business. This helps us identify any issues or bugs before they affect our customers.</p><p>We use our own products internally, such as <a href="https://workers.cloudflare.com/">Cloudflare Workers</a>, a serverless platform that allows developers to run their code on our global network. Since its launch in 2017, the Workers ecosystem has grown significantly. Today, there are thousands of developers building and deploying applications on the platform. The power of the Workers ecosystem lies in its ability to enable developers to build sophisticated applications that were previously impossible or impractical to run so close to clients. Workers can be used to build APIs, generate dynamic content, optimize images, perform real-time processing, and much more. The possibilities are virtually endless. We used Workers to power services like <a href="/technology-behind-radar2/">Radar 2.0</a>, or software packages like <a href="/welcome-to-wildebeest-the-fediverse-on-cloudflare/">Wildebeest</a>.</p><p>Recently our <a href="https://developers.cloudflare.com/email-routing/">Email Routing</a> product joined forces with Workers, enabling <a href="/announcing-route-to-workers/">processing incoming emails</a> via Workers scripts. As the <a href="https://developers.cloudflare.com/email-routing/email-workers/">documentation</a> states: “With Email Workers you can leverage the power of Cloudflare Workers to implement any logic you need to <a href="https://www.cloudflare.com/learning/email-security/what-is-email-routing/">process your emails</a> and create complex rules. These rules determine what happens when you receive an email.” Rules and verified addresses can all be configured via our <a href="https://developers.cloudflare.com/api/operations/email-routing-destination-addresses-list-destination-addresses">API</a>.</p><p>Here’s how a simple Email Worker looks like:</p>
            <pre><code>export default {
  async email(message, env, ctx) {
    const allowList = ["friend@example.com", "coworker@example.com"];
    if (allowList.indexOf(message.headers.get("from")) == -1) {
      message.setReject("Address not allowed");
    } else {
      await message.forward("inbox@corp");
    }
  }
}</code></pre>
            <p>Pretty straightforward, right?</p><p>With the ability to programmatically process incoming emails in place, it seemed like the perfect way to handle incoming DMARC report emails in a scalable and efficient manner, letting Email Routing and Workers do the heavy lifting of receiving an unbound number of emails from across the globe. A high level description of what we needed is:</p><ol><li><p>Receive email and extract report</p></li><li><p>Publish relevant details to analytics platform</p></li><li><p>Store the raw report</p></li></ol><p>Email Workers enable us to do #1 easily. We just need to create a worker with an email() handler. This handler will receive the <a href="https://www.rfc-editor.org/rfc/rfc5321">SMTP</a> envelope elements, a pre-parsed version of the email headers, and a stream to read the entire raw email.</p><p>For #2 we can also look into the Workers platform, and we will find the <a href="https://developers.cloudflare.com/analytics/analytics-engine/">Workers Analytics Engine</a>. We just need to define an appropriate schema, which depends both on what’s present in the reports and the queries we plan to do later. Afterwards we can query the data using either the <a href="https://developers.cloudflare.com/analytics/graphql-api/">GraphQL</a> or <a href="https://developers.cloudflare.com/analytics/analytics-engine/sql-api/">SQL</a> API.</p><p>For #3 we don’t need to look further than our <a href="https://www.cloudflare.com/developer-platform/products/r2/">R2 object storage</a>. It is <a href="https://developers.cloudflare.com/r2/examples/demo-worker/">trivial</a> to access R2 from a Worker. After extracting the reports from the email we will store them in R2 for posterity.</p><p>We built this as a managed service that you can enable on your zone, and added a dashboard interface for convenience, but in reality all the tools are available for you to deploy your own DMARC reports processor on top of Cloudflare Workers, in your own account, without having to worry about servers, scalability or performance.</p>
    <div>
      <h3>Architecture</h3>
      <a href="#architecture">
        
      </a>
    </div>
    
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3d55aU3WlGrgQcuc1TKPAF/a02a34f819174b82e768b0aed5053708/Screenshot-2023-03-16-at-4.18.08-PM.png" />
            
            </figure><p><a href="https://developers.cloudflare.com/email-routing/email-workers/">Email Workers</a> is a feature of our Email Routing product. The Email Routing component runs in all our nodes, so any one of them is able to process incoming mail, which is important because we announce the Email ingress BGP prefix from all our datacenters. Sending emails to an Email Worker is as easy as setting a rule in the Email Routing dashboard.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4tgjcPuXeJ3lJ9yLxQoPxz/7c9f34dd7ae03aeb2293e64df9ebf8e6/pasted-image-0--4--3.png" />
            
            </figure><p>When the Email Routing component receives an email that matches a rule to be delivered to a Worker, it will contact our internal version of the recently open-sourced <a href="https://github.com/cloudflare/workerd">workerd</a> runtime, which also runs on all nodes. The RPC schema that governs this interaction is defined in a <a href="https://github.com/capnproto/capnproto">Capnproto</a> schema, and allows the body of the email to be streamed to Edgeworker as it’s read. If the worker script decides to forward this email, Edgeworker will contact Email Routing using a capability sent in the original request.</p>
            <pre><code>jsg::Promise&lt;void&gt; ForwardableEmailMessage::forward(kj::String rcptTo, jsg::Optional&lt;jsg::Ref&lt;Headers&gt;&gt; maybeHeaders) {
  auto req = emailFwdr-&gt;forwardEmailRequest();
  req.setRcptTo(rcptTo);

  auto sendP = req.send().then(
      [](capnp::Response&lt;rpc::EmailMetadata::EmailFwdr::ForwardEmailResults&gt; res) mutable {
    auto result = res.getResponse().getResult();
    JSG_REQUIRE(result.isOk(), Error, result.getError());
  });
  auto&amp; context = IoContext::current();
  return context.awaitIo(kj::mv(sendP));
}
</code></pre>
            <p>In the context of DMARC reports this is how we handle the incoming emails:</p><ol><li><p>Fetch the recipient of the email being processed, this is the RUA that was used. RUA is a DMARC configuration parameter that indicates where aggregate DMARC processing feedback should be reported pertaining to a certain domain. This recipient can be found in the “to” attribute of the message.</p></li></ol>
            <pre><code>const ruaID = message.to</code></pre>
            <ol><li><p>Since we handle DMARC reports for an unbounded number of domains, we use Workers KV to store some information about each one and key this information on the RUA. This also lets us know if we should be receiving these reports.</p></li></ol>
            <pre><code>const accountInfoRaw = await env.KV_DMARC_REPORTS.get(dmarc:${ruaID})</code></pre>
            <ol><li><p>At this point, we want to read the entire email into an arrayBuffer in order to parse it. Depending on the size of the report we may run into the limits of the free Workers plan. If this happens, we recommend that you switch to the <a href="https://www.cloudflare.com/workers-unbound-beta/">Workers Unbound</a> resource model which does not have this issue.</p></li></ol>
            <pre><code>const rawEmail = new Response(message.raw)
const arrayBuffer = await rawEmail.arrayBuffer()</code></pre>
            <ol><li><p>Parsing the raw email involves, among other things, parsing its MIME parts. There are multiple libraries available that allow one to do this. For example, you could use <a href="https://www.npmjs.com/package/postal-mime">postal-mime</a>:</p></li></ol>
            <pre><code>const parser = new PostalMime.default()
const email = await parser.parse(arrayBuffer)</code></pre>
            <ol><li><p>Having parsed the email we now have access to its attachments. These attachments are the DMARC reports themselves and they can be compressed. The first thing we want to do is store them in their compressed form in <a href="https://developers.cloudflare.com/r2/data-access/workers-api/workers-api-usage/">R2</a> for long-term storage. They can be useful later on for re-processing or investigating interesting reports. Doing this is as simple as calling put() on the R2 binding. In order to facilitate retrieval later we recommend that you spread the report files across directories based on the current time.</p></li></ol>
            <pre><code>await env.R2_DMARC_REPORTS.put(
    `${date.getUTCFullYear()}/${date.getUTCMonth() + 1}/${attachment.filename}`,
    attachment.content
  )</code></pre>
            <ol><li><p>We now need to look into the attachment mime type. The raw form of DMARC reports is XML, but they can be compressed. In this case we need to decompress them first. DMARC reporter files can use multiple compression algorithms. We use the MIME type to know which one to use. For <a href="https://en.wikipedia.org/wiki/Zlib">Zlib</a> compressed reports <a href="https://www.npmjs.com/package/pako">pako</a> can be used while for ZIP compressed reports <a href="https://www.npmjs.com/package/unzipit">unzipit</a> is a good choice.</p></li><li><p>Having obtained the raw XML form of the report, <a href="https://www.npmjs.com/package/fast-xml-parser">fast-xml-parser</a> has worked well for us in parsing them. Here’s how the DMARC report XML looks:</p></li></ol>
            <pre><code>&lt;feedback&gt;
  &lt;report_metadata&gt;
    &lt;org_name&gt;example.com&lt;/org_name&gt;
    &lt;emaildmarc-reports@example.com&lt;/email&gt;
   &lt;extra_contact_info&gt;http://example.com/dmarc/support&lt;/extra_contact_info&gt;
    &lt;report_id&gt;9391651994964116463&lt;/report_id&gt;
    &lt;date_range&gt;
      &lt;begin&gt;1335521200&lt;/begin&gt;
      &lt;end&gt;1335652599&lt;/end&gt;
    &lt;/date_range&gt;
  &lt;/report_metadata&gt;
  &lt;policy_published&gt;
    &lt;domain&gt;business.example&lt;/domain&gt;
    &lt;adkim&gt;r&lt;/adkim&gt;
    &lt;aspf&gt;r&lt;/aspf&gt;
    &lt;p&gt;none&lt;/p&gt;
    &lt;sp&gt;none&lt;/sp&gt;
    &lt;pct&gt;100&lt;/pct&gt;
  &lt;/policy_published&gt;
  &lt;record&gt;
    &lt;row&gt;
      &lt;source_ip&gt;192.0.2.1&lt;/source_ip&gt;
      &lt;count&gt;2&lt;/count&gt;
      &lt;policy_evaluated&gt;
        &lt;disposition&gt;none&lt;/disposition&gt;
        &lt;dkim&gt;fail&lt;/dkim&gt;
        &lt;spf&gt;pass&lt;/spf&gt;
      &lt;/policy_evaluated&gt;
    &lt;/row&gt;
    &lt;identifiers&gt;
      &lt;header_from&gt;business.example&lt;/header_from&gt;
    &lt;/identifiers&gt;
    &lt;auth_results&gt;
      &lt;dkim&gt;
        &lt;domain&gt;business.example&lt;/domain&gt;
        &lt;result&gt;fail&lt;/result&gt;
        &lt;human_result&gt;&lt;/human_result&gt;
      &lt;/dkim&gt;
      &lt;spf&gt;
        &lt;domain&gt;business.example&lt;/domain&gt;
        &lt;result&gt;pass&lt;/result&gt;
      &lt;/spf&gt;
    &lt;/auth_results&gt;
  &lt;/record&gt;
&lt;/feedback&gt;</code></pre>
            <ol><li><p>We now have all the data in the report at our fingertips. What we do from here on depends a lot on how we want to present the data. For us, the goal was to display meaningful data extracted from them in our Dashboard. Therefore we needed an Analytics platform where we could push the enriched data. Enter, <a href="https://developers.cloudflare.com/analytics/analytics-engine/">Workers Analytics Engine</a>. The Analytics engine is perfect for this task since it allows us to <a href="https://developers.cloudflare.com/analytics/analytics-engine/get-started/#3-write-data-from-your-worker">send</a> data to it from a worker, and exposes a <a href="https://developers.cloudflare.com/analytics/graphql-api/">GraphQL API</a> to interact with the data afterwards. This is how we obtain the data to show in our dashboard.</p></li></ol><p>In the future, we are also considering integrating <a href="https://developers.cloudflare.com/queues/">Queues</a> in the workflow to asynchronously process the report and avoid waiting for the client to complete it.</p><p>We managed to implement this project end-to-end relying only on the Workers infrastructure, proving that it’s possible, and advantageous, to build non-trivial apps without having to worry about scalability, performance, storage and security issues.</p>
    <div>
      <h3>Open sourcing</h3>
      <a href="#open-sourcing">
        
      </a>
    </div>
    <p>As we mentioned before, we built a managed service that you can enable and use, and we will manage it for you. But, everything we did can also be deployed by you, in your account, so that you can manage your own DMARC reports. It’s easy, and free. To help you with that, we are releasing an open-source version of a Worker that processes DMARC reports in the way described above: <a href="https://github.com/cloudflare/dmarc-email-worker">https://github.com/cloudflare/dmarc-email-worker</a></p><p>If you don’t have a dashboard where to show the data, you can also <a href="https://developers.cloudflare.com/analytics/analytics-engine/worker-querying/">query</a> the Analytics Engine from a Worker. Or, if you want to store them in a relational database, then there’s <a href="https://developers.cloudflare.com/d1/platform/client-api/">D1</a> to the rescue. The possibilities are endless and we are excited to find out what you’ll build with these tools.</p><p>Please contribute, make your own, we’ll be listening.</p>
    <div>
      <h3>Final words</h3>
      <a href="#final-words">
        
      </a>
    </div>
    <p>We hope that this post has furthered your understanding of the Workers platform. Today Cloudflare takes advantage of this platform to build most of our services, and we think you should too.</p><p>Feel free to contribute to our open-source version and show us what you can do with it.</p><p>The Email Routing is also working on expanding the Email Workers API more functionally, but that deserves another blog soon.</p> ]]></content:encoded>
            <category><![CDATA[Security Week]]></category>
            <category><![CDATA[Email Security]]></category>
            <category><![CDATA[Security]]></category>
            <category><![CDATA[DMARC]]></category>
            <guid isPermaLink="false">HNhMxPSjzPXyTdtRLp51K</guid>
            <dc:creator>André Cruz</dc:creator>
            <dc:creator>Nelson Duarte</dc:creator>
        </item>
    </channel>
</rss>