I recently upgraded a Symfony 5.4 project to 6.1. After the upgrade I can't open the start page anymore. The /login
page and logging in with a user still works.
The error shown on any other page is pretty cryptic:
ErrorException: Warning: preg_match(): Compilation failed: unmatched closing parenthesis at offset 2
at vendor/symfony/http-foundation/RequestMatcher.php:165
at Symfony\Component\HttpFoundation\RequestMatcher->matches(object(Request)) (vendor/symfony/security-http/AccessMap.php:42)
If I comment out all access_control
in security.yaml
I can navigate around the page again, so I assume the error is somewhere in those rules. I have looked at https://symfony.com/doc/current/security/access_control.html but can't figure out why my config is broken. Is this the source of the error message?
This is my security.yaml
:
security:
enable_authenticator_manager: true
password_hashers:
App\Entity\User:
algorithm: auto
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: app_user_provider
custom_authenticator: App\Security\LoginFormAuthenticator
logout:
path: security_logout
target: security_login
form_login:
check_path: security_login
login_path: security_login
enable_csrf: true
default_target_path: default_index
entry_point: form_login
access_control:
- { path: ^/login$, roles: PUBLIC_ACCESS }
- { path: ^/registration, roles: PUBLIC_ACCESS }
- { path: ^/resetting, roles: PUBLIC_ACCESS }
- { path: ^/locale, roles: PUBLIC_ACCESS }
- { path: ^/_error, roles: PUBLIC_ACCESS }
- { path: ^/), roles: ROLE_USER }
CodePudding user response:
The error message basically tells you what's wrong.
Your last access_control rule uses a closing parenthesis ")". In Regex this is a reserved character. If this is not a mistake and you actually have routes starting with a closing parenthesis, then you will have to escape the character like so:
- { path: ^/\), roles: ROLE_USER }