Repository navigation
Test isLoggedIn()'s returned User, not the return itself - #2110
Merged
Merged
Conversation
Issue #2107. A role gets an Allowed Networks list (addresses and CIDR ranges, IPv4 and IPv6). A user whose roles carry lists may sign in to the web UI and use the REST API only from an address in the union of those lists. A role with no list does not lift another role's limit. Empty everywhere means no restriction, which is every existing install. The iPXE menu login, the advanced menu, and FOS checkcredentials are not limited: they prove the credential through passwordValidate() / authenticate(), which carry no network check, so a technician can still start a task from the boot menu on any network. Gates: - establishSession(): a new sign-in, any provider. After the FOGUser rebind, so it tests the account the session is stamped with. - LoadGlobals: an existing session, on every request. Nothing downstream re-checked the account, so a session (or a replayed session cookie) kept working from anywhere. This also drops an existing session of an account marked API-only, which had the same gap. - _isLoggedIn() plus ProcessLogin: the remember-me replay. ProcessLogin now unbinds the cookie's account when isLoggedIn() refuses it; before, the pages rendered anyway, because they test only isValid(). - Route: token, Bearer and basic-auth API clients get 403. validatePw() now mints the remember-me cookie only after establishSession() accepts the sign-in, so a refused sign-in leaves no userAuths row behind. REMOTE_ADDR only, never X-Forwarded-For. Loopback gets no exception: a reverse proxy on the server would make every request loopback and the limit would silently pass everyone. Role::save() refuses an edit that would lock out the user making it. Schema 461 adds roles.rAllowedNetworks varchar(2048). OpenAPI: no hand edit. The new role field is in $databaseFields and the manifest, so _entitySchema() emits it. The new 403 on the token paths is covered by the generic '403' response every operation already documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
User::isLoggedIn() returns an object, $this or an invalid User(0), and its docblock said bool. The remember-me replay in ProcessLogin and management/other/index.php tested `isLoggedIn() && isValid()`; an object is always truthy, so every account the cookie named was accepted and the API-only and role network refusals in _isLoggedIn() never took effect there. Found by the live lab test of #2107: a remember-me cookie kept a user signed in after their role's networks stopped covering the address. After the fix the same request shows the login form. Both callers now test isLoggedIn()->isValid(), the docblock says @return User, and the test scans every PHP file under packages/ for a boolean use of the return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The leading-! branch flagged the correct form, !$u->isLoggedIn()->isValid(), so a caller writing the right code got a red build. Both branches now skip a call followed by ->. The before-the-call branch also catches &&, || and (bool), so an assignment like $a = $x && $u->isLoggedIn() is flagged. Probed both correct forms green and five bad shapes red. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
global-class-prefix.test.php requires a leading backslash on built-in classes; the new isLoggedIn() scan used three without one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Follow-up to #2109 (issue #2107), stacked on it. #2109 entered the merge queue before this fix could be pushed to its branch. Until #2109 merges, this diff also shows #2109's commits; the change here is the last commit.
The bug
User::isLoggedIn()returns an object:$this, or an invalidUser(0)on refusal. Its docblock saidbool. Two callers tested it as a boolean,isLoggedIn() && isValid():ProcessLogin::processMainLogin()management/other/index.phpAn object is always truthy. So the replay accepted every account its cookie named, and the refusals inside
_isLoggedIn()never took effect on that path. That covers both the API-only refusal and the role network refusal from #2109.How it was found
In the live lab test of #2109, a remember-me cookie kept a user signed in after their role's networks stopped covering the address. With this fix, the same request shows the login form. Every other path in that test passed: password sign-in, an open session, the API, the self-lockout guard, and iPXE and FOS still working.
The change
isLoggedIn()->isValid().@return User. PHPStan flagged the first caller fix against the old docblock.tests/role-allowed-networks.test.phpscans every PHP file underpackages/, with comments stripped, for a boolean use of the return. It goes red on the old code.For a user who is signed in normally, or signed out, nothing changes. Both expressions call
_isLoggedIn()once, so its side effects are the same.🤖 Generated with Claude Code