passbolt/passbolt_api · error · FormValidationException

Could not validate the user passphrase policies settings.

Error message

Could not validate the user passphrase policies settings.

What it means

After the admin check, UserPassphrasePoliciesSetSettingsService::createOrUpdate runs the request data through UserPassphrasePoliciesSettingsForm. If execute() fails, it throws FormValidationException with this message and the form object, which carries the per-field validation errors.

Solutions

  1. Read the errors from the FormValidationException/form to identify the offending fields.
  2. Correct the payload to match UserPassphrasePoliciesSettingsForm's schema (valid source, integer lengths within range) and resend.
  3. Validate the DTO client-side (e.g. via UserPassphrasePoliciesSettingsDto shapes) before posting.

Example fix

// before
{ "source": "policy", "length_min": "eight" }
// after
{ "source": "policy", "length_min": 8 }
Defensive patterns

Strategy: validation

Validate before calling

const valid = Number.isInteger(cfg.length_min) && cfg.length_min >= 8 && ['policy','user'].includes(cfg.source); if (!valid) return reject('invalid passphrase policy payload');

Type guard

const isValidPolicyPayload = (p): p is PolicyPayload => typeof p?.length_min === 'number' && typeof p?.source === 'string';

Try / catch

try { await postSettings(payload); } catch (e) { if (e.formErrors) showFieldErrors(e.formErrors); }

Prevention

When it happens

Trigger: POSTing user passphrase policies settings whose payload fails form rules - e.g. invalid 'source' value, non-numeric or out-of-range length, bad entropy/weak-min-entropy values, or wrong value types.

Common situations: Client sends snake_case vs camelCase mismatch, omits required fields, or sends strings where integers are expected; automation posts raw config that was never validated.

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/3ccac9bd8591f71b. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltEe/UserPassphrasePolicies/src/Service/UserPassphrasePoliciesSetSettingsService.php:58

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

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

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

        /** @var \Passbolt\UserPassphrasePolicies\Model\Table\UserPassphrasePoliciesSettingsTable $userPassphrasePoliciesSettingsTable */
        $userPassphrasePoliciesSettingsTable = $this->fetchTable('Passbolt/UserPassphrasePolicies.UserPassphrasePoliciesSettings'); // phpcs:ignore

        /** @var \Passbolt\UserPassphrasePolicies\Model\Entity\UserPassphrasePoliciesSetting $userPassphrasePoliciesSetting */
        $userPassphrasePoliciesSetting = $userPassphrasePoliciesSettingsTable->createOrUpdateSetting(
            $userPassphrasePoliciesSettingsTable->getProperty(),
            $settingsDto->toOrganizationSettingValueArray(),
            $uac
        );

View on GitHub (pinned to 31c1bbc10f)