Symfony's Doctrine tenant filter explained: where it works and where it silently fails
A single-database multi-tenancy setup in Symfony can be enforced using a roughly 30-line Doctrine SQLFilter that automatically appends an organization_id condition to queries for tenant-owned entities. The filter is activated via a Symfony kernel.request listener at priority 7, just after the firewall populates the authenticated user at priority 8, ensuring tenant scoping applies to HTTP requests. However, the filter is deliberately disabled by default in configuration, meaning CLI processes such as console commands, cron jobs, and Messenger consumers run without it and can access all tenants' data. This is intentional for tasks like billing that must span all organizations, but it means the isolation guarantee applies only to web requests, not the full application. Any worker or script touching tenant-owned data must implement its own scoping logic, as no framework-level safeguard exists in those contexts.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in