Commit Graph

33 Commits

Author SHA1 Message Date
Chi-teck
f90f27b63a Fix rate limiter documentation 2020-12-02 09:46:43 +01:00
Fabien Potencier
fc615e9845 feature #38664 [RateLimiter] Moved classes implementing LimiterInterface to a new namespace (Nyholm)
This PR was squashed before being merged into the 5.2-dev branch.

Discussion
----------

[RateLimiter] Moved classes implementing LimiterInterface to a new namespace

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no?
| Tickets       |
| License       | MIT
| Doc PR        |

Before we release the RateLimit component.
I think it would be a good idea to put the 7 classes that belongs to a specific strategy in their own "Policy" namespace. It is very likely that it will be more strategies in the future and the `Symfony\Component\RateLimiter` namespace is crowed as it is.

I decided not to put the `CompoundLimiter` in this namespace as it is not a strategy.

Commits
-------

1e6cea56e4 [RateLimiter] Moved classes implementing LimiterInterface to a new namespace
2020-10-25 09:35:39 +01:00
Nyholm
1e6cea56e4 [RateLimiter] Moved classes implementing LimiterInterface to a new namespace 2020-10-25 09:35:33 +01:00
Nicolas Grekas
605a5674a8 Merge branch '5.1' into 5.x
* 5.1:
  fix merge
  fix merge
  Remove branch-version (keep them for contracts only)
  [HttpClient] relax auth bearer format requirements
  [PHPUnitBridge] Silence errors from mkdir()
  [DependencyInjection] Preload classes with union types correctly.
  [Serializer] fix decoding float XML attributes starting with 0
  add missing dutch translations
  [TwigBridge] Remove "transchoice" from the code base
  Support PHPUnit 8 and PHPUnit 9 in constraint compatibility trait
  Add expectDeprecation, expectNotice, expectWarning, and expectError to TestCase polyfill
  [String] fix before/after[Last]() returning the empty string instead of the original one on non-match
  Add missing exporter function for PHPUnit 7
  [Validator] Add missing romanian translations
  [String] fix slicing in UnicodeString
  [Cache] Use correct expiry in ChainAdapter
  do not translate null placeholders or titles
2020-10-24 14:08:07 +02:00
Robin Chalas
1c81aa72a6 bug #38675 [RateLimiter] Rename RateLimiter to RateLimiterFactory (Nyholm)
This PR was squashed before being merged into the 5.x branch.

Discussion
----------

[RateLimiter] Rename RateLimiter to RateLimiterFactory

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | No, not released yet
| Tickets       |
| License       | MIT
| Doc PR        | should be added

Sorry for making a few BC breaks.

