Skip to main content

InvalidTokenMonitor

\Benecaster\Security\InvalidTokenMonitor

Class Free

Added feature/invalid-token-monitoring, in a new Security namespace. Counts feed requests whose token matches no subscriber row, per show, over a rolling 60-minute window of per-minute buckets, and publishes a Warning-tier admin notice via NoticeManager once a show crosses the threshold.

Registers on benecaster_feed_request_dispatched (not benecaster_token_invalid, which fires before revoked/not-found is told apart) and on benecaster_notice_dismissed, so dismissing a show’s current alert clears its count and starts the one-hour quiet period.

Constructor Dependencies

Type Description
NoticeManager

Methods

Method Visibility Since Description
register(): void Public Hooks benecaster_feed_request_dispatched (handle_event) and benecaster_notice_dismissed (handle_dismissal).
handle_event( array $ctx ): void Public Counts the request if, and only if, $ctx['token_status'] is 'not_found'. Increments the show's per-minute bucket, then publishes or refreshes the Warning notice once the show's rolling-window count reaches its configured threshold. No-ops when config() returns null for the show.
handle_dismissal( string $notice_id ): void Public Matches $notice_id against this class's NOTICE_ID_PREFIX. When it matches the show's current alert, clears that show's failure count and writes a cooldown transient valued at the notice ID, effective for DISMISS_QUIET_SECONDS.
config( int $show_id ): ?array Public Runs benecaster_invalid_token_alert_threshold for the show and returns the filtered [ 'count', 'window_minutes' ] array, or null when the filter switched monitoring off for the show.
current_count( int $show_id ): int Public Sums the show's per-minute buckets that fall inside its currently configured window. This is the value passed as $current_count on benecaster_invalid_token_recorded.

Constants

Name Value Description
WINDOW_MINUTES 60 Default rolling window, in minutes, before benecaster_invalid_token_alert_threshold overrides it per show.
ALERT_THRESHOLD 10 Default failure count that triggers an alert, before the filter overrides it per show.
MAX_WINDOW_MINUTES 1440 Upper clamp (one day) on window_minutes returned by the filter — bounds the per-minute bucket storage.
DISMISS_QUIET_SECONDS HOUR_IN_SECONDS Quiet period after a show's current alert is dismissed, before a fresh burst of failures can alert again.
NOTICE_ID_PREFIX 'benecaster_invalid_token_alert_' Prefix of every notice ID this class publishes: {prefix}{show_id}_{unix time}, one per incident.
COOLDOWN_PREFIX 'benecaster_invalid_token_cooldown_' Prefix of the transient key storing a show's cooldown; the transient's value is the notice ID the cooldown belongs to.

Hooks Fired

Notes

Storage: one transient per show for the per-minute buckets (benecaster_invalid_token_count_{show_id}), and one for the cooldown. Revoked tokens never reach handle_event()'s counting branch, by operator ruling — only token_status: not_found counts.