FrontFormLimiter
in package
Throttles of public front forms that do not go through the API `save` (and so not through {@see ContentCreationLimiter}).
IMPORTANT: this is not ContentCreationLimiter::isAnonymousInsertAllowed(). That one is switched off for an unknown context (the API guard was not evaluated), which is exactly the state of a front component that does not call the API (advert password check), so the throttle would never apply there. Here it is always counted, with no exemption, because both actions are public and need no admin.
The IP comes from the server (IRequest::getRemoteAddress()), never from the form; the key
holds only a hash. Fail-open like the whole RateLimit: a storage outage does not
block the form.
Table of Contents
Properties
- $config : RateLimitConfig
- $httpRequest : IRequest
- $rateLimit : RateLimit
Methods
- __construct() : mixed
- isAdvertPasswordBlocked() : bool
- Returns whether trying the advert edit password is blocked.
- isAdvertPhoneRevealAllowed() : bool
- Returns whether "show phone" on an advert without an account is allowed.
- isRecommendAllowed() : bool
- Returns whether another recommendation may be sent.
- recordAdvertPasswordFailure() : void
- Records a failed advert password attempt (both dimensions).
- advertPasswordAdvertKey() : string
- advertPasswordIpKey() : string|null
- check() : bool
- hit() : bool
- resolveRemoteIp() : string|null
Properties
$config read-only
private
RateLimitConfig
$config
$httpRequest read-only
private
IRequest
$httpRequest
$rateLimit read-only
private
RateLimit
$rateLimit
Methods
__construct()
public
__construct(RateLimit $rateLimit, RateLimitConfig $config, IRequest $httpRequest) : mixed
Parameters
- $rateLimit : RateLimit
- $config : RateLimitConfig
- $httpRequest : IRequest
isAdvertPasswordBlocked()
Returns whether trying the advert edit password is blocked.
public
isAdvertPasswordBlocked(string $module, int $advertId) : bool
Only reads (does not draw on the quota). IMPORTANT: call it before verifying the password, so that after exhaustion even the correct password fails; otherwise an attacker would recognize a hit by a different response.
Parameters
- $module : string
-
bazaarorcomcat; separates module quotas because ids overlap - $advertId : int
Return values
boolisAdvertPhoneRevealAllowed()
Returns whether "show phone" on an advert without an account is allowed.
public
isAdvertPhoneRevealAllowed() : bool
The phone is on the advert, not on a user, so it cannot go through the API
revealPhone() with its limit. Uses ratelimit.showPhone values (per IP) under its own
key, so adverts without an account have a separate budget.
Return values
boolisRecommendAllowed()
Returns whether another recommendation may be sent.
public
isRecommendAllowed(string $recipientEmail) : bool
Draws on the quota (every send, including failed delivery), per sender IP and per normalized recipient email.
Parameters
- $recipientEmail : string
Return values
boolrecordAdvertPasswordFailure()
Records a failed advert password attempt (both dimensions).
public
recordAdvertPasswordFailure(string $module, int $advertId) : void
Parameters
- $module : string
- $advertId : int
advertPasswordAdvertKey()
private
advertPasswordAdvertKey(string $module, int $advertId) : string
Parameters
- $module : string
- $advertId : int
Return values
stringadvertPasswordIpKey()
private
advertPasswordIpKey() : string|null
Return values
string|nullcheck()
private
check(string $key, int $limit, int $window) : bool
Parameters
- $key : string
- $limit : int
- $window : int
Return values
boolhit()
private
hit(string $key, int $limit, int $window) : bool
Parameters
- $key : string
- $limit : int
- $window : int
Return values
boolresolveRemoteIp()
private
resolveRemoteIp() : string|null