Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

[mail/mime] Fix content-type has invalid characters in field value. Fix #7503 #7510

Closed
wants to merge 2 commits into from
Closed

[mail/mime] Fix content-type has invalid characters in field value. Fix #7503 #7510

wants to merge 2 commits into from

Conversation

Maks3w
Copy link
Member

@Maks3w Maks3w commented May 10, 2015

This bug has been introduced in v2.4.1 due the security patch ZF2015-04 for to prevent CRLF injection.

Zend\Mime\Part line was originally introduced in ZF1@583 with the following commit message

  • Correctly handle multipart/alternative to close Service\Amazon: SimpleDb and Authentication services ported #59:
    • If both text and html body present, create multipart/alternative part
    • If text, html, and attachments are present, create multipart/alternative
      part for text+html, but mark email as multipart/mixed
  • Note: Zend_Mime::LINEEND as \r\n is causing issues on multipart emails (too
    many line breaks); switching to \n fixes the issue, but doesn't follow
    standards. Need reviewers.

Zend_Mime::LINEEND was replaced by $EOL argument on ZF1@598 with the following commit message

RFC 2045 section 5.1 defines the syntax of Content-Type Header field as this (only relevant parts of the syntax posted):

In the Augmented BNF notation of RFC 822, a Content-Type header field
value is defined as follows:

content := "Content-Type" ":" type "/" subtype
           *(";" parameter)
           ; Matching of media type and subtype
           ; is ALWAYS case-insensitive.

parameter := attribute "=" value

attribute := token
             ; Matching of attributes
             ; is ALWAYS case-insensitive.

value := token / quoted-string

token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
         or tspecials>

tspecials :=  "(" / ")" / "<" / ">" / "@" /
              "," / ";" / ":" / "\" / <">
              "/" / "[" / "]" / "?" / "="
              ; Must be in quoted-string,
              ; to use within parameter values

Finally on ZF2 has been duplicated the same behavior on Zend\Mail\Header\ContentType

297ba86#diff-78a765eeca5dcb0c4d8fa594675622f6R76

This bug has been introduced in v2.4.1 due the security patch ZF2015-04 for to prevent CRLF injection.

Zend\Mime\Part line was originally introduced in ZF1@583 with the following commit message

> * Correctly handle multipart/alternative to close #59:
>   * If both text and html body present, create multipart/alternative part
>   * If text, html, and attachments are present, create multipart/alternative
>     part for text+html, but mark email as multipart/mixed
> * Note: Zend_Mime::LINEEND as \r\n is causing issues on multipart emails (too
>   many line breaks); switching to \n fixes the issue, but doesn't follow
>   standards. Need reviewers.

Zend_Mime::LINEEND was replaced by $EOL argument on ZF1@598 with the following commit message

> * Refactoring of Zend_Mail/Zend_Mime; mail message construction happens in
>   transport. Fixes #134 and #106.

RFC 2045 section 5.1 defines the syntax of Content-Type Header field as this (only relevant parts of the syntax posted):

> In the Augmented BNF notation of RFC 822, a Content-Type header field
> value is defined as follows:
>
> ```
> content := "Content-Type" ":" type "/" subtype
>            *(";" parameter)
>            ; Matching of media type and subtype
>            ; is ALWAYS case-insensitive.
>
> parameter := attribute "=" value
>
> attribute := token
>              ; Matching of attributes
>              ; is ALWAYS case-insensitive.
>
> value := token / quoted-string
>
> token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
>          or tspecials>
>
> tspecials :=  "(" / ")" / "<" / ">" / "@" /
>               "," / ";" / ":" / "\" / <">
>               "/" / "[" / "]" / "?" / "="
>               ; Must be in quoted-string,
>               ; to use within parameter values
> ```

Finally on ZF2 has been duplicated the same behavior on Zend\Mail\Header\ContentType

297ba86#diff-78a765eeca5dcb0c4d8fa594675622f6R76
@Maks3w Maks3w added this to the 2.4.2 milestone May 10, 2015
@Maks3w Maks3w changed the title [mail/mime] Fix content-type has invalid characters in field value [mail/mime] Fix content-type has invalid characters in field value. Fix #7503 May 10, 2015
@Maks3w
Copy link
Member Author

Maks3w commented May 10, 2015

Seems to break each parameter in his own line is just a cosmetic change for pretty print the header using the header folding feature.

Fix:

  • Generation of headers with EOL in Zend\Mime\Part

Don't fix:

  • Generation of headers with EOL in Zend\Mail\Headers\Content-type
  • Headers with folding sequences when call HeaderInterface::fromString()

@weierophinney
Copy link
Member

Just a note for those coming to this issue: ContentType currently uses Headers::FOLDING, and not a hard-coded inline sequence: https://github.com/zendframework/zf2/blob/master/library/Zend/Mail/Header/ContentType.php#L72

@@ -165,7 +165,7 @@ public function getParameter($name)
if (isset($this->parameters[$name])) {
return $this->parameters[$name];
}
return;
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have a return statement at all?

@Maks3w Maks3w closed this May 11, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse Error: T_OBJECT_OPERATOR in \Zend\Tool\Framework\Client\Console\Manifest.php
2 participants