Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a67c292
fix(FOUR-34260): store per-user random TOTP secrets for 2FA
gproly Nov 9, 2026
51235c1
fix(FOUR-34260): use per-user TOTP secrets and reprovision legacy 2FA…
gproly Nov 9, 2026
daade4e
fix(FOUR-34260): use __() for 2FA translations
gproly Nov 10, 2026
a046a92
fix(FOUR-34260): align 2FA screens with shared auth Decisions layout
gproly Nov 10, 2026
4a3f991
fix(FOUR-34260): reload 2FA user without flushing permission caches
gproly Nov 10, 2026
f922d96
fix(FOUR-34260): split 2FA secrets and harden authenticator QR enroll…
gproly Nov 10, 2026
ffea1a0
fix(FOUR-34260): reduce returns in displayAuthAppQr for Sonar S1142
gproly Nov 10, 2026
9b70858
fix(FOUR-34260): lower cognitive complexity in displayTwoFactorAuthForm
gproly Nov 10, 2026
f831935
fix(FOUR-34260): use single return in validateCode for Sonar S1142
gproly Nov 10, 2026
0a72e9c
fix(FOUR-34260): keep authenticator secret in session until first val…
gproly Nov 10, 2026
9353142
fix(FOUR-34260): show OTP after QR when authenticator secret is pending
gproly Nov 10, 2026
d1d8e94
Merge branch 'develop' into bugfix/FOUR-34260
nolanpro Nov 17, 2026
4edefc5
feat(FOUR-34260): fix Sonar S1488 in createOtpInstance
gproly Nov 18, 2026
54197e4
refactor(FOUR-34260): remove unused getUserTotpSecret per Sonar S1144
gproly Nov 18, 2026
cd5ceca
fix(FOUR-34260): block authenticator enrollment before delivery step-up
gproly Nov 18, 2026
e84ffbd
fix(FOUR-34260): allow authenticator enroll after delivery step-up
gproly Nov 19, 2026
c21c613
fix(FOUR-34260): guide mixed-method users through delivery then QR en…
gproly Nov 19, 2026
c913471
fix(FOUR-34260): harden mixed-method enrollment and preference bypass
gproly Nov 19, 2026
e9d0f0f
fix(FOUR-34260): narrow API preferences guard to active web challenge
gproly Nov 19, 2026
4675165
fix(FOUR-34260): bind preferences API gate to matching web session
gproly Nov 19, 2026
7009dbe
fix(FOUR-34260): mitigate 2FA preference bypass in user update
gproly Nov 19, 2026
82c94df
fix(FOUR-34260): use random authenticator secrets instead of predicta…
gproly Nov 19, 2026
d40448c
fix(FOUR-34260): merge early exits in mayEnrollNewAuthenticator for S…
gproly Nov 19, 2026
5631a2c
fix(FOUR-34260): block self-service preferences_2fa update until web …
gproly Nov 19, 2026
562b39a
fix(FOUR-34260): satisfy Sonar S1142 in validateTwoFactorAuthCode
gproly Nov 19, 2026
4badbbc
refactor(FOUR-34260): extract UserController::update helpers for Sona…
gproly Nov 19, 2026
3e855dd
fix(FOUR-34260): block stateless API preferences_2fa updates without …
gproly Nov 19, 2026
5bc0a82
fix(OUR-34260): block OTP destination changes until web 2FA is validated
gproly Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 177 additions & 88 deletions ProcessMaker/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use ProcessMaker\Events\UserUpdated;
use ProcessMaker\Exception\ReferentialIntegrityException;
use ProcessMaker\Filters\SaveSession;
use ProcessMaker\Http\Controllers\Auth\TwoFactorAuthController;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Http\Resources\ApiCollection;
use ProcessMaker\Http\Resources\Users as UserResource;
Expand Down Expand Up @@ -535,97 +536,19 @@ public function update(User $user, Request $request)
$isLdapUser = isset($user->meta?->authenticationType)
&& $user->meta->authenticationType === 'ldap';
$user->fill($fields);
if (array_key_exists('cell', $fields)) {
$response = $this->validateCellPhoneNumber($user, $fields['cell']);
if ($response) {
return $response;
}
}
if ($fields['email'] !== $original['email']) {
$ssoUser = $isLdapUser;
if (class_exists(SsoUser::class)) {
// Check if the user is an SSO user (including SAML)
$ssoUser = $ssoUser || SsoUser::where('user_id', $user->id)->exists();
}
if ($ssoUser) {
return response([
'message' => __(
"The email can't be edited. This action is only available for SSO-synced users."
),
'errors' => [
'email' => [
__(
"The email can't be edited. This action is only available for SSO-synced users."
),
],
],
], 422);
}
if (!isset($fields['valpassword'])) {
return response([
'message' => __(
'A valid authentication is required for for update the email.'
),
'errors' => [
'email' => [
__(
'The password is required.'
),
],
],
], 422);
} else {
$response = $this->validateBeforeChange(Auth::user(), $fields['valpassword']);
if ($response) {
return $response;
}
}
}
if (Auth::user()->is_administrator && $request->has('is_administrator')) {
// user must be an admin to make another user an admin
$user->is_administrator = $request->get('is_administrator');
}

