CoolCMS API

FrontFormLimiter
in package

FinalYes

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

Methods

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

bazaar or comcat; separates module quotas because ids overlap

$advertId : int
Return values
bool

isAdvertPhoneRevealAllowed()

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
bool

isRecommendAllowed()

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
bool

recordAdvertPasswordFailure()

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
string

advertPasswordIpKey()

private advertPasswordIpKey() : string|null
Return values
string|null

check()

private check(string $key, int $limit, int $window) : bool
Parameters
$key : string
$limit : int
$window : int
Return values
bool

hit()

private hit(string $key, int $limit, int $window) : bool
Parameters
$key : string
$limit : int
$window : int
Return values
bool

resolveRemoteIp()

private resolveRemoteIp() : string|null
Return values
string|null
On this page

Search results