kroo / kroo/reflex-clerk

Better Pattern for Protected State Vars

Open
#8 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
29
Forks
17
PR merge metrics
No merged PRs in 30d

Description

Investigate the following two methods for ensuring state vars are not leaked to unauthenticated users:

  1. Inherit from a "protected state" class, which does not allow any of the fields to be returned unless the user is logged in.
class State(clerk.ClerkProtectedState):
    field1: int
    field2: str
  1. Annotate a state class or var with a decorator, perhaps named auth_required, or protect, which allows you to specify 'permission' or 'role', similar to the react component:
@protect(permission="org:invoices:create")
class State(rx.State):
    field1: int
    field2: str


class State2(rx.State):
    field1: Protected[int, Role("org:billing")]
    field2: Protected[str, Permission("org:invoices:create")]
    field3: Protected[bool]

    @rx.var
    @protect(role="org:billing")
    def field4(self) -> str:
        return self._field2

Approach 1 is simple, encourages the substate behavior described above, and makes accessing the signed in user information straight forward... Approach 2 feels pretty magical, and allows for much finer-grained permissions, but has the dangerous default of allowing information to leak if you don't wrap one of the fields...

(Discord thread here)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the protected-state inheritance and decorator or type-annotation approaches described in issue #8, then review the linked Discord discussion for existing context. Done means documenting or agreeing on a safe pattern that prevents unauthenticated state leakage and defines the permission and role behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authentication, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.