<?xml version="1.0" encoding="UTF-8"?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     version="3"
     ipr="trust200902"
     submissionType="IETF"
     category="info"
     consensus="false"
     docName="draft-chen-email-mime-ambiguity-defense-00"
     xml:lang="en">
  <front>
    <title abbrev="MIME Ambiguity Defense">Defensive Handling of MIME Parsing Ambiguities in Email Delivery</title>

    <seriesInfo name="Internet-Draft" value="draft-chen-email-mime-ambiguity-defense-00"/>

    <author fullname="Jianjun Chen" initials="J." surname="Chen">
      <organization>Tsinghua University</organization>
      <address>
        <postal>
          <country>China</country>
        </postal>
        <email>jianjun@tsinghua.edu.cn</email>
      </address>
    </author>

    <date year="2026" month="03" day="12"/>

    <area>SEC</area>
    <keyword>MIME</keyword>
    <keyword>Email Security</keyword>
    <keyword>Attachment Detection</keyword>
    <keyword>Parsing Ambiguity</keyword>

    <abstract>
      <t>
        Email security gateways and endpoint mail clients frequently rely on
        different MIME parsers, decoders, and error-recovery behavior.  An
        attacker can exploit those differences so that a security control fails
        to extract or scan an attachment that a downstream client later exposes
        to a user.  This document describes defensive processing guidance for
        SMTP receivers, mail gateways, and message stores that handle MIME
        messages with malformed or ambiguous structure.
      </t>
      <t>
        This document provides operational guidance for ingress validation,
        strict decoding floors, ambiguity detection, multi-view extraction,
        union scanning, logging, and policy handling.  It also defines an
        optional "MIME-Ambiguity-Results" header field for conveying
        receiver-generated ambiguity assessments to downstream components
        inside an administrative domain.
      </t>
    </abstract>
  </front>

  <middle>
    <section anchor="intro">
      <name>Introduction</name>
      <t>
        Email attachment defenses often assume that the object scanned by a
        gateway is the same object that a receiving mail client will later
        present for download or execution.  That assumption is not always true.
        Divergent handling of malformed or ambiguous MIME can create a gap
        between the detector-side view and the client-side view of the same
        message.  That gap can be exploited to evade attachment detection.
      </t>
      <t>
        The problem is operational rather than purely theoretical: deployed
        products differ in how they resolve duplicate or conflicting header
        fields, how they parse multipart boundaries, and how they decode
        malformed transfer encodings.  This document provides defensive
        guidance intended to ensure that a receiving system scans at least
        every attachment view that mainstream clients could plausibly expose,
        or else blocks or quarantines the message.
      </t>
      <t>
        This document is intentionally scoped to receiver-side defenses.  It
        does not attempt to standardize all client parser behavior, nor does it
        provide exploit construction guidance.
      </t>
    </section>

    <section anchor="conventions">
      <name>Requirements Language and Conventions</name>
      <t>
        The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
        "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
        "OPTIONAL" in this document are to be interpreted as described in BCP
        14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only
        when, they appear in all capitals, as shown here.
      </t>
      <t>
        "Detector side" means any SMTP receiver, mail gateway, content filter,
        malware scanner, sandbox, or message store component that parses or
        scans inbound content before user access.  "Client side" means the mail
        user agent or webmail interface that renders message structure or makes
        attachments available for download.
      </t>
      <t>
        "Strict parse" means message parsing and decoding that follows Internet
        Message Format and MIME specifications, including the baseline decoding
        semantics required by those specifications.  "Compatible parse" means a
        receiver-controlled parsing path used to approximate tolerated client
        behavior without inventing new semantics beyond what deployed clients
        are known to expose.
      </t>
      <t>
        "Attachment view" means the set of extracted byte sequences that a
        given parsing path would make available to a user as attachments,
        downloadable body parts, or equivalent objects.
      </t>
    </section>

    <section anchor="threat-model">
      <name>Threat Model</name>
      <t>
        The attacker is assumed to be able to send email to the target domain.
        The attacker need not control the target mail system, the malware
        detection engine, or the recipient account.  The attack succeeds if a
        message is accepted and delivered without the malicious content being
        blocked or quarantined, and if a downstream client later exposes an
        attachment or downloadable object that was not effectively covered by
        the detector-side scan.
      </t>
      <t>
        This document addresses attacks that rely on parser disagreement,
        malformed structure, conflicting MIME metadata, or divergent decoding.
        It does not attempt to solve malicious content classification in the
        absence of such ambiguity.
      </t>
    </section>

    <section anchor="design-goals">
      <name>Defensive Goals</name>
      <t>
        A receiver implementing this document aims to satisfy the following
        goals:
      </t>
      <ol>
        <li>A scanned attachment set MUST be at least as broad as any
        attachment view that a supported downstream client could plausibly
        expose.</li>
        <li>If that condition cannot be met with sufficient confidence, the
        message MUST be rejected, quarantined, or sanitized according to local
        policy.</li>
        <li>Receiver behavior SHOULD favor deterministic and auditable handling
        over heuristic repair that could create new message semantics.</li>
        <li>Deployments SHOULD support phased rollout, beginning with logging
        and policy reporting before enabling blocking behavior.</li>
      </ol>
    </section>

    <section anchor="receiver-model">
      <name>Receiver Processing Model</name>
      <t>
        A receiver implementing this specification SHOULD process inbound
        messages using the following high-level sequence:
      </t>
      <ol>
        <li>Ingress structural validation</li>
        <li>Strict parsing and extraction</li>
        <li>Compatible parsing and extraction</li>
        <li>Construction of a union attachment view</li>
        <li>Scanning of every extracted object in that union</li>
        <li>Disposition according to local policy</li>
        <li>Optional emission of receiver-generated ambiguity results</li>
      </ol>
      <t>
        Receivers MAY combine or pipeline these steps internally, but the
        effective security outcome MUST be equivalent.
      </t>

      <section anchor="ingress-checks">
        <name>Ingress Structural Validation</name>
        <t>
          Before normal delivery, a receiver SHOULD evaluate the message for
          structural conditions that are highly correlated with parser
          disagreement.  At minimum, implementations SHOULD detect the
          following classes of conditions:
        </t>
        <ol>
          <li>duplicate or conflicting MIME structural header fields, including
          multiple <tt>Content-Type</tt> fields with different effective
          values;</li>
          <li>control characters, including NUL, in MIME-relevant header field
          names or values;</li>
          <li>multipart bodies with absent, empty, or otherwise invalid
          boundary parameters;</li>
          <li>use of RFC 2047 encoded-word syntax inside MIME parameter values,
          such as <tt>boundary</tt> or <tt>filename</tt>, where such usage is
          not permitted;</li>
          <li>decoding anomalies in transfer encodings that are known to create
          divergent extraction outcomes; and</li>
          <li>malformed line folding or abnormal header/body separation that can
          change message interpretation.</li>
        </ol>
        <t>
          A receiver MUST classify each detected condition as either:
        </t>
        <ul>
          <li><tt>fatal</tt>: the message cannot be trusted to have a single
          safe interpretation and MUST be rejected or quarantined; or</li>
          <li><tt>ambiguous</tt>: the message might still be processable, but
          additional extraction and union scanning are required before any
          delivery decision.</li>
        </ul>
        <t>
          Empty multipart boundaries, NUL in MIME-relevant header data, and
          directly conflicting MIME structural header fields SHOULD be treated
          as <tt>fatal</tt> by default.
        </t>
      </section>

      <section anchor="strict-floor">
        <name>Strict Parsing and Decoding Floor</name>
        <t>
          A receiver MUST implement at least one strict parsing path grounded in
          <xref target="RFC5322"/>, <xref target="RFC2045"/>,
          <xref target="RFC2046"/>, <xref target="RFC2047"/>, and
          <xref target="RFC2183"/>.
        </t>
        <t>
          For transfer encodings, a receiver MUST NOT implement a decoding
          behavior that is weaker than the minimum semantics already required by
          the MIME specifications.  In particular, if a MIME decoding rule
          requires tolerant handling of certain non-alphabet characters or
          whitespace, a receiver MUST NOT stop extraction earlier than that
          specification permits if doing so would produce a narrower scan view
          than a conformant client could expose.
        </t>
      </section>

      <section anchor="compatible-parse">
        <name>Compatible Parsing</name>
        <t>
          A receiver SHOULD implement at least one receiver-controlled
          compatible parsing path to approximate attachment views that common
          downstream clients may expose in practice.  The purpose of the
          compatible path is defensive coverage, not message repair for end-user
          fidelity.
        </t>
        <t>
          A compatible path MUST be constrained so that it does not invent new
          attachment semantics unsupported by realistic client behavior.
          Compatible parsing SHOULD be derived from observed receiver or client
          interoperability needs, regression testing, or differential parser
          analysis.
        </t>
      </section>

      <section anchor="union-scanning">
        <name>Union Extraction and Scanning</name>
        <t>
          A receiver that performs both strict and compatible parsing MUST form
          a union attachment view from all extracted objects.  Every object in
          that union MUST be subject to the same malware detection, content
          policy, archive expansion, and sandboxing controls that would apply
          to a normal attachment.
        </t>
        <t>
          If any object in the union is classified as malicious or disallowed,
          the receiver MUST apply that disposition to the message as a whole,
          unless local policy instead replaces the object with a safe,
          auditable sanitization result.
        </t>
        <t>
          If the union attachment view differs from the strict attachment view,
          the receiver MUST treat the message as ambiguous.  Local policy MAY
          still permit delivery after successful scanning, but the default
          action SHOULD be quarantine or other restricted handling.
        </t>
      </section>

      <section anchor="limits">
        <name>Resource Limits and Abuse Resistance</name>
        <t>
          Because multi-view parsing and scanning can expand resource
          consumption, implementations MUST enforce limits on message size,
          extracted object count, nested multipart depth, recursive archive
          expansion, decoding output size, and processing time.  Messages that
          exceed such limits MUST fail closed, typically by quarantine or
          rejection.
        </t>
      </section>
    </section>

    <section anchor="anomaly-catalog">
      <name>Minimum Anomaly Classes</name>
      <t>
        The following anomaly classes form a minimum common vocabulary for
        receiver implementations.  Implementations MAY define additional local
        classes.
      </t>
      <dl newline="false">
        <dt>dup-content-type</dt>
        <dd>Duplicate or conflicting <tt>Content-Type</tt> fields or parameter
        interpretations that could change body-part structure.</dd>
        <dt>nul-in-header</dt>
        <dd>NUL or comparable control characters in MIME-relevant header field
        names or values.</dd>
        <dt>empty-boundary</dt>
        <dd>Missing or empty multipart boundary values, or equivalent boundary
        invalidity causing structure disagreement.</dd>
        <dt>invalid-b64-char</dt>
        <dd>Base64 decoding anomalies that alter extraction outcome across
        implementations.</dd>
        <dt>qp-broken-softbreak</dt>
        <dd>Quoted-printable soft line break anomalies that can alter recovered
        bytes or part delimitation.</dd>
        <dt>encoded-word-in-parameter</dt>
        <dd>Use of RFC 2047 encoded-word syntax in MIME parameters where not
        permitted.</dd>
      </dl>
      <t>
        Receivers SHOULD log anomaly classes in structured security telemetry
        even when local policy ultimately delivers the message.
      </t>
    </section>

    <section anchor="smtp-handling">
      <name>SMTP Handling and Disposition</name>
      <t>
        If a receiver detects a fatal ambiguity during SMTP transaction
        processing, it MAY reject the message during or immediately after DATA.
        Enhanced status codes from the 5.6.x or 5.7.x classes are generally
        appropriate depending on whether the receiver treats the event as a
        format violation or a security-policy violation; exact code selection
        is a local policy matter.
      </t>
      <t>
        If the receiver accepts the message first and later determines that it
        is fatally ambiguous or malicious, it MUST prevent unrestricted user
        access, for example by quarantine, silent administrative hold, or
        bounded sanitization with operator auditability.
      </t>
    </section>

    <section anchor="mar-field">
      <name>The MIME-Ambiguity-Results Header Field</name>
      <t>
        This section defines an OPTIONAL receiver-generated header field,
        <tt>MIME-Ambiguity-Results</tt>, for use within an administrative
        domain.  The field communicates whether the receiver detected MIME
        ambiguity and what disposition was applied.
      </t>
      <t>
        This field is not an originator assertion.  It MUST be inserted only by
        trusted receiving infrastructure.  Downstream consumers MUST ignore
        instances that originate outside the local trust boundary.
      </t>

      <section anchor="mar-syntax">
        <name>Syntax</name>
        <t>
          The syntax in this section is described using ABNF <xref target="RFC5234"/>.
          The <tt>FWS</tt>, <tt>CFWS</tt>, and <tt>CRLF</tt> rules are imported
          from <xref target="RFC5322"/>.  The <tt>authserv-id</tt>, <tt>token</tt>,
          and <tt>value</tt> rules are imported from <xref target="RFC8601"/>.
        </t>
        <sourcecode type="abnf"><![CDATA[
MIME-Ambiguity-Results = "MIME-Ambiguity-Results:" FWS authserv-id
                           *( CFWS ";" CFWS mar-param ) CRLF

mar-param    = mar-result / mar-policy / mar-anomaly / mar-ext
mar-result   = "result=" ( "pass" / "ambiguous" / "fail" )
mar-policy   = "policy=" ( "accept" / "quarantine" /
                            "reject" / "sanitize" )
mar-anomaly  = "anomaly=" anomaly-code
anomaly-code = "dup-content-type" /
               "nul-in-header" /
               "empty-boundary" /
               "invalid-b64-char" /
               "qp-broken-softbreak" /
               "encoded-word-in-parameter" /
               x-anomaly
x-anomaly    = "x-" 1*(ALPHA / DIGIT / "-")
mar-ext      = token ["=" value]
]]></sourcecode>
        <t>
          The <tt>ALPHA</tt> and <tt>DIGIT</tt> rules are imported from
          <xref target="RFC5234"/>.
        </t>
      </section>

      <section anchor="mar-semantics">
        <name>Semantics</name>
        <t>
          <tt>result</tt> indicates the receiver's overall ambiguity
          assessment.  <tt>policy</tt> indicates the disposition taken by the
          receiver.  <tt>anomaly</tt> identifies one or more anomaly classes
          that contributed to the assessment.
        </t>
        <t>
          A receiver SHOULD place this field near other receiver-generated
          assessment fields.  A downstream consumer that uses the field for
          policy decisions MUST rely only on instances inserted by trusted
          infrastructure inside the same administrative domain.
        </t>
      </section>

      <section anchor="mar-example">
        <name>Example</name>
        <sourcecode type="text"><![CDATA[
MIME-Ambiguity-Results: mx.example.net; result=ambiguous;
  policy=quarantine; anomaly=dup-content-type;
  anomaly=invalid-b64-char
]]></sourcecode>
      </section>
    </section>

    <section anchor="ops-guidance">
      <name>Operational Deployment Guidance</name>
      <t>
        Deployments SHOULD introduce these checks in stages.  A common rollout
        sequence is:
      </t>
      <ol>
        <li>log-only anomaly detection;</li>
        <li>logging plus internal reporting via
        <tt>MIME-Ambiguity-Results</tt> or equivalent telemetry;</li>
        <li>quarantine for fatal anomalies and union-view disagreement; and</li>
        <li>selective SMTP rejection for classes shown to be low-noise and high
        confidence.</li>
      </ol>
      <t>
        Implementers SHOULD maintain a regression corpus of malformed and
        ambiguous messages and SHOULD use differential testing against supported
        downstream clients to verify that detector-side coverage remains at
        least as broad as client-side exposure.
      </t>
    </section>

    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>
        This entire document is about security.  The central security property
        is coverage equivalence: the detector-side scan view must not be
        narrower than the client-side exposure view.
      </t>
      <t>
        Overly aggressive message repair can itself create security problems.
        Receivers SHOULD avoid speculative rewriting that changes message
        structure or attachment semantics in ways not directly justified by
        local sanitization policy.
      </t>
      <t>
        The <tt>MIME-Ambiguity-Results</tt> header field is trustworthy only
        within a local administrative trust boundary.  Attackers can forge the
        field in received messages; therefore downstream consumers MUST ignore
        untrusted instances.
      </t>
      <t>
        Multi-view parsing increases computational cost and therefore creates a
        denial-of-service risk.  Implementations MUST enforce hard resource
        limits and fail closed when those limits are exceeded.
      </t>
    </section>

    <section anchor="privacy-considerations">
      <name>Privacy Considerations</name>
      <t>
        Union extraction and scanning can cause more message content to be
        processed than would be visible under a single parser.  Operators
        SHOULD review retention, access control, and data handling policies for
        extracted objects and scanner outputs.
      </t>
      <t>
        Receivers SHOULD avoid placing unnecessary high-entropy content-derived
        identifiers in <tt>MIME-Ambiguity-Results</tt>.  If deployments need
        richer forensic linkage, they SHOULD prefer internal telemetry systems
        over header fields that may later be forwarded outside the original
        trust boundary.
      </t>
    </section>

    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <t>
        This document has no IANA actions.
      </t>
      <t>
        The <tt>MIME-Ambiguity-Results</tt> header field defined in this
        document is intended for use within an administrative domain.  This
        document does not request registration of that field in an IANA message
        header field registry.
      </t>
    </section>
  </middle>

  <back>
    <references>
      <name>Normative References</name>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2045.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2046.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2047.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2183.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.5234.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.5322.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8601.xml"/>
    </references>

    <references>
      <name>Informative References</name>
      <reference anchor="INBOXINVASION" target="https://www.jianjunchen.com/p/inbox-invasion.CCS24.pdf">
        <front>
          <title>Inbox Invasion: Exploiting MIME Ambiguities to Evade Email Attachment Detectors</title>
          <author fullname="Jiahe Zhang"/>
          <author fullname="Jianjun Chen"/>
          <author fullname="Qi Wang"/>
          <author fullname="Hangyu Zhang"/>
          <author fullname="Chuhan Wang"/>
          <author fullname="Jianwei Zhuge"/>
          <author fullname="Haixin Duan"/>
          <date month="October" year="2024"/>
        </front>
        <seriesInfo name="CCS" value="2024"/>
      </reference>
    </references>
  </back>
</rfc>
