Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(LockedField): prevent purge of lockedField without authorization on the linked object entity #18353

Open
wants to merge 7 commits into
base: 10.0/bugfixes
Choose a base branch
from

Conversation

stonebuzz
Copy link
Contributor

@stonebuzz stonebuzz commented Nov 20, 2024

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

GLPI does not respect the current user's permissions when deleting (purging) a LockedField.

This allows a LockedField linked to an object from another entity to be deleted.

I am also questioning the handling of global LockedFields.
Currently, anyone with the UPDATE permission can delete a global lock (with or without this PR), regardless of the entity, as the LockedField object does not include an entities_id.

  • It fixes !35279

Screenshots (if appropriate):

@stonebuzz stonebuzz self-assigned this Nov 20, 2024
@stonebuzz stonebuzz added the bug label Nov 20, 2024
@stonebuzz stonebuzz added this to the 10.0.18 milestone Nov 20, 2024
@trasher
Copy link
Contributor

trasher commented Nov 20, 2024

Seems correct, could you add a test please?

Co-authored-by: Cédric Anne <[email protected]>
Copy link
Member

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

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

Tests are failing.

Comment on lines +74 to +80
if (
$item->getFromDB($this->fields['items_id']) //not a global lock
&& $item->isEntityAssign()
&& !Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive()) // no access to main item entity
) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

If there is a lack of checks for the purge right, I guess there is the same lack of checks for the creation and the update right. Could you fix that too ?

Comment on lines +88 to +96
$item = new $lock->fields['itemtype']();
if (
$item->getFromDB($lock->fields['items_id']) //not a global lock
&& $item->isEntityAssign()
&& !Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive()) // no access to main item entity
) {
return false;
}
return true;
Copy link
Member

Choose a reason for hiding this comment

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

The code looks pretty similar to what is done in the canPurgeItem() method. You should probably move it into a private function canAccessItemEntity(string $itemtype, int $items_id): bool method.

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.

4 participants