Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d0ded92

Browse filesBrowse files
committed
bug #38367 [RateLimiter] Fix cache storage (use namespaced pool + remove \Serializable) (wouterj)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [RateLimiter] Fix cache storage (use namespaced pool + remove \Serializable) | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #38365, fix #38338 | License | MIT | Doc PR | - Commits ------- 251c202 Use a dedicated cache.rate_limiter cache pool 5dc562a Use __sleep/__wakeup instead of Serializable
2 parents 67a7be2 + 251c202 commit d0ded92
Copy full SHA for d0ded92

File tree

7 files changed

+33
-17
lines changed
Filter options

7 files changed

+33
-17
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ private function addRateLimiterSection(ArrayNodeDefinition $rootNode)
18081808
->end()
18091809
->scalarNode('cache_pool')
18101810
->info('The cache pool to use for storing the current limiter state')
1811-
->defaultValue('cache.app')
1811+
->defaultValue('cache.rate_limiter')
18121812
->end()
18131813
->scalarNode('storage_service')
18141814
->info('The service ID of a custom storage implementation, this precedes any configured "cache_pool"')

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,9 @@ private function registerRateLimiterConfiguration(array $config, ContainerBuilde
22542254

22552255
public static function registerRateLimiter(ContainerBuilder $container, string $name, array $limiterConfig)
22562256
{
2257+
// default configuration (when used by other DI extensions)
2258+
$limiterConfig += ['lock_factory' => 'lock.factory', 'cache_pool' => 'cache.rate_limiter'];
2259+
22572260
$limiter = $container->setDefinition($limiterId = 'limiter.'.$name, new ChildDefinition('limiter'));
22582261

22592262
$limiter->addArgument(new Reference($limiterConfig['lock_factory']));

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/rate_limiter.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/rate_limiter.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
return static function (ContainerConfigurator $container) {
1717
$container->services()
18+
->set('cache.rate_limiter')
19+
->parent('cache.app')
20+
->tag('cache.pool')
21+
1822
->set('limiter', Limiter::class)
1923
->abstract()
2024
->args([

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal
7676
'strategy' => 'fixed_window',
7777
'limit' => $config['max_attempts'],
7878
'interval' => '1 minute',
79-
'lock_factory' => 'lock.factory',
80-
'cache_pool' => 'cache.app',
8179
];
8280
FrameworkExtension::registerRateLimiter($container, $localId = '_login_local_'.$firewallName, $limiterOptions);
8381

‎src/Symfony/Component/RateLimiter/LimiterStateInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/RateLimiter/LimiterStateInterface.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
namespace Symfony\Component\RateLimiter;
1313

1414
/**
15+
* Representing the stored state of the limiter.
16+
*
17+
* Classes implementing this interface must be serializable,
18+
* which is used by the storage implementations to store the
19+
* object.
20+
*
1521
* @author Wouter de Jong <wouter@wouterj.nl>
1622
*
1723
* @experimental in 5.2
1824
*/
19-
interface LimiterStateInterface extends \Serializable
25+
interface LimiterStateInterface
2026
{
2127
public function getId(): string;
2228

‎src/Symfony/Component/RateLimiter/TokenBucket.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/RateLimiter/TokenBucket.php
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,22 @@ public function getExpirationTime(): int
7070
return $this->rate->calculateTimeForTokens($this->burstSize);
7171
}
7272

73-
public function serialize(): string
73+
/**
74+
* @internal
75+
*/
76+
public function __sleep(): array
7477
{
75-
return serialize([$this->id, $this->tokens, $this->timer, $this->burstSize, (string) $this->rate]);
78+
$this->stringRate = (string) $this->rate;
79+
80+
return ['id', 'tokens', 'timer', 'burstSize', 'stringRate'];
7681
}
7782

78-
public function unserialize($serialized): void
83+
/**
84+
* @internal
85+
*/
86+
public function __wakeup(): void
7987
{
80-
[$this->id, $this->tokens, $this->timer, $this->burstSize, $rate] = unserialize($serialized);
81-
82-
$this->rate = Rate::fromString($rate);
88+
$this->rate = Rate::fromString($this->stringRate);
89+
unset($this->stringRate);
8390
}
8491
}

‎src/Symfony/Component/RateLimiter/Window.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/RateLimiter/Window.php
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ public function getHitCount(): int
4848
return $this->hitCount;
4949
}
5050

51-
public function serialize(): string
51+
/**
52+
* @internal
53+
*/
54+
public function __sleep(): array
5255
{
5356
// $intervalInSeconds is not serialized, it should only be set
5457
// upon first creation of the Window.
55-
return serialize([$this->id, $this->hitCount]);
56-
}
57-
58-
public function unserialize($serialized): void
59-
{
60-
[$this->id, $this->hitCount] = unserialize($serialized);
58+
return ['id', 'hitCount'];
6159
}
6260
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.