Skip to content

sudo mode#23447

Draft
SebSept wants to merge 47 commits into
glpi-project:mainfrom
SebSept:fork/SebSept/sudo-mode
Draft

sudo mode#23447
SebSept wants to merge 47 commits into
glpi-project:mainfrom
SebSept:fork/SebSept/sudo-mode

Conversation

@SebSept

@SebSept SebSept commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

@SebSept SebSept force-pushed the fork/SebSept/sudo-mode branch from 4b15d22 to 4c5f567 Compare March 11, 2026 10:59
@SebSept SebSept changed the base branch from 11.0/bugfixes to main March 11, 2026 11:00
@SebSept SebSept requested a review from cedric-anne March 11, 2026 11:18
@SebSept

SebSept commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

lots of files changed because of a method signature change. important files to review : User.php CommonX.php Security/ReAuthxxx ReAuth controller.
Atm, the redirection after reauth doesn't work but that not important, we are validatating the code design

Comment thread src/CommonGLPI.php Outdated
Comment thread src/CommonDBTM.php Outdated
Comment thread src/CommonGLPI.php Outdated
@SebSept SebSept force-pushed the fork/SebSept/sudo-mode branch from ad4c71e to e255a00 Compare March 19, 2026 16:50
@SebSept SebSept closed this Mar 26, 2026
@SebSept SebSept reopened this Mar 26, 2026
@SebSept SebSept force-pushed the fork/SebSept/sudo-mode branch from 743f71b to 0e80332 Compare March 30, 2026 10:08
Comment thread src/Glpi/Application/SystemConfigurator.php Outdated
Comment thread src/CommonDBTM.php Outdated
{
global $CFG_GLPI;

$this->setSuccessRedirectURL(\Html::getRefererUrl() ?? $CFG_GLPI['url_base']);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the target URL should be the current URL instead of the referer. Indeed, if you display a form with the /Software/DoSomething (current URL) action from the Computer/X (referer URL) page, then after the reauth you need to submit the form data on the /Software/DoSomething to make the form submission processed.

Comment thread src/CommonDBTM.php Outdated
Comment thread src/Glpi/Controller/Security/ReAuthController.php Outdated
@SebSept SebSept force-pushed the fork/SebSept/sudo-mode branch from 8413e75 to 14502be Compare April 29, 2026 08:20
@trasher

trasher commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

There is a conflict to solve

@SebSept SebSept force-pushed the fork/SebSept/sudo-mode branch from 14502be to 197c4e8 Compare April 29, 2026 14:55
Comment thread front/user.form.php Outdated

Html::back();
} else {
$user->check((int) $_GET['id'], READ, $input);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The CommonDBTM::displayFullPageForItem() already perform a $item->can($id, READ). This may be replaced by a call to the check() method.
Anyway, I think we should find a way to not have to alter all legacy controllers that call CommonDBTM::displayFullPageForItem().

methods: ['GET']
)]
#[SecurityStrategy(Firewall::STRATEGY_AUTHENTICATED)]
public function prompt(Request $request, string $error = ''): Response

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please ensure the presence of the string $error parameter cannot be used to force a specifi message throught the URL parameters. It could be used by an attacker to display a custom message during a prompt authentication, and I guess it could be used to encourage users to take an unexpected action, such as contacting a fictitious support team.

A solution could be to mutualize the template rendering in a private function getPromptResponse(?string $error = null).

return [
'redirect' => $this->reAuthManager->getRedirectURL(),
'cancel_url' => $this->reAuthManager->getCancelURL(),
'action' => $this->router->generate('reauth_verify'),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please verify that the generated URL is correct when GLPI is served under an Alias (e.g. http://example.org/glpi). We did not used the URL generator for the moment because we did not checked it is fully working the GLPI context.

Comment on lines +92 to +97
// catched in RedirectPostExceptionListener
throw new ReauthRedirectException(
$this->reAuthManager->getRedirectURL(),
$this->reAuthManager->getRedirectData(),
$this->reAuthManager->getRedirectMethod(),
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The response could be built here directly, since this is the only place where this exception is thrown.

Comment on lines +58 to +60
if ($this->http_method === 'POST' && isset($this->data['id'])) {
return $this->url . '?id=' . $this->data['id'];
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMHO, this could lead to unexpected issues. I guess this parameter was present in the initial request URL. Maybe $_GET parameters should be preserved in the URL.

Comment on lines +39 to 51
enum ReAuthStrategyEnum: string
{
public function __construct(
string $date,
string $author,
) {
parent::__construct(
label: __("Current version"),
description: __("Updated by"),
date: $date,
author: $author,
);
case TOTP = 'totp';
case PASSWORD = 'password';

public function createStrategy(): ReAuthStrategyInterface
{
return match ($this) {
self::TOTP => new TOTPReAuthStrategy(),
self::PASSWORD => new PasswordReAuthStrategy(),
};
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could instanciate the ReAuthManager directly from the dependency injection logic, to not have to maintain this enum.

We have sucessfully done it for the Glpi\Application\ViewTemplateRendererclass. The constructor is initialized by the DI system, and thegetInstance()` method can be used where it is not possible to une the DI system.

Comment thread src/Session.php

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are no changes in this class except some code reorganization. This add 10% more lines changes to this PR, increasing the review complexity. Please try to not do too much refactoring. We have thousand lines of code in GLPI that are indeed pretty hard to understand, but since our code is far from being entirely covered by tests and since we still do not use strict types everywhere, this kind of changes can result in unexpected side effects and should be avoid when it is not necessary.

Comment thread src/CommonDBTM.php
Comment thread src/MassiveAction.php
Comment thread templates/components/form/buttons.html.twig Outdated
@orthagh orthagh linked an issue May 4, 2026 that may be closed by this pull request
SebSept added 13 commits May 27, 2026 14:20
# Conflicts:
#	src/CommonDBTM.php
no code change, just move the else. - may be reverted

# Conflicts:
#	src/Session.php
# Conflicts:
#	src/CommonDBTM.php
#	src/CommonGLPI.php
#	src/Glpi/Controller/Security/ReAuthController.php
#	src/Glpi/Security/ReAuth/ReAuthManager.php
- autosubmit totp on last char typed
- remove useless array handling
SebSept added 14 commits May 27, 2026 14:30
GLPI_REAUTH to false for tests
- ReauthRedirecException handle $_GET requests
- move rights checks form \CommonDBTM::displayFullPageForItem() to front/user.form.php
- refacto ReAuthManager.php
- just redirect to previous url (not to form on form submit)
- fix \Glpi\Security\ReAuth\ReAuthManager::isReAuthenticated() constant usage
- reauth can be done on all rights (not only UPADTE).
- simplify \CommonDBTM::check()
@SebSept SebSept force-pushed the fork/SebSept/sudo-mode branch from 197c4e8 to c6976eb Compare May 27, 2026 15:16
@SebSept SebSept changed the title sudo mode poc 2 sudo mode May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sudo mode

3 participants