Skip to content

Commit

Permalink
fix: Fix incorrect typing of 'same_site' cookie option
Browse files Browse the repository at this point in the history
The 'same_site' value was always expected to be a bool, even though it would always be 'string', 'lax', 'none' or null
  • Loading branch information
ollieread committed Dec 23, 2024
1 parent e8e89e0 commit ae345be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Overrides/CookieOverride.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function setup(Tenancy $tenancy, Tenant $tenant): void
$path = settings()->getUrlPath(config('session.path') ?? '/'); // @phpstan-ignore-line
$domain = settings()->getUrlDomain(config('session.domain')); // @phpstan-ignore-line
$secure = settings()->shouldCookieBeSecure(config('session.secure', false)); // @phpstan-ignore-line
$sameSite = settings()->shouldCookeBeSameSite(config('session.same_site')); // @phpstan-ignore-line
$sameSite = settings()->getCookieSameSite(config('session.same_site')); // @phpstan-ignore-line

/**
* This is here to make PHPStan quiet down
Expand Down
2 changes: 1 addition & 1 deletion src/Overrides/SessionOverride.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function setup(Tenancy $tenancy, Tenant $tenant): void
}

if ($settings->has(Settings::COOKIE_SAME_SITE)) {
$config->set('session.same_site', $settings->shouldCookeBeSameSite());
$config->set('session.same_site', $settings->getCookieSameSite());
}

$config->set('session.cookie', $this->getCookieName($tenancy, $tenant));
Expand Down
14 changes: 11 additions & 3 deletions src/Support/SettingsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ public function shouldCookieBeSecure(?bool $default = null): bool
return $this->boolean(Settings::COOKIE_SECURE, $default);
}

public function setCookieSameSite(bool $sameSite): void
public function setCookieSameSite(?string $sameSite): void
{
$this->set(Settings::COOKIE_SAME_SITE, $sameSite);
}

public function shouldCookeBeSameSite(?bool $default = null): bool
public function getCookieSameSite(?string $default = null): ?string
{
return $this->boolean(Settings::COOKIE_SAME_SITE, $default);
/**
* This is only here because the config repository has terrible support
* for typing, as you'd expect.
*
* @var string|null $sameSite
*/
$sameSite = $this->get(Settings::COOKIE_SAME_SITE, $default);

return $sameSite;
}

public function doNotOverrideTheDatabase(): void
Expand Down

0 comments on commit ae345be

Please sign in to comment.