Skip to content

Commit

Permalink
Merge pull request #14 from FluffyDiscord/cookie_secure
Browse files Browse the repository at this point in the history
secure cookie is no longer ignored
  • Loading branch information
FluffyDiscord authored Jan 28, 2025
2 parents 2eaf086 + 24c7ce0 commit 3a3b52e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
param('session.metadata.update_threshold'),
]),
service(RequestStack::class),
false,
null,
])
;

Expand Down
18 changes: 15 additions & 3 deletions src/Session/WorkerSessionStorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface;
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
use Symfony\Contracts\Service\ResetInterface;

readonly class WorkerSessionStorageFactory implements SessionStorageFactoryInterface
{
Expand All @@ -24,19 +23,32 @@ public function __construct(
private ?MetadataBag $metaBag,

private RequestStack $requestStack,
private bool $secure = false,
private ?bool $secure = null,
)
{
if ($this->secure !== null) {
trigger_deprecation("fluffydiscord/roadrunner-symfony-bundle", "3.2.0", 'Passing "$secure" in constructor is deprecated, use framework.session options instead');
}
}

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

if ($this->secure && $request?->isSecure()) {
if ($this->isSecure($request)) {
$workerSessionStorage->setOptions(['cookie_secure' => true]);
}

return $workerSessionStorage;
}

private function isSecure(?Request $request): bool
{
$cookieSecure = $this->secure;
if ($cookieSecure === null) {
$cookieSecure = 'auto' === ($this->options['cookie_secure'] ?? null);
}

return $cookieSecure && $request?->isSecure();
}
}

0 comments on commit 3a3b52e

Please sign in to comment.