mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-03 21:54:07 +09:00
Harden session cookie handling and simplify legacy tests (#3570)
* Initial plan * fix session cookie handling and clean legacy tests Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/9e1e623b-d220-42b5-a434-5ddee8324bc3 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * Fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Remove incomplete EntityManagerFactory test instead of leaving markTestIncomplete placeholder Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/48e905a2-4d3c-4b73-93b4-de6101030d14 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> Co-authored-by: Adam Daley <admdly@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
3 files changed
+29
-47
No files matched your search
@@ -58,7 +58,7 @@ class Session implements InjectionAwareInterface
|
||||
'httponly' => $currentCookieParams['httponly'],
|
||||
];
|
||||
|
||||
if (Config::getProperty('security.mode', 'strict') == 'strict') {
|
||||
if (Config::getProperty('security.mode', 'strict') === 'strict') {
|
||||
$cookieParams['samesite'] = 'Strict';
|
||||
}
|
||||
|
||||
@@ -168,6 +168,20 @@ class Session implements InjectionAwareInterface
|
||||
if ($invalid) {
|
||||
$this->di['db']->trash($session);
|
||||
if ($sessionName !== '') {
|
||||
$cookieParams = session_get_cookie_params();
|
||||
$cookieOptions = [
|
||||
'expires' => time() - 3600,
|
||||
'path' => $cookieParams['path'] ?? '/',
|
||||
'domain' => $cookieParams['domain'] ?? '',
|
||||
'secure' => (bool) ($cookieParams['secure'] ?? false),
|
||||
'httponly' => (bool) ($cookieParams['httponly'] ?? false),
|
||||
];
|
||||
|
||||
if (!empty($cookieParams['samesite'])) {
|
||||
$cookieOptions['samesite'] = $cookieParams['samesite'];
|
||||
}
|
||||
|
||||
setcookie($sessionName, '', $cookieOptions);
|
||||
unset($_COOKIE[$sessionName]);
|
||||
}
|
||||
}
|
||||
@@ -224,8 +238,20 @@ class Session implements InjectionAwareInterface
|
||||
session_regenerate_id(false);
|
||||
|
||||
$sessionName = session_name();
|
||||
if ($sessionName !== '') {
|
||||
$_COOKIE[$sessionName] = session_id();
|
||||
$sessionId = session_id();
|
||||
if ($sessionName !== '' && $sessionId !== '') {
|
||||
$params = session_get_cookie_params();
|
||||
|
||||
setcookie($sessionName, $sessionId, [
|
||||
'expires' => 0,
|
||||
'path' => $params['path'] ?? '/',
|
||||
'domain' => $params['domain'] ?? '',
|
||||
'secure' => (bool) ($params['secure'] ?? false),
|
||||
'httponly' => (bool) ($params['httponly'] ?? true),
|
||||
'samesite' => $params['samesite'] ?? 'Lax',
|
||||
]);
|
||||
|
||||
$_COOKIE[$sessionName] = $sessionId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use FOSSBilling\Doctrine\EntityManagerFactory;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Filesystem\Path;
|
||||
|
||||
#[Group('Core')]
|
||||
final class FOSSBilling_Doctrine_EntityManagerFactoryTest extends BBTestCase
|
||||
{
|
||||
public function testCacheNamespaceSeedChangesWhenEntityDefinitionChanges(): void
|
||||
{
|
||||
$filesystem = new Filesystem();
|
||||
$directory = Path::join(sys_get_temp_dir(), 'fb-doctrine-seed-' . bin2hex(random_bytes(8)));
|
||||
$file = Path::join($directory, 'Currency.php');
|
||||
|
||||
try {
|
||||
$filesystem->mkdir($directory);
|
||||
$filesystem->dumpFile($file, "<?php\nfinal class Currency {}\n");
|
||||
|
||||
$seedBefore = $this->invokePrivateStaticMethod('getCacheNamespaceSeed', [[$directory]]);
|
||||
|
||||
sleep(1);
|
||||
$filesystem->dumpFile($file, "<?php\nfinal class Currency { public string \$code; }\n");
|
||||
|
||||
$seedAfter = $this->invokePrivateStaticMethod('getCacheNamespaceSeed', [[$directory]]);
|
||||
|
||||
$this->assertNotSame($seedBefore, $seedAfter);
|
||||
} finally {
|
||||
$filesystem->remove($directory);
|
||||
}
|
||||
}
|
||||
|
||||
private function invokePrivateStaticMethod(string $method, array $args = []): mixed
|
||||
{
|
||||
$reflection = new ReflectionClass(EntityManagerFactory::class);
|
||||
$methodReflection = $reflection->getMethod($method);
|
||||
|
||||
return $methodReflection->invokeArgs(null, $args);
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,6 @@ final class GuestTest extends \BBTestCase
|
||||
->willReturn(true);
|
||||
|
||||
$toolsMock = $this->createMock(\FOSSBilling\Tools::class);
|
||||
// $toolsMock->expects($this->atLeastOnce())->method('validateAndSanitizeEmail');
|
||||
|
||||
$di = $this->getDi();
|
||||
$di['events_manager'] = $eventMock;
|
||||
|
||||
Reference in new issue
Block a user