Skip to content
This repository was archived by the owner on Dec 28, 2020. It is now read-only.

Commit a329aa2

Browse files
iambrosidunglas
authored andcommitted
Define all Cookie arguments explicitly (#58)
* Define all Cookie arguments explicitly This adds support for Symfony 4.2, which deprecates not defining all the arguments as some of their default values are scheduled to change in Symfony 5.0. * Set Cookie $sameSite as `lax` instead of null This is the default value as of Symfony 4.2, and makes cookies safer as they won't be sent along with cross-site requests. Also, added missing prediction when registering the cookie in the ResponseHeaderBag. * Define PHP version in cinst instruction This ensures appveyor uses PHP 7.2 and not a default version(currently 7.3) * Fixed tests after new method call in Symfony 4.2.6 and 3.4.25
1 parent 4d50e23 commit a329aa2

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

EventListener/AngularCsrfCookieListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public function onKernelResponse(FilterResponseEvent $event)
102102
$this->cookiePath,
103103
$this->cookieDomain,
104104
$this->cookieSecure,
105-
false
105+
false /* httpOnly */,
106+
false /* raw */,
107+
Cookie::SAMESITE_LAX
106108
));
107109
}
108110
}

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ init:
1010

1111
install:
1212
- ps: Set-Service wuauserv -StartupType Manual
13-
- cinst -y php
13+
- cinst -y php --version 7.2.17
1414
- cd c:\tools\php72
1515
- copy php.ini-production php.ini /Y
1616
- echo date.timezone="UTC" >> php.ini

spec/Dunglas/AngularCsrfBundle/DependencyInjection/DunglasAngularCsrfExtensionSpec.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function it_loads(ContainerBuilder $container, ParameterBagInterface $par
6060
$container->addResource(Argument::type('Symfony\Component\Config\Resource\FileResource'))->shouldBeCalled();
6161
}
6262

63+
if (method_exists('Symfony\Component\DependencyInjection\ContainerBuilder', 'addRemovedBindingIds')) {
64+
// Added in Symfony v4.2.6 and v3.4.25
65+
$container->addRemovedBindingIds(Argument::type('string'))->willReturn(null);
66+
}
67+
6368
$container->getParameterBag()->willReturn($parameterBag)->shouldBeCalled();
6469
$container->hasExtension('http://symfony.com/schema/dic/services')->willReturn(false)->shouldBeCalled();
6570
$container->setParameter('dunglas_angular_csrf.token.id', $configs['dunglas_angular_csrf']['token']['id'])->shouldBeCalled();

spec/Dunglas/AngularCsrfBundle/EventListener/AngularCsrfCookieListenerSpec.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ public function it_sets_cookie_when_it_does(
7979
Response $response,
8080
ResponseHeaderBag $headers
8181
) {
82-
$headers->setCookie(Argument::type('Symfony\Component\HttpFoundation\Cookie'));
82+
$headers->setCookie(Argument::allOf(
83+
Argument::type('Symfony\Component\HttpFoundation\Cookie'),
84+
Argument::which('getSameSite', 'lax')
85+
))->shouldBeCalled();
8386
$response->headers = $headers;
8487

8588
$event->getRequestType()->willReturn(HttpKernelInterface::MASTER_REQUEST)->shouldBeCalled();

0 commit comments

Comments
 (0)