iq2i / herse-bundle
Account security building blocks for Symfony and Sylius: password policy, login throttling, trusted devices, password change notification and two-factor authentication
Requires
- php: >=8.2
- symfony/config: ^6.4|^7.0|^8.0
- symfony/dependency-injection: ^6.4|^7.0|^8.0
- symfony/http-kernel: ^6.4|^7.0|^8.0
- symfony/property-access: ^6.4|^7.0|^8.0
- symfony/security-bundle: ^6.4|^7.0|^8.0
- symfony/security-http: ^6.4|^7.0|^8.0
- symfony/validator: ^6.4|^7.0|^8.0
Requires (Dev)
- bacon/bacon-qr-code: ^2.0|^3.0
- doctrine/collections: ^1.8|^2.1|^3.0
- doctrine/doctrine-bundle: ^2.12|^3.0
- doctrine/orm: ^2.19|^3.0
- doctrine/persistence: ^3.1|^4.0
- easycorp/easyadmin-bundle: ^4.8|^5.0
- friendsofphp/php-cs-fixer: ^3.52
- phpstan/phpstan: ^2.1
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^10.5|^11.5
- scheb/2fa-bundle: ^7.0|^8.0
- scheb/2fa-email: ^7.0|^8.0
- scheb/2fa-totp: ^7.0|^8.0
- scheb/2fa-trusted-device: ^7.0|^8.0
- spomky-labs/otphp: ^11.4
- symfony/browser-kit: ^6.4|^7.0|^8.0
- symfony/cache: ^6.4|^7.0|^8.0
- symfony/css-selector: ^6.4|^7.0|^8.0
- symfony/dom-crawler: ^6.4|^7.0|^8.0
- symfony/form: ^6.4|^7.0|^8.0
- symfony/framework-bundle: ^6.4|^7.0|^8.0
- symfony/http-client: ^6.4|^7.0|^8.0
- symfony/mailer: ^6.4|^7.0|^8.0
- symfony/phpunit-bridge: ^7.4|^8.0
- symfony/polyfill-php84: ^1.31
- symfony/rate-limiter: ^6.4|^7.0|^8.0
- symfony/translation: ^6.4|^7.0|^8.0
- symfony/twig-bundle: ^6.4|^7.0|^8.0
- symfony/yaml: ^6.4|^7.0|^8.0
- vincentlanglet/twig-cs-fixer: ^4.1
Suggests
- bacon/bacon-qr-code: To show a QR code on the screen enrolling an authenticator app (two_factor.method: totp)
- doctrine/doctrine-bundle: To detect the password changes (password_change_notification) and to register the trusted devices (trusted_devices)
- doctrine/orm: To detect the password changes (password_change_notification) and to register the trusted devices (trusted_devices)
- scheb/2fa-bundle: To enable the two-factor authentication (two_factor), with scheb/2fa-email or scheb/2fa-totp for the method
- scheb/2fa-email: To use the email method of the two-factor authentication (two_factor.method: email)
- scheb/2fa-totp: To use the TOTP method of the two-factor authentication (two_factor.method: totp)
- scheb/2fa-trusted-device: To let a trusted device skip the second factor (two_factor.trusted_devices)
- symfony/ai-mate: Gives your agent the Herse skill (vendor/bin/mate discover)
- symfony/form: To use the PasswordPolicyType form type
- symfony/http-client: To reject compromised passwords (password_policy.check_compromised)
- symfony/mailer: To send the security emails
- symfony/rate-limiter: To limit the login attempts (login_throttling) and the wrong second factors (two_factor.throttling)
- symfony/translation: To translate the validation messages
- symfony/twig-bundle: To render the security emails
Provides
None
Conflicts
None
Replaces
None
README
Account security building blocks for Symfony and Sylius. Each feature is configured on its own and is disabled by default; a disabled feature registers no service, listener or route.
| Feature | Config key | Guide |
|---|---|---|
| Password policy | password_policy |
docs/password-policy.md |
| Login throttling | login_throttling |
docs/login-throttling.md |
| Trusted devices | trusted_devices |
docs/trusted-devices.md |
| Password change notification | password_change_notification |
docs/password-change-notification.md |
| Two-factor authentication | two_factor |
docs/two-factor.md |
The three security emails (new device, password change, two-factor code) share one sender, described in docs/emails.md.
The bundle brings the screens with the features: the second factor form, the enrollment of an authenticator app, the reset of a lost one and the list of the trusted devices. They are bare pages placed in the layout of your project, see docs/two-factor.md.
Requirements: PHP 8.2+, Symfony 6.4, 7.x or 8.x. Sylius 2.2 and 2.3 are supported, see docs/sylius.md.
Installation
composer require iq2i/herse-bundle
Register the bundle in config/bundles.php if Symfony Flex did not:
IQ2i\HerseBundle\IQ2iHerseBundle::class => ['all' => true],
Each feature then lists the packages it needs: enabling a feature without one of them fails the container
compilation with the exact composer require command to run. On a project that already has users, follow
docs/upgrading-an-existing-project.md.
Configuration
Declare the user classes of your project. A user is referred to by a neutral reference (a type and an identifier), never by a Doctrine relation.
iq2i_herse: users: App\Entity\AdminUser: type: admin # unique across the declared classes email: email # property path of the recipient address id: id # property path of the identifier, "id" by default password: password # Doctrine field of the hashed password, "password" by default locale: locale # property path of the user locale, optional App\Entity\ShopUser: type: shop email: customer.email firewalls: # the firewalls the features protect admin: ~ main: ~ password_policy: true # or { enabled: true }
The bundle never writes your security configuration. It checks it instead: when a declared firewall misses a line
a feature relies on, the container compilation fails with the lines to add to security.yaml.
The other options are described in the guide of each feature.
AI agents
The bundle ships a skill and instructions for Symfony Mate, so that an AI agent can install and configure the features:
composer require --dev symfony/ai-mate vendor/bin/mate discover
Development
The tools run in Docker.
make install make ci
The Sylius application of the test suite has its own dependencies:
make sylius-install # SYLIUS_VERSION=2.2 for the other supported version
make sylius-test
License
MIT