Skip to content

Commit 58c4b2b

Browse files
authored
Merge pull request #11 from wdhaoui/feature/add-http-only-config
feat(Cookies): add new option httpOnly
2 parents b43623f + 3f8ccd0 commit 58c4b2b

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function getConfigTreeBuilder(): TreeBuilder
2323
->integerNode('expire')->defaultValue(0)->end()
2424
->scalarNode('path')->cannotBeEmpty()->defaultValue('/')->end()
2525
->scalarNode('domain')->defaultNull()->end()
26+
->booleanNode('httpOnly')->defaultFalse()->end()
2627
->booleanNode('secure')->defaultFalse()->end()
2728
->scalarNode('header')->cannotBeEmpty()->defaultValue('X-XSRF-TOKEN')->end()
2829
->scalarNode('sameSite')->cannotBeEmpty()->defaultValue(Cookie::SAMESITE_LAX)->end()

DependencyInjection/DneustadtCsrfCookieExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function load(array $configs, ContainerBuilder $container): void
2222
$container->setParameter('dneustadt_csrf_cookie.expire', $config['expire']);
2323
$container->setParameter('dneustadt_csrf_cookie.path', $config['path']);
2424
$container->setParameter('dneustadt_csrf_cookie.domain', $config['domain']);
25+
$container->setParameter('dneustadt_csrf_cookie.httpOnly', $config['httpOnly']);
2526
$container->setParameter('dneustadt_csrf_cookie.secure', $config['secure']);
2627
$container->setParameter('dneustadt_csrf_cookie.header', $config['header']);
2728
$container->setParameter('dneustadt_csrf_cookie.sameSite', $config['sameSite']);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ dneustadt_csrf_cookie:
4040
path: /
4141
# Cookie domain
4242
domain: null
43+
# Cookie HttpOnly
44+
httpOnly: true
4345
# Cookie secure
4446
secure: false
4547
# Name of the HTTP header the token is expected to be stored in

Resources/config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
$cookieExpire: '%dneustadt_csrf_cookie.expire%'
1212
$cookiePath: '%dneustadt_csrf_cookie.path%'
1313
$cookieDomain: '%dneustadt_csrf_cookie.domain%'
14+
$cookieHttpOnly: '%dneustadt_csrf_cookie.httpOnly%'
1415
$cookieSecure: '%dneustadt_csrf_cookie.secure%'
1516
$cookieHeader: '%dneustadt_csrf_cookie.header%'
1617
$cookieSameSite: '%dneustadt_csrf_cookie.sameSite%'

Service/CsrfRequestEvaluator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class CsrfRequestEvaluator
5252
*/
5353
protected $cookieDomain;
5454

55+
/**
56+
* @var bool
57+
*/
58+
protected $cookieHttpOnly;
59+
5560
/**
5661
* @var bool
5762
*/
@@ -75,6 +80,7 @@ public function __construct(
7580
int $cookieExpire,
7681
string $cookiePath,
7782
?string $cookieDomain,
83+
bool $cookieHttpOnly,
7884
bool $cookieSecure,
7985
string $cookieHeader,
8086
string $cookieSameSite
@@ -86,6 +92,7 @@ public function __construct(
8692
$this->cookieExpire = $cookieExpire;
8793
$this->cookiePath = $cookiePath;
8894
$this->cookieDomain = $cookieDomain;
95+
$this->cookieHttpOnly = $cookieHttpOnly;
8996
$this->cookieSecure = $cookieSecure;
9097
$this->cookieHeader = $cookieHeader;
9198
$this->cookieSameSite = $cookieSameSite;
@@ -143,7 +150,7 @@ public function setCookie(Request $request, Response $response): void
143150
$this->cookiePath,
144151
$this->cookieDomain,
145152
$this->cookieSecure,
146-
false,
153+
$this->cookieHttpOnly,
147154
false,
148155
$this->cookieSameSite
149156
)

0 commit comments

Comments
 (0)