From d4484b7a95efec75b4efd2542168a255969a3207 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 4 Aug 2026 16:46:08 +0200 Subject: [PATCH] perf(PasswordConfirmationMiddleware): Reuse reflection object Signed-off-by: Carl Schwan --- .../Security/PasswordConfirmationMiddleware.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php index 534303dc9bcf2..8027c38eaa9b7 100644 --- a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php @@ -24,8 +24,6 @@ use OCP\IUserSession; use OCP\Session\Exceptions\SessionNotAvailableException; use OCP\User\Backend\IPasswordConfirmationBackend; -use ReflectionAttribute; -use ReflectionMethod; class PasswordConfirmationMiddleware extends Middleware { private array $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; @@ -75,8 +73,7 @@ public function beforeController(Controller $controller, string $methodName): vo // No scope to test } - $reflectionMethod = new ReflectionMethod($controller, $methodName); - if ($this->isPasswordConfirmationStrict($reflectionMethod)) { + if ($this->isPasswordConfirmationStrict()) { $password = $this->request->getHeader('PHP_AUTH_PW'); if ($password === '') { @@ -103,9 +100,8 @@ private function needsPasswordConfirmation(): bool { return $this->reflector->hasAnnotationOrAttribute('PasswordConfirmationRequired', PasswordConfirmationRequired::class); } - private function isPasswordConfirmationStrict(ReflectionMethod $reflectionMethod): bool { - /** @var ReflectionAttribute[] $attributes */ - $attributes = $reflectionMethod->getAttributes(PasswordConfirmationRequired::class); - return !empty($attributes) && ($attributes[0]->newInstance()->getStrict()); + private function isPasswordConfirmationStrict(): bool { + $attribute = $this->reflector->getAttribute(PasswordConfirmationRequired::class); + return $attribute !== null && ($attribute->newInstance()->getStrict()); } }