{"record":{"id":"0bf299817fffce5b","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-password-policies-settings-0bf299","errorCode":null,"errorMessage":"Could not validate the password policies settings.","messagePattern":"Could not validate the password policies settings\\.","errorType":"validation","errorClass":"FormValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltEe/PasswordPoliciesUpdate/src/Service/PasswordPoliciesUpdateSetSettingsService.php","lineNumber":57,"sourceCode":"\n    /**\n     * Create passwords policies settings if not present already in DB or updates the settings value if already exists.\n     *\n     * @param \\App\\Utility\\ExtendedUserAccessControl $uac Extended user access control.\n     * @param array $requestData Request data.\n     * @return \\Passbolt\\PasswordPoliciesUpdate\\Model\\Dto\\PasswordPoliciesUpdateSettingsDto\n     */\n    public function createOrUpdate(ExtendedUserAccessControl $uac, array $requestData): PasswordPoliciesUpdateSettingsDto // phpcs:ignore\n    {\n        if (!$uac->isAdmin()) {\n            throw new ForbiddenException(\n                __('Only administrators are allowed to create/update password policies settings.')\n            );\n        }\n\n        $form = new PasswordPoliciesSettingsForm();\n        if (!$form->execute($requestData)) {\n            throw new FormValidationException(__('Could not validate the password policies settings.'), $form);\n        }\n\n        /** @var \\Passbolt\\PasswordPoliciesUpdate\\Model\\Dto\\PasswordPoliciesUpdateSettingsDto $settingsDto */\n        $settingsDto = PasswordPoliciesUpdateSettingsDto::createFromArray($form->getData());\n\n        /** @var \\Passbolt\\PasswordPoliciesUpdate\\Model\\Table\\PasswordPoliciesSettingsTable $passwordPoliciesSettingsTable */\n        $passwordPoliciesSettingsTable = $this->fetchTable('Passbolt/PasswordPoliciesUpdate.PasswordPoliciesSettings'); // phpcs:ignore\n\n        /** @var \\Passbolt\\PasswordPoliciesUpdate\\Model\\Entity\\PasswordPoliciesSetting $passwordPoliciesSetting */\n        $passwordPoliciesSetting = $passwordPoliciesSettingsTable->createOrUpdateSetting(\n            $passwordPoliciesSettingsTable->getProperty(),\n            $settingsDto->toOrganizationSettingValueArray(),\n            $uac\n        );\n\n        $createdUpdatedSettingsDto = PasswordPoliciesUpdateSettingsDto::createFromEntity($passwordPoliciesSetting);\n\n        /** Dispatch settings updated event. */","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/PasswordPoliciesUpdate/src/Service/PasswordPoliciesUpdateSetSettingsService.php#L39-L75","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Read the form errors attached to the FormValidationException to see which fields failed","Fix the payload so it matches PasswordPoliciesSettingsForm's validation rules (types, ranges, required keys)","Send the full expected settings structure, not a partial update, unless the form supports partial data","Add/update client-side validation mirroring the server form rules"],"exampleFix":"// before\n$this->post('/password-policies.json', ['password_generator' => ['length' => 3]]); // below min\n// after\n$this->post('/password-policies.json', ['password_generator' => ['length' => 20, 'words' => 3, 'min_digits' => 1, 'min_upper' => 1, 'min_special' => 1]]);","handlingStrategy":"validation","validationCode":"const requiredKeys = ['password_generator'];\nif (!requiredKeys.every(k => k in payload)) throw new Error('Missing required password policy fields');","typeGuard":null,"tryCatchPattern":"try { await postPasswordPolicies(payload); } catch (e) { if (e.formErrors) console.error('Invalid fields:', e.formErrors); else throw e; }","preventionTips":["Mirror the server-side form validation rules in the client","Keep the settings payload schema in sync with the current API version","Always send complete settings structures rather than partial updates","Inspect formErrors in the exception response for exact field failures"],"tags":["validation","form-validation","password-policies"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}