Skip to content

Evaluate RLS joins with the owner identity #2832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

egormanga
Copy link

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

Additionally, this seems to allow for some extra query optimizations (see tests).
@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
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 :)

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