Skip to content

Commit 3a3b52e

Browse files
Merge pull request #14 from FluffyDiscord/cookie_secure
secure cookie is no longer ignored
2 parents 2eaf086 + 24c7ce0 commit 3a3b52e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

config/services.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
param('session.metadata.update_threshold'),
9898
]),
9999
service(RequestStack::class),
100-
false,
100+
null,
101101
])
102102
;
103103

src/Session/WorkerSessionStorageFactory.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
1010
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface;
1111
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
12-
use Symfony\Contracts\Service\ResetInterface;
1312

1413
readonly class WorkerSessionStorageFactory implements SessionStorageFactoryInterface
1514
{
@@ -24,19 +23,32 @@ public function __construct(
2423
private ?MetadataBag $metaBag,
2524

2625
private RequestStack $requestStack,
27-
private bool $secure = false,
26+
private ?bool $secure = null,
2827
)
2928
{
29+
if ($this->secure !== null) {
30+
trigger_deprecation("fluffydiscord/roadrunner-symfony-bundle", "3.2.0", 'Passing "$secure" in constructor is deprecated, use framework.session options instead');
31+
}
3032
}
3133

3234
public function createStorage(?Request $request): SessionStorageInterface
3335
{
3436
$workerSessionStorage = new WorkerSessionStorage($this->options, $this->handler, $this->metaBag, $this->requestStack);
3537

36-
if ($this->secure && $request?->isSecure()) {
38+
if ($this->isSecure($request)) {
3739
$workerSessionStorage->setOptions(['cookie_secure' => true]);
3840
}
3941

4042
return $workerSessionStorage;
4143
}
44+
45+
private function isSecure(?Request $request): bool
46+
{
47+
$cookieSecure = $this->secure;
48+
if ($cookieSecure === null) {
49+
$cookieSecure = 'auto' === ($this->options['cookie_secure'] ?? null);
50+
}
51+
52+
return $cookieSecure && $request?->isSecure();
53+
}
4254
}

0 commit comments

Comments
 (0)