@wouterj [said](https://github.com/symfony/symfony/pull/38562#issue-503193238) that this class was suggested to be named `LimiterFactory` before. But that was rejected.

Just my looking at the names of the classes we currently have:
- Rate
- RateLimit
- RateLimiter

I find it hard to know what these are doing and the difference between them. Note that none of them are used as a rate limiter (ie implements `LimiterInterface`)

I would like to be clear that a `RateLimiterFactory` is used to create an object implementing `LimiterInterface`.

Commits
-------

8be261b300 [RateLimiter] Rename RateLimiter to RateLimiterFactory
2020-10-24 10:11:08 +02:00
Nyholm
8be261b300 [RateLimiter] Rename RateLimiter to RateLimiterFactory 2020-10-24 10:10:52 +02:00
Nyholm
76c22fab02
bug #38661 [RateLimiter] Fix delete method of the cache storage (GregOriol, Nyholm)
This PR was merged into the 5.x branch.

Discussion
----------

[RateLimiter] Fix delete method of the cache storage

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | None
| License       | MIT

This PR fixes a small issue with RateLimiter's cache storage and the delete method: all getItems are called with a sha1 of the id, but not the one for delete, which makes it miss the deletion.

Commits
-------

b61d9d1ea3 minor
88c1e2439e Added a test
fb540bba73 Fix delete method on RateLimiter's cache storage
2020-10-22 19:09:06 +02:00
Nyholm
b61d9d1ea3
minor 2020-10-22 12:14:59 +02:00
Nyholm
88c1e2439e
Added a test 2020-10-22 12:12:23 +02:00
Nyholm
067153f452
Make sure we actually can use sliding_window and no_limit 2020-10-22 11:54:30 +02:00
Greg ORIOL
fb540bba73
Fix delete method on RateLimiter's cache storage 2020-10-22 11:48:25 +02:00
Robin Chalas
753932527e bug #38670 [RateLimiter] Be more type safe when fetching from cache (Nyholm)
This PR was merged into the 5.x branch.

Discussion
----------

[RateLimiter] Be more type safe when fetching from cache

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

This is a super minor thing. A `$cacheItem` can be a hit, but it does not contain a `LimiterStateInterface`.

Also, PSR-6 specifies that if the `$cacheItem` is not a hit, it must return null.

Commits
-------

4795756cc7 [RateLimiter] Be more type safe when fetching form cache
2020-10-22 10:40:20 +02:00
Robin Chalas
58f4e9dfc8 bug #38665 [RateLimiter] Allow configuration value "no_limit" (Nyholm)
This PR was squashed before being merged into the 5.x branch.

Discussion
----------

[RateLimiter] Allow configuration value "no_limit"

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | maybe?
| New feature?  | not sure
| Deprecations? |
| Tickets       |
| License       | MIT
| Doc PR        |

I dont see any reason why we should allow people to configure "no_limit". I assume this was just forgotten.

Commits
-------

2b9058d6b6 [RateLimiter] Allow configuration value "no_limit"
2020-10-22 10:35:38 +02:00
Nyholm
2b9058d6b6 [RateLimiter] Allow configuration value "no_limit" 2020-10-22 10:35:15 +02:00
Robin Chalas
6bb46dedca minor #38668 [RateLimiter] Remove Window::sleep() (Nyholm)
This PR was merged into the 5.x branch.

Discussion
----------

[RateLimiter] Remove Window::sleep()

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? |
| Tickets       |
| License       | MIT
| Doc PR        |

This function is not needed since #38562

Commits
-------

ccbf7d5a06 [RateLimiter] Remove Window::sleep()
2020-10-22 10:31:04 +02:00
Nyholm
5dfafd334e [RateLimiter] Adding annotations 2020-10-22 10:25:47 +02:00
Nyholm
4795756cc7
[RateLimiter] Be more type safe when fetching form cache 2020-10-21 23:51:48 +02:00
Nyholm
ccbf7d5a06
[RateLimiter] Remove Window::sleep() 2020-10-21 23:43:19 +02:00
Kevin Bond
c5361cfc58 [RateLimiter] rename Limit to RateLimit and add RateLimit::getLimit() 2020-10-20 08:15:14 +02:00
Wouter de Jong
cd34f21254 [RateLimiter] Added reserve() to LimiterInterface and rename Limiter to RateLimiter 2020-10-16 07:10:27 +02:00
Oskar Stark
db392d2441
Fix: Typo 2020-10-15 10:06:30 +02:00
Fabien Potencier
19a320513a feature #38565 [RateLimiter] Adding SlidingWindow algorithm (Nyholm)
This PR was squashed before being merged into the 5.x branch.

Discussion
----------

[RateLimiter] Adding SlidingWindow algorithm

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? |
| Tickets       |
| License       | MIT
| Doc PR        | Should be added

This is a draft PR to make sure we like the idea. I'll keep working on adding tests.

Commits
-------

c6d3b70315 [RateLimiter] Adding SlidingWindow algorithm
2020-10-15 08:59:52 +02:00
Nyholm
c6d3b70315 [RateLimiter] Adding SlidingWindow algorithm 2020-10-15 08:59:46 +02:00
Nicolas Grekas
ffbb9883bd Merge branch '5.1' into 5.x
* 5.1:
  [Contracts] add branch-aliases for dev-main
  [Cache] Make Redis initializers static
  [Messenger] Fixed typos in Connection
  [CI] Fixed build on AppVeyor
  Fix tests typo
  [Lock] Reset Key lifetime time before we acquire it
  [CI] Silence errors when remove file/dir on test tearDown()
  Fix tests
  Remove content-type check on toArray methods
2020-10-14 19:08:19 +02:00
Nyholm
e9ac9712d8 Fix minor issue when sharing windows between Limiters 2020-10-14 18:22:58 +02:00
Nicolas Grekas
11c4f28137 Merge branch '5.1' into 5.x
* 5.1:
  fix merge
  [appveyor] fix checking for the .x branch
  Remove "branch-alias", populate "version"
2020-10-06 14:00:29 +02:00
Fabien Potencier
bd8c3c1c42 feature #38354 [RateLimiter] add Limit::ensureAccepted() which throws RateLimitExceededException if not accepted (kbond)
This PR was merged into the 5.2-dev branch.

Discussion
----------

[RateLimiter] add Limit::ensureAccepted() which throws RateLimitExceededException if not accepted

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Ref https://github.com/symfony/symfony/issues/38241#issuecomment-695212027
| License       | MIT
| Doc PR        | todo

Example:

```php
try {
    $limit = $limiter->consume()->ensureAccepted();
} catch (RateLimitExceededException $e) {
    $limit = $e->getLimit();
}
```

Commits
-------

a7ecd0ed08 [RateLimiter] add Limit::ensureAccepted() and RateLimitExceededException
2020-10-02 13:18:49 +02:00
Kevin Bond
a7ecd0ed08
[RateLimiter] add Limit::ensureAccepted() and RateLimitExceededException 2020-10-01 20:04:22 -04:00
Wouter de Jong
5dc562a318 Use __sleep/__wakeup instead of Serializable
Fixes #38338
2020-10-01 14:20:33 +02:00
Wouter de Jong
5d03afea99 Added request rate limiters and improved login throttling
This allows limiting on different elements of a request. This is usefull to
e.g. prevent breadth-first attacks, by allowing to enforce a limit on both IP
and IP+username.
2020-09-30 21:18:40 +02:00
Wouter de Jong
0279f88e6c Call all compound limiters on failure and added IO blocking 2020-09-30 12:14:20 +02:00
Valentin
8f62afc5f9 [RateLimiter] Return Limit object on Consume method 2020-09-30 07:47:20 +02:00
Wouter de Jong
67417a693e [RFC] Introduce a RateLimiter component 2020-09-16 15:45:01 +02:00