Skip to content

Commit ddba8ed

Browse files
committed
added Helpers::initCookie()
1 parent 4cb9b01 commit ddba8ed

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/Bridges/HttpDI/HttpExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function sendHeaders()
120120
}
121121
}
122122

123-
$this->initialization->addBody('$response->setCookie(...?);', [['nette-samesite', '1', 0, '/', null, null, true, 'Strict']]);
123+
$this->initialization->addBody('Nette\Http\Helpers::initCookie($response);');
124124
}
125125

126126

src/Http/Helpers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ final class Helpers
2020
{
2121
use Nette\StaticClass;
2222

23+
/** @internal */
24+
public const STRICT_COOKIE_NAME = 'nette-samesite';
25+
26+
2327
/**
2428
* Returns HTTP valid date format.
2529
* @param string|int|\DateTimeInterface $time
@@ -46,4 +50,10 @@ public static function ipMatch(string $ip, string $mask): bool
4650
}
4751
return strncmp($ip, $mask, $size === '' ? $max : (int) $size) === 0;
4852
}
53+
54+
55+
public static function initCookie(IResponse $response)
56+
{
57+
$response->setCookie(self::STRICT_COOKIE_NAME, '1', 0, '/', null, null, true, 'Strict');
58+
}
4959
}

src/Http/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function isSecured(): bool
239239
*/
240240
public function isSameSite(): bool
241241
{
242-
return isset($this->cookies['nette-samesite']);
242+
return isset($this->cookies[Helpers::STRICT_COOKIE_NAME]);
243243
}
244244

245245

0 commit comments

Comments
 (0)