Skip to content

Commit

Permalink
Merge pull request #11 from wdhaoui/feature/add-http-only-config
Browse files Browse the repository at this point in the history
feat(Cookies): add new option httpOnly
  • Loading branch information
dneustadt authored Jun 21, 2023
2 parents b43623f + 3f8ccd0 commit 58c4b2b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->integerNode('expire')->defaultValue(0)->end()
->scalarNode('path')->cannotBeEmpty()->defaultValue('/')->end()
->scalarNode('domain')->defaultNull()->end()
->booleanNode('httpOnly')->defaultFalse()->end()
->booleanNode('secure')->defaultFalse()->end()
->scalarNode('header')->cannotBeEmpty()->defaultValue('X-XSRF-TOKEN')->end()
->scalarNode('sameSite')->cannotBeEmpty()->defaultValue(Cookie::SAMESITE_LAX)->end()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/DneustadtCsrfCookieExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('dneustadt_csrf_cookie.expire', $config['expire']);
$container->setParameter('dneustadt_csrf_cookie.path', $config['path']);
$container->setParameter('dneustadt_csrf_cookie.domain', $config['domain']);
$container->setParameter('dneustadt_csrf_cookie.httpOnly', $config['httpOnly']);
$container->setParameter('dneustadt_csrf_cookie.secure', $config['secure']);
$container->setParameter('dneustadt_csrf_cookie.header', $config['header']);
$container->setParameter('dneustadt_csrf_cookie.sameSite', $config['sameSite']);
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ dneustadt_csrf_cookie:
path: /
# Cookie domain
domain: null
# Cookie HttpOnly
httpOnly: true
# Cookie secure
secure: false
# Name of the HTTP header the token is expected to be stored in
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
$cookieExpire: '%dneustadt_csrf_cookie.expire%'
$cookiePath: '%dneustadt_csrf_cookie.path%'
$cookieDomain: '%dneustadt_csrf_cookie.domain%'
$cookieHttpOnly: '%dneustadt_csrf_cookie.httpOnly%'
$cookieSecure: '%dneustadt_csrf_cookie.secure%'
$cookieHeader: '%dneustadt_csrf_cookie.header%'
$cookieSameSite: '%dneustadt_csrf_cookie.sameSite%'
Expand Down
9 changes: 8 additions & 1 deletion Service/CsrfRequestEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class CsrfRequestEvaluator
*/
protected $cookieDomain;

/**
* @var bool
*/
protected $cookieHttpOnly;

/**
* @var bool
*/
Expand All @@ -75,6 +80,7 @@ public function __construct(
int $cookieExpire,
string $cookiePath,
?string $cookieDomain,
bool $cookieHttpOnly,
bool $cookieSecure,
string $cookieHeader,
string $cookieSameSite
Expand All @@ -86,6 +92,7 @@ public function __construct(
$this->cookieExpire = $cookieExpire;
$this->cookiePath = $cookiePath;
$this->cookieDomain = $cookieDomain;
$this->cookieHttpOnly = $cookieHttpOnly;
$this->cookieSecure = $cookieSecure;
$this->cookieHeader = $cookieHeader;
$this->cookieSameSite = $cookieSameSite;
Expand Down Expand Up @@ -143,7 +150,7 @@ public function setCookie(Request $request, Response $response): void
$this->cookiePath,
$this->cookieDomain,
$this->cookieSecure,
false,
$this->cookieHttpOnly,
false,
$this->cookieSameSite
)
Expand Down

0 comments on commit 58c4b2b

Please sign in to comment.