Skip to content

Commit 0a67abd

Browse files
authored
Merge pull request #8818 from kenjis/fix-incorrect-SecurityException-message
fix: incorrect Security exception message
2 parents 8738340 + fa06a8b commit 0a67abd

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

system/HTTP/ResponseTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ private function dispatchCookies(): void
670670

671671
foreach ($this->cookieStore->display() as $cookie) {
672672
if ($cookie->isSecure() && ! $request->isSecure()) {
673-
throw SecurityException::forDisallowedAction();
673+
throw SecurityException::forInsecureCookie();
674674
}
675675

676676
$name = $cookie->getPrefixedName();

system/Language/en/Security.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// Security language settings
1515
return [
1616
'disallowedAction' => 'The action you requested is not allowed.',
17+
'insecureCookie' => 'Attempted to send a secure cookie over a non-secure connection.',
1718

1819
// @deprecated
1920
'invalidSameSite' => 'The SameSite value must be None, Lax, Strict, or a blank string. Given: "{0}"',

system/Security/Exceptions/SecurityException.php

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class SecurityException extends FrameworkException implements HTTPExceptionInter
2020
{
2121
/**
2222
* Throws when some specific action is not allowed.
23+
* This is used for CSRF protection.
2324
*
2425
* @return static
2526
*/
@@ -28,6 +29,15 @@ public static function forDisallowedAction()
2829
return new static(lang('Security.disallowedAction'), 403);
2930
}
3031

32+
/**
33+
* Throws if a secure cookie is dispatched when the current connection is not
34+
* secure.
35+
*/
36+
public static function forInsecureCookie(): static
37+
{
38+
return new static(lang('Security.insecureCookie'));
39+
}
40+
3141
/**
3242
* Throws when the source string contains invalid UTF-8 characters.
3343
*

tests/system/HTTP/ResponseSendTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,11 @@ public function testRedirectResponseCookies(): void
162162

163163
/**
164164
* Make sure secure cookies are not sent with HTTP request
165-
*
166-
* @ runInSeparateProcess
167-
* @ preserveGlobalState disabled
168165
*/
169166
public function testDoNotSendUnSecureCookie(): void
170167
{
171168
$this->expectException(SecurityException::class);
172-
$this->expectExceptionMessage('The action you requested is not allowed');
169+
$this->expectExceptionMessage('Attempted to send a secure cookie over a non-secure connection.');
173170

174171
$request = $this->createMock(IncomingRequest::class);
175172
$request->method('isSecure')->willReturn(false);

user_guide_src/source/changelogs/v4.5.2.rst

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ BREAKING
1818
Message Changes
1919
***************
2020

21+
- Added ``Security.insecureCookie`` message.
22+
2123
*******
2224
Changes
2325
*******

0 commit comments

Comments
 (0)