Skip to content

Commit

Permalink
Use more secure boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed May 25, 2016
1 parent 625a9b4 commit 0259741
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Mailer/Email.php
Expand Up @@ -22,6 +22,7 @@
use Cake\Log\Log;
use Cake\Network\Http\FormData\Part;
use Cake\Utility\Hash;
use Cake\Utility\Security;
use Cake\Utility\Text;
use Cake\View\ViewVarsTrait;
use Closure;
Expand Down Expand Up @@ -1610,7 +1611,7 @@ protected function _wrap($message, $wrapLength = Email::LINE_LENGTH_MUST)
protected function _createBoundary()
{
if (!empty($this->_attachments) || $this->_emailFormat === 'both') {
$this->_boundary = md5(uniqid(time()));
$this->_boundary = md5(Security::randomBytes(16));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Network/Http/FormData.php
Expand Up @@ -14,6 +14,7 @@
namespace Cake\Network\Http;

use Cake\Network\Http\FormData\Part;
use Cake\Utility\Security;
use Countable;
use finfo;

Expand Down Expand Up @@ -66,7 +67,7 @@ public function boundary()
if ($this->_boundary) {
return $this->_boundary;
}
$this->_boundary = md5(uniqid(time()));
$this->_boundary = md5(Security::randomBytes(16));
return $this->_boundary;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Mailer/EmailTest.php
Expand Up @@ -2071,7 +2071,7 @@ public function testRenderWithLayoutAndAttachment()
$this->assertNotEmpty($result);

$result = $this->CakeEmail->getBoundary();
$this->assertNotEmpty($result);
$this->assertRegExp('/^[0-9a-f]{32}$/', $result);
}

/**
Expand Down

0 comments on commit 0259741

Please sign in to comment.