if (empty($fields['meta'])) {
$user->meta = null;
}

try {
$user->saveOrFail();
} catch (\Exception $e) {
$slackExceptionClass = 'ProcessMaker\Packages\Connectors\Slack\Exceptions\SlackConfigurationException';

if (class_exists($slackExceptionClass) && $e instanceof $slackExceptionClass) {
return response([
'message' => $e->getMessage(),
], 422);
}

throw $e;
$validationResponse = $this->resolveUserUpdateValidationResponse(
$authenticatedUser,
$user,
$fields,
$original,
$isLdapUser
);
if ($validationResponse !== null) {
return $validationResponse;
}

$changes = $user->getChanges();

//Call new Event to store User Changes into LOG
UserUpdated::dispatch($user, $changes, $original);
try {
if ($request->has('avatar')) {
$this->uploadAvatar($user, $request);
}
} catch (\Exception $e) {
return response([
'message' => 'Error uploading avatar',
'errors' => [
'avatar' => [
$e->getMessage(),
],
],
], 422);
}

RecommendationEngine::handleUserSettingChanges($user, $original);

return response([], 204);
return $this->completeUserUpdate($user, $request, $fields, $original);
}

/**
Expand Down Expand Up @@ -681,6 +604,172 @@ private function normalizeSelfServiceMeta(User $user, array $fields): array
return $fields;
}

private function resolveUserUpdateValidationResponse(
User $authenticatedUser,
User $user,
array $fields,
array $original,
bool $isLdapUser
) {
$response = $this->selfServiceTwoFactorSensitiveUpdateBlocked(
$authenticatedUser,
$user,
$fields,
$original
);
if ($response === null && array_key_exists('cell', $fields)) {
$response = $this->validateCellPhoneNumber($user, $fields['cell']) ?: null;
}
if ($response === null && $fields['email'] !== $original['email']) {
$response = $this->validateEmailChangeForUpdate($user, $fields, $isLdapUser);
}

return $response;
}

private function selfServiceTwoFactorSensitiveUpdateBlocked(
User $authenticatedUser,
User $user,
array $fields,
array $original
) {
if ($authenticatedUser->id !== $user->id || !$this->touchesTwoFactorDestinations($fields, $original)) {
return null;
}

if (!$this->selfServiceTwoFactorCompletionPending($authenticatedUser)) {
return null;
}

return response()->json([
'message' => __('Two-factor authentication must be completed before updating 2FA preferences.'),
], 422);
}

private function touchesTwoFactorDestinations(array $fields, array $original): bool
{
if (array_key_exists('preferences_2fa', $fields)) {
return true;
}

if (array_key_exists('cell', $fields) && ($fields['cell'] ?? null) !== ($original['cell'] ?? null)) {
return true;
}

return array_key_exists('email', $fields)
&& ($fields['email'] ?? null) !== ($original['email'] ?? null);
}

private function selfServiceTwoFactorCompletionPending(User $authenticatedUser): bool
{
if (session('sso_driver') !== null
|| !config('password-policies.2fa_enabled', false)
|| empty(config('password-policies.2fa_method', []))
|| !TwoFactorAuthController::check2faByGroups()
) {
return false;
}

$webUserId = Auth::guard('web')->id();

return $webUserId === null
|| (int) $webUserId !== (int) $authenticatedUser->id
|| !session()->get(TwoFactorAuthController::TFA_VALIDATED, false);
}

private function validateEmailChangeForUpdate(User $user, array $fields, bool $isLdapUser)
{
$response = null;
$ssoUser = $isLdapUser;
if (class_exists(SsoUser::class)) {
// Check if the user is an SSO user (including SAML)
$ssoUser = $ssoUser || SsoUser::where('user_id', $user->id)->exists();
}
if ($ssoUser) {
$response = response([
'message' => __(
"The email can't be edited. This action is only available for SSO-synced users."
),
'errors' => [
'email' => [
__(
"The email can't be edited. This action is only available for SSO-synced users."
),
],
],
], 422);
} elseif (!isset($fields['valpassword'])) {
$response = response([
'message' => __(
'A valid authentication is required for for update the email.'
),
'errors' => [
'email' => [
__(
'The password is required.'
),
],
],
], 422);
} else {
$emailAuthResponse = $this->validateBeforeChange(Auth::user(), $fields['valpassword']);
if ($emailAuthResponse) {
$response = $emailAuthResponse;
}
}

return $response;
}

private function completeUserUpdate(User $user, Request $request, array $fields, array $original)
{
if (Auth::user()->is_administrator && $request->has('is_administrator')) {
// user must be an admin to make another user an admin
$user->is_administrator = $request->get('is_administrator');
}

if (empty($fields['meta'])) {
$user->meta = null;
}

try {
$user->saveOrFail();
} catch (\Exception $e) {
$slackExceptionClass = 'ProcessMaker\Packages\Connectors\Slack\Exceptions\SlackConfigurationException';

if (class_exists($slackExceptionClass) && $e instanceof $slackExceptionClass) {
return response([
'message' => $e->getMessage(),
], 422);
}

throw $e;
}

$changes = $user->getChanges();

//Call new Event to store User Changes into LOG
UserUpdated::dispatch($user, $changes, $original);
try {
if ($request->has('avatar')) {
$this->uploadAvatar($user, $request);
}
} catch (\Exception $e) {
return response([
'message' => 'Error uploading avatar',
'errors' => [
'avatar' => [
$e->getMessage(),
],
],
], 422);
}

RecommendationEngine::handleUserSettingChanges($user, $original);

return response([], 204);
}

/**
* Validate the phone number for SMS two-factor authentication.
*
Expand Down
14 changes: 14 additions & 0 deletions ProcessMaker/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
use Laravel\Passport\ApiTokenCookieFactory;
use Laravel\Passport\Passport;
use ProcessMaker\Events\Logout;
use ProcessMaker\Http\Controllers\Auth\TwoFactorAuthController;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Managers\LoginManager;
use ProcessMaker\Models\Setting;
use ProcessMaker\Models\User;
use ProcessMaker\Package\Auth\Database\Seeds\AuthDefaultSeeder;
use ProcessMaker\Services\PermissionCacheService;
use ProcessMaker\Traits\HasControllerAddons;
use ProcessMaker\TwoFactorAuthentication;

class LoginController extends Controller
{
Expand Down Expand Up @@ -274,6 +276,13 @@ protected function authenticated(Request $request, $user)
if (env('LOGOUT_OTHER_DEVICES', false)) {
Auth::logoutOtherDevices($request->input('password'));
}

if (config('password-policies.2fa_enabled', false)
&& !empty(config('password-policies.2fa_method', []))
&& TwoFactorAuthController::check2faByGroups()
) {
(new TwoFactorAuthentication())->rememberChallengeMethodsSnapshot($user);
}
}

public function beforeLogout(Request $request)
Expand All @@ -294,6 +303,11 @@ public function beforeLogout(Request $request)
session()->remove(TwoFactorAuthController::TFA_VALIDATED);
session()->remove(TwoFactorAuthController::TFA_MESSAGE);
session()->remove(TwoFactorAuthController::TFA_ERROR);
session()->remove(TwoFactorAuthentication::CHALLENGE_METHODS_SNAPSHOT);
session()->remove(TwoFactorAuthentication::CHALLENGE_DELIVERY_EMAIL);
session()->remove(TwoFactorAuthentication::CHALLENGE_DELIVERY_CELL);
session()->remove(TwoFactorAuthentication::DELIVERY_STEP_UP);
session()->remove(TwoFactorAuthentication::PENDING_AUTHENTICATOR_SECRET);

// Notify to listeners (package-auth, security logger)
$eventResult = event(new Logout(Auth::user()));
Expand Down
Loading
Loading