passbolt/passbolt_api · error · FormValidationException

Could not validate the password policies settings.

Error message

Could not validate the password policies settings.

What it means

FormValidationException thrown when PasswordPoliciesSettingsForm::execute() fails on the submitted request data. The form validates password policy fields (e.g. generator settings, length, entropy requirements) and any invalid or missing value aborts the update with this generic message plus form errors attached.

Solutions

  1. Read the form errors attached to the FormValidationException to see which fields failed
  2. Fix the payload so it matches PasswordPoliciesSettingsForm's validation rules (types, ranges, required keys)
  3. Send the full expected settings structure, not a partial update, unless the form supports partial data
  4. Add/update client-side validation mirroring the server form rules

Example fix

// before
$this->post('/password-policies.json', ['password_generator' => ['length' => 3]]); // below min
// after
$this->post('/password-policies.json', ['password_generator' => ['length' => 20, 'words' => 3, 'min_digits' => 1, 'min_upper' => 1, 'min_special' => 1]]);
Defensive patterns

Strategy: validation

Validate before calling

const requiredKeys = ['password_generator'];
if (!requiredKeys.every(k => k in payload)) throw new Error('Missing required password policy fields');

Try / catch

try { await postPasswordPolicies(payload); } catch (e) { if (e.formErrors) console.error('Invalid fields:', e.formErrors); else throw e; }

Prevention

When it happens

Trigger: POST to the password policies settings endpoint by an admin whose payload contains values rejected by PasswordPoliciesSettingsForm validation rules (wrong types, out-of-range numbers, unknown keys, missing required fields).

Common situations: Client sends old/incomplete settings schema after an upgrade; boolean fields sent as strings; password generator length below the minimum or above the maximum; nested structure of the settings payload does not match the form's expected shape.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/0bf299817fffce5b. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltEe/PasswordPoliciesUpdate/src/Service/PasswordPoliciesUpdateSetSettingsService.php:57

    /**
     * Create passwords policies settings if not present already in DB or updates the settings value if already exists.
     *
     * @param \App\Utility\ExtendedUserAccessControl $uac Extended user access control.
     * @param array $requestData Request data.
     * @return \Passbolt\PasswordPoliciesUpdate\Model\Dto\PasswordPoliciesUpdateSettingsDto
     */
    public function createOrUpdate(ExtendedUserAccessControl $uac, array $requestData): PasswordPoliciesUpdateSettingsDto // phpcs:ignore
    {
        if (!$uac->isAdmin()) {
            throw new ForbiddenException(
                __('Only administrators are allowed to create/update password policies settings.')
            );
        }

        $form = new PasswordPoliciesSettingsForm();
        if (!$form->execute($requestData)) {
            throw new FormValidationException(__('Could not validate the password policies settings.'), $form);
        }

        /** @var \Passbolt\PasswordPoliciesUpdate\Model\Dto\PasswordPoliciesUpdateSettingsDto $settingsDto */
        $settingsDto = PasswordPoliciesUpdateSettingsDto::createFromArray($form->getData());

        /** @var \Passbolt\PasswordPoliciesUpdate\Model\Table\PasswordPoliciesSettingsTable $passwordPoliciesSettingsTable */
        $passwordPoliciesSettingsTable = $this->fetchTable('Passbolt/PasswordPoliciesUpdate.PasswordPoliciesSettings'); // phpcs:ignore

        /** @var \Passbolt\PasswordPoliciesUpdate\Model\Entity\PasswordPoliciesSetting $passwordPoliciesSetting */
        $passwordPoliciesSetting = $passwordPoliciesSettingsTable->createOrUpdateSetting(
            $passwordPoliciesSettingsTable->getProperty(),
            $settingsDto->toOrganizationSettingValueArray(),
            $uac
        );

        $createdUpdatedSettingsDto = PasswordPoliciesUpdateSettingsDto::createFromEntity($passwordPoliciesSetting);

        /** Dispatch settings updated event. */

View on GitHub (pinned to 31c1bbc10f)