Better Pattern for Protected State Vars
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:
- 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
- Annotate a state class or var with a decorator, perhaps named
auth_required, orprotect, 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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