[3.0] Read cached bans from the right place in the session - #9313
Open
albertlast wants to merge 1 commit into
Open
[3.0] Read cached bans from the right place in the session#9313albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
Security::checkBans() stores the restrictions that applied under $_SESSION['ban'], by merging them in alongside last_checked, id_member, ip, ip2 and email. The cached path read them back from $_SESSION directly instead, one level too high, so it never found them: Undefined array key "cannot_access" in Sources/Security.php:396 Undefined array key "cannot_login" in Sources/Security.php:396 Undefined array key "cannot_post" in Sources/Security.php:396 Undefined array key "cannot_register" in Sources/Security.php:396 That is four warnings on every request that took the cached path, and a returned array of nulls, so a banned member stopped being recognised as banned until the ban was rechecked against the database. Reads from $_SESSION['ban'], and only copies restrictions that are present, since checkBans() only stores the ones that applied. Also restores expire_time, which the cached path dropped even though User::enforceBans() uses it to tell the member when the ban ends. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This change was produced by an LLM. The code, the commit message and this
description were all written by Claude (Anthropic), driven by @albertlast. It has
not yet had human code review.
Everything stated below was verified by actually running it against a fresh
PostgreSQL install of this branch, rather than only reasoned about. Even so,
please review it as untrusted work: the diagnosis may be right while the fix is
not what SMF would prefer stylistically or architecturally.
Description
Security::checkBans()stores the restrictions that applied under$_SESSION['ban'],by merging them in alongside the metadata:
The cached path read them back from
$_SESSIONdirectly, one level too high, so itnever found them:
That is four warnings on every request that takes the cached path:
and an array of
nulls returned to the caller, so a banned member stops beingrecognised as banned until the ban is rechecked against the database.
This reads from
$_SESSION['ban'], and only copies restrictions that are actuallypresent, since
checkBans()only stores the ones that applied. It also restoresexpire_time, which the cached path dropped even thoughUser::enforceBans()usesit to tell the member when the ban ends.
How this was verified
PostgreSQL 17 / PHP 8.4. Before: four warnings logged per request taking the cached
path. After: eight consecutive guest requests, 0 errors logged, all HTTP 200.
Re-checked with a real ban in place to confirm the cached path still returns the ban.
Relationship to other PRs
Same subsystem as #9310, #9311 and #9312, but an independent mechanism — this one is
observable without any ban existing, as log spam on ordinary requests. Merges cleanly
alongside them.
Also merges cleanly onto #9302, which touches
Sources/Security.phpat lines 24, 676and 1037; this change is at ~396.
Issues References (Fixes|Related|Closes)