|
10 | 10 | namespace ZendTest\Mail\Transport; |
11 | 11 |
|
12 | 12 | use Zend\Mail\Message; |
| 13 | +use Zend\Mail\Transport\Exception\RuntimeException; |
13 | 14 | use Zend\Mail\Transport\Sendmail; |
14 | 15 |
|
15 | 16 | /** |
@@ -133,4 +134,28 @@ public function testAssertSubjectEncoded() |
133 | 134 | $this->transport->send($message); |
134 | 135 | $this->assertEquals('=?UTF-8?Q?Testing=20Zend\Mail\Transport\Sendmail?=', $this->subject); |
135 | 136 | } |
| 137 | + |
| 138 | + public function testCodeInjectionInFromHeader() |
| 139 | + { |
| 140 | + $message = $this->getMessage(); |
| 141 | + $message->setBody('This is the text of the email.'); |
| 142 | + $message->setFrom('"AAA\" code injection"@domain', 'Sender\'s name'); |
| 143 | + $message->addTo('hacker@localhost', 'Name of recipient'); |
| 144 | + $message->setSubject('TestSubject'); |
| 145 | + |
| 146 | + $this->setExpectedException(RuntimeException::class); |
| 147 | + $this->transport->send($message); |
| 148 | + } |
| 149 | + |
| 150 | + public function testValidEmailLocaDomainInFromHeader() |
| 151 | + { |
| 152 | + $message = $this->getMessage(); |
| 153 | + $message->setBody('This is the text of the email.'); |
| 154 | + $message->setFrom('"foo-bar"@domain', 'Foo Bar'); |
| 155 | + $message->addTo('hacker@localhost', 'Name of recipient'); |
| 156 | + $message->setSubject('TestSubject'); |
| 157 | + |
| 158 | + $this->transport->send($message); |
| 159 | + $this->assertContains('From: Foo Bar <"foo-bar"@domain>', $this->additional_headers); |
| 160 | + } |
136 | 161 | } |
0 commit comments