What happened

The post details a surprising discovery regarding row-level security (RLS) in Symfony applications using PostgreSQL. The core issue centers around the role that connects to the database – often the application's default user – bypassing RLS policies defined on tables. This occurs regardless of whether those policies are correctly configured or actively enforced.

Specifically, the author found that a test environment connected with a superuser account consistently bypassed RLS, while an identically-configured production deployment did not. The root cause lay in the fact that a simple database owner role – the one typically used for Doctrine migrations — lacked explicit configuration to enforce RLS. The crucial piece is that the 'owner' role allows access but doesn’t inherently demand adherence to those row-level policies. This means the connection’s identity, regardless of whether it was set intentionally or not (like a superuser), was granting unfiltered access. The example provided demonstrates this vulnerability with a simple table creation and policy implementation, showcasing how an application connecting as the ‘app’ role, without any specific tenant ID, could read all rows in the table – bypassing the intended isolation enforced by the RLS policy.

Why it matters

This vulnerability represents a significant security risk for Symfony applications utilizing PostgreSQL and Doctrine. The fact that the issue wasn't detected during testing—due to the test environment’s superuser access—underscores the danger of relying solely on test data or connections that bypass security measures.

Many developers assume their tests accurately represent production, but this is a critical misstep when dealing with RLS. The wider implication is that developers need to deeply understand how roles and privileges interact within PostgreSQL, especially concerning RLS. Failing to recognize the potential for default roles to circumvent policies can lead to data breaches and unauthorized access, particularly in multi-tenant environments.

But, but, but…

The issue arises because Doctrine’s migration process often defaults to using the application's database connection—a role that is frequently set up as a superuser. This creates a scenario where the connection itself possesses sufficient privileges to ignore row-level security configurations.

The author emphasizes that this isn't an intentional design flaw in Symfony or Doctrine; it simply reflects a prevalent deployment pattern: connecting with a powerful, unrestricted role. It highlights the need for careful scrutiny of database roles and their associated permissions when implementing RLS, along with robust testing that mirrors real-world application environments. The author is arguing that 'normal' deployments are prone to this vulnerability because the assumption of an owner role automatically enforcing RLS doesn’t always hold true.

“A plain role that merely owns the table bypasses that table's policies too. Not a superuser. No BYPASSRLS . Just the owner.”
— Dr Non

The counter-take

The common assumption that Doctrine migrations automatically handle RLS without requiring manual role configuration is demonstrably false. Many developers overlook the subtle differences between database roles and their impact on security policies, leading to significant vulnerabilities.

The AI angle

As AI systems increasingly rely on relational databases to manage data, vulnerabilities like this become critically important; a compromised RLS policy can expose sensitive information or allow unauthorized access to critical datasets.