Skip to content

Commit 9be9046

Browse files
committed
Fix a bug where EE CSRF cookies could be encrypted by Laravel
1 parent 368509c commit 9be9046

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- Bug where ExpressionEngine CSRF cookies could be encrypted by Laravel
8+
59
## [1.3.0] - 2024-03-18
610

711
### Added

src/Middleware/EncryptCookies.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@
22

33
namespace Expressionengine\Coilpack\Middleware;
44

5-
use Closure;
65
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
76

87
class EncryptCookies extends Middleware
98
{
109
/**
11-
* Handle an incoming request.
10+
* Determine whether encryption has been disabled for the given cookie.
1211
*
13-
* @param \Illuminate\Http\Request $request
14-
* @return \Symfony\Component\HttpFoundation\Response
12+
* @param string $name
13+
* @return bool
1514
*/
16-
public function handle($request, Closure $next)
15+
public function isDisabled($name)
1716
{
18-
$prefix = app('ee')->config->item('cookie_prefix') ?: 'exp_';
19-
20-
foreach ($request->cookies->keys() as $key) {
21-
if (strpos($key, $prefix) === 0) {
22-
$this->disableFor($key);
23-
}
17+
// If this is not Laravel's session cookie and it matches ExpressionEngine's
18+
// cookie prefix then we will disable Laravel's encryption on the cookie
19+
if ($name !== config('session.cookie') && strpos($name, $this->getPrefix()) === 0) {
20+
return true;
2421
}
2522

26-
return parent::handle($request, $next);
23+
return parent::isDisabled($name);
24+
}
25+
26+
/**
27+
* Get the prefix ExpressionEngine is using for its cookie names
28+
*
29+
* @return string
30+
*/
31+
protected function getPrefix()
32+
{
33+
return app('ee')->config->item('cookie_prefix') ?: 'exp_';
2734
}
2835
}

0 commit comments

Comments
 (0)