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

Always escape shell arguments before mail() #140

Merged
merged 4 commits into from Jun 8, 2017

Conversation

paragonie-scott
Copy link
Contributor

No description provided.

@Ocramius
Copy link
Member

Ocramius commented May 5, 2017

Pretty much agree with the patch, but I'm cracking my whip about test changes that need to be made.

@paragonie-scott
Copy link
Contributor Author

I'm doing it one-file-at-a-time because I'm using github.com, but sure :)

@Ocramius
Copy link
Member

Ocramius commented May 5, 2017

Some existing tests will also need fixing. I will try prioritizing this today, as it kinda looks bad :|

@paragonie-scott
Copy link
Contributor Author

Yeah :\

@Ocramius
Copy link
Member

Ocramius commented May 6, 2017

Sorry, didn't get to it due to IRL issues. I'll work on it asap.

@Ocramius
Copy link
Member

Ocramius commented May 8, 2017

So, I picked this up, and an exception is fired very early on (while setting the From: on the Message object), so a different string needs to be forged in order to get to a reproducible failure.

As discussed with @paragonie-scott, this is not a security issue report, but just hardening the test suite and improving current reliability against the already reported CVE.

@paragonie-scott
Copy link
Contributor Author

an exception is fired very early on

That means ZF2 is safe, given a typical usage. This is just defense in depth. :)

@Ocramius
Copy link
Member

Ocramius commented May 8, 2017

@paragonie-scott the fact that the shell arg escaping is not applied is still bothersome, so the test should indeed verify the exception as it does before paragonie-scott/zend@7551343, but with a different escape sequence (valid domain, valid mail, shell escape).

One possible approach I can think of is to mock the Message object (so we verify that even if you want to hurt yourself, the Sendmail adapter will not allow you to do so)

paragonie-security added a commit to paragonie/airship that referenced this pull request May 13, 2017
@paragonie-scott
Copy link
Contributor Author

I'm really not sure how to do fancy stuff with object mocking in unit tests. :\

It looks like the underlying issue was reported previously as ZF2016-04, but the fix was incomplete.

weierophinney added a commit to paragonie-scott/zend-mail that referenced this pull request Jun 8, 2017
Always escape shell arguments before mail()
weierophinney added a commit to paragonie-scott/zend-mail that referenced this pull request Jun 8, 2017
This patch refactors the new test for zendframework#140 as follows:

- Moves the test `SendmailTest::testSecondCodeInjectionInFromHeader()`
  to `MessageTest`
- Updates that test to expect an `InvalidArgumentException` instead of a `RuntimeException`.
- Updates that test to simply instantiate the message, and then call
  `setFrom()`, as that's all that's necessary to trigger the exception.
- Adds two new tests to `SendmailTest`:
  - `testPrepareParametersEscapesSenderUsingEscapeShellArg` tests
    that a malformed sender address will be escaped.
  - `testPrepareParametersEscapesFromAddressUsingEscapeShellArg` tests
    that a malformed from address will be escaped.

These last two conditions should not occur, but could occur if somebody
were to provide custom From/Sender implementations that did not contain
the checks we currently have that prevent invalid arguments.
paragonie-scott and others added 4 commits June 8, 2017 14:12
This patch refactors the new test for zendframework#140 as follows:

- Moves the test `SendmailTest::testSecondCodeInjectionInFromHeader()`
  to `MessageTest`
- Updates that test to expect an `InvalidArgumentException` instead of a `RuntimeException`.
- Updates that test to simply instantiate the message, and then call
  `setFrom()`, as that's all that's necessary to trigger the exception.
- Adds two new tests to `SendmailTest`:
  - `testPrepareParametersEscapesSenderUsingEscapeShellArg` tests
    that a malformed sender address will be escaped.
  - `testPrepareParametersEscapesFromAddressUsingEscapeShellArg` tests
    that a malformed from address will be escaped.

These last two conditions should not occur, but could occur if somebody
were to provide custom From/Sender implementations that did not contain
the checks we currently have that prevent invalid arguments.
@weierophinney
Copy link
Member

Hey, @paragonie-scott — I've pushed a commit to your branch that performs the testing that @Ocramius suggested. If travis looks okay (minus expected issues with the zend-servicemanager compat tests), I'll merge this today.

Thanks!

@weierophinney weierophinney merged commit 9fc21ed into zendframework:master Jun 8, 2017
weierophinney added a commit that referenced this pull request Jun 8, 2017
weierophinney added a commit that referenced this pull request Jun 8, 2017
Forward port #140

Conflicts:
	test/Transport/SendmailTest.php
weierophinney added a commit that referenced this pull request Jun 8, 2017
@paragonie-scott paragonie-scott deleted the patch-2 branch June 8, 2017 19:30
glensc referenced this pull request in PHPMailer/PHPMailer Feb 27, 2023
Validate Sender address
Consistent use of empty()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants