Skip to content

Conversation

@egormanga
Copy link
Contributor

Description of Changes

Fix for a bigger issue brought up in #2830 (comment).

Additionally, this seems to allow for some extra query optimizations (see tests).

API and ABI breaking changes

None.

Expected complexity level and risk

2:

While the fix seems pretty straightforward, it somehow affected query optimization logic so it might go a bit deeper than that.

Testing

  • A simple setup:
    #[table(name=test, public)]
    pub struct Test {
    	owner_id: Identity,
    }
    
    #[client_visibility_filter]
    const TEST_FILTER: Filter = Filter::Sql("SELECT test.* FROM test JOIN access WHERE access.owner_id == :sender AND access.allowed = true");
    
    #[table(name=access, public)]
    pub struct Access {
    	owner_id: Identity,
    	allowed: bool,
    }
    
    #[client_visibility_filter]
    const ACCESS_FILTER: Filter = Filter::Sql("SELECT * FROM access WHERE false");
    
    #[reducer]
    pub fn test_add(ctx: &ReducerContext) {
    	ctx.db.test().insert(Test {
    		owner_id: ctx.sender,
    	});
    }
    1. call test_add
    2. add an Access
    3. sql SELECT * FROM test;
      Result: [][0xIDENTITY]
  • A personal project where the issue arose
  • Added a test
  • Understand why the existing test result changed

@CLAassistant
Copy link

CLAassistant commented Jun 5, 2025

CLA assistant check
All committers have signed the CLA.

Comment on lines 272 to 273
// Use the owner identity to evaluate the RLS query joins
&AuthCtx::for_current(auth.owner),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@egormanga this means the expression will be evaluated as though it were from the owner identity, not the caller identity. And the owner bypasses RLS rules, meaning their access is not restricted. So this would result in non-owner identities gaining access to data they shouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. According to my testing, this only applies to the RLS rule evaluation, not to the original user query.

I might be wrong, but if I wouldn't get both positive test results for my case and negative for restricted data access (e.g. the access table in my example), I wouldn't've submitted this PR :)

@egormanga

This comment was marked as resolved.

Additionally, this seems to allow for some extra query optimizations (see tests).
@egormanga egormanga force-pushed the fix-rls-joins-identity branch from 2df7580 to d1ea89b Compare November 22, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants