Skip to content

Fix - getEntitiesRestrictCriteria() returns invalid SQL criterion when no session is active#23934

Merged
cedric-anne merged 5 commits intoglpi-project:11.0/bugfixesfrom
RomainLvr:fix/entities-restrict-criteria-empty-session
Apr 20, 2026
Merged

Fix - getEntitiesRestrictCriteria() returns invalid SQL criterion when no session is active#23934
cedric-anne merged 5 commits intoglpi-project:11.0/bugfixesfrom
RomainLvr:fix/entities-restrict-criteria-empty-session

Conversation

@RomainLvr
Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

When getEntitiesRestrictCriteria() is called with no active session, no CLI context, and no cron context, the function falls through all conditions without an else branch. This leaves $value as an empty string '', producing the invalid SQL criterion entities_id = '' on an integer column and triggering MySQL warning 1292 (Truncated incorrect DECIMAL value).

This fix adds a missing else branch that returns [new QueryExpression('false')] when no valid context is available, denying all access instead of generating invalid SQL. If there is no session, no results should be returned.

Fixes all callers of getEntitiesRestrictCriteria() that are affected by this edge case (e.g. pluginsGLPI/fields#1179).

Copy link
Copy Markdown
Contributor

@Rom1-B Rom1-B left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests

@RomainLvr
Copy link
Copy Markdown
Contributor Author

The initial problem is that isCommandLine() relies on the PHP_SAPI constant, which is always set to ‘cli’ in PHPUnit. The solution we found: extract the call to isCommandLine() || Session::isCron() into a protected method called isPrivilegedContext(), which we override in a test using an anonymous class.

Comment thread src/DbUtils.php Outdated
@cedric-anne cedric-anne merged commit 83439e7 into glpi-project:11.0/bugfixes Apr 20, 2026
11 checks passed
@cedric-anne cedric-anne added this to the 11.0.7 milestone Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants