Repository navigation
Conversation
ManageUsersService checked the browser session
(ServiceLocator::GetServer()->GetUserSession()). A REST request has
none, so an application administrator authenticated by API token was
denied ("Only application administrators may create users", log:
"AddUser denied. UserId=0"), and a browser cookie sent along with an
API request would decide instead of the API token.
ServiceLocator::GetUserSession() now returns the authenticated API
session first during a web service request, and ManageUsersService
uses it for all its admin checks. No PHP session is written for API
calls.
Fixes LibreBooking#1736
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ROB-ernst
force-pushed
the
fix/api-session-admin-user-operations
branch
from
October 18, 2026 14:15
a288044 to
4c12f53
Compare
This branch has not been deployed
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.
Fixes #1736
Problem
ManageUsersServicechecks the acting user withServiceLocator::GetServer()->GetUserSession(), i.e. the PHPbrowser session. A REST request authenticated by
X-Booked-SessionToken/X-Booked-UserIdhas no browser session,so the check sees a
NullUserSessionand an application administrator is denied:POST /Web/Services/Users/→ 400 "Only application administrators may create users"(log:
AddUser denied. UserId=0 is not an application administrator)DELETE /Web/Services/Users/{id}→ 200 "The item was deleted", but nothing is deleted(
DeleteUserreturns early on the same check)POST /Web/Services/Users/{id}(update), password and attribute changes are affected the same wayThe admin-only route check in
WebServiceSecuritypasses, so this is only the second check inside the service.Reproduced on 7.0.0 (Docker image
librebooking/librebooking:7.0.0-3.5.1); the code is unchanged ondevelop.A related point:
ServiceLocator::GetUserSession()already knows the API server, but it returns the browser sessionfirst. A REST call that also carries a browser cookie of another user would therefore be judged by that user.
Change
ServiceLocator::GetUserSession()returns the authenticated API session first during a web service request, thenthe browser session, else
null. Outside the API (no API server registered) nothing changes.ManageUsersServiceuses it (via a privateCurrentUser()that falls back toNullUserSession) for all six adminchecks.
have worked, but would put an admin session into
$_SESSION).ServiceLocator::SetApiServer()acceptsnull;TestBase::teardown()resets it so tests stay independent.Tests
ManageUsersServiceTest: user creation and deletion succeed for an API admin without a browser session; an APInon-admin is denied even when the browser session is an admin.
ServiceLocatorTest: precedence of API and browser session, fallback when the API request is notauthenticated,
nullwithout any session.after the change in my environment (missing PHP extensions in the container);
phpstanandphp-cs-fixerreportnothing for the changed files.
booking and the user through the API all work.
🤖 Generated with Claude Code
https://claude.ai/code/session_013tFERcCHKhG6St25mzFRYq