symfony/validator
The Symfony Validator component provides tools to validate values following the JSR-303 Bean Validation specification, with constraints, annotations, and attributes for expressive, reusable validation rules.
symfony/validator package adheres to JSR-303 Bean Validation, a standard widely adopted in PHP ecosystems. It integrates seamlessly with Laravel’s existing validation mechanisms (e.g., Validator facade) and can replace or augment Laravel’s built-in validation logic.ValidatorBuilder) for faster validation in production.Illuminate/Validation is built on top of Symfony’s validator, so adopting this package directly aligns with Symfony’s roadmap (e.g., PHP 8.4+ compatibility in v8.x).Validator facade already uses Symfony’s validator under the hood. Direct integration is possible with minimal changes.Validator::make($data, $rules) with ValidatorBuilder::create()->getValidator()->validate($data, $constraints).symfony/options-resolver, symfony/property-access). No conflicts with Laravel’s core.symfony/expression-language version and any Expression-constraint usage resolve to patched releases. Composer will not surface this as a conflict — verify via composer show / SBOM, not just composer update.'email', 'required') can be mapped to Symfony’s constraints (e.g., Email, NotBlank) via custom constraint classes or validation groups.symfony/validator's YAML/XML mapping or attributes (PHP 8+) for declarative validation.Expression constraint (and any When/conditional constraints that delegate to the expression parser) will happily parse an arbitrarily deep expression tree. An attacker able to influence expression content — e.g. a rule-builder UI, tenant-configurable validation, imported/uploaded constraint metadata, or admin-supplied expressions persisted to the DB — can induce deep recursion and exhaust the request’s stack/CPU. This is a denial-of-service vector, not a data-exfiltration vector, so the blast radius is availability.GroupSequence). Requires migration effort if using older configurations.Constraint, ConstraintValidator). Mitigate with documentation and unit tests.ValidatorBuilder::create()->enableAnnotationMapping() for attribute-based validation (PHP 8+).symfony/validator line are we actually resolving today — 5.4.x, 6.4, 7.x, or 8.x? The advisory is published against 5.4.54; we need the resolved version per environment, not the target version.Expression constraint’s expression string originates from user input, tenant config, or an import? If yes, this is a Sev-1 remediation, not a routine bump.[SECURITY]-tagged upstream releases?Rule objects) be migrated to Symfony constraints?Default, Create, Update) be defined and reused across the application?Validator::make()) be adapted to use Symfony’s validator?Expression constraint and asserts a controlled failure rather than a stack overflow?ConstraintViolationList can be mapped to Laravel’s Validator::errors().Video, ExtendsValidationFor) be incorporated into the codebase?Illuminate/Validation is a wrapper around Symfony’s validator. Direct adoption reduces abstraction layers.ValidatorInterface for dependency injection.FormRequest or ApiResource for automatic validation.protected $rules in FormRequest with Symfony constraints via attributes or metadata.| Phase | Action Items | Tools/Dependencies |
|---|---|---|
| Hotfix (new, step 0) | Inventory resolved symfony/validator version per environment; patch to 5.4.54+ (or confirmed-patched 6.4/7.x/8.x). Grep for Expression constraint usage. |
composer show, SBOM export, CI dependency scanner. |
| Assessment | Audit existing validation logic (e.g., Validator::make(), custom rules). |
PHPStan, Pest tests. |
| Pilot | Replace 1–2 critical validation use cases (e.g., user registration, API endpoints). | Symfony’s ValidatorBuilder, Laravel’s Validator facade. |
| Core Integration | Migrate FormRequest/ApiResource validation to Symfony constraints. |
PHP attributes (v8.x) or YAML/XML mapping. |
| Testing | Update unit/feature tests to use Symfony’s ConstraintViolationList. |
PestPHP, Laravel Dusk. |
| Deprecation | Phase out Laravel’s Rule objects in favor of Symfony constraints. |
Custom constraint classes. |
| Optimization | Enable compiled metadata for production. | ValidatorBuilder::enableAnnotationMapping(). |
| Laravel Rule | Symfony Constraint | Notes |
|---|---|---|
required |
NotBlank |
Use null for nullable fields. |
email |
Email |
Supports custom domains. |
min:5 |
Length(min=5) |
Supports min/max in error messages. |
unique:users,email |
UniqueEntity (Doctrine) |
Requires symfony/doctrine-bridge. |
| Custom rules | Custom Constraint class |
Extend AbstractConstraint. |
| (new) expression-based rules | Expression |
Only with patched versions; never with user-supplied expression strings. |
composer show and a deployment smoke test.FormRequest/ApiResource validation first (high ROI, isolated scope).Rule objects to Symfony constraints (e.g., CustomRule::class → new CustomConstraint()).if (!$request->has('email'))) with Symfony’s validator.config/validator.php).Validator::make() in favor of dependency-injected ValidatorInterface.Email, Url validations).ConstraintValidator interfaces).symfony/validator:validate) for debugging.[SECURITY]-tagged releases escalated, or composer audit in CI) so security patches on the validator package cannot sit unapplied.ConstraintViolation objects with property paths).App\Exceptions\Handler or via Sentry.symfony/expression-language remains locked. Both leave the parsing path exposed despite a green changelog. Mitigate with a single dependency-resolution check across all environments in CI.Expression constraints. Days, not weeks, provided no user-supplied expressions are found.How can I help you explore Laravel packages today?