Rule types
Every collection (base, auth, or view) can have the following API rules:Rules are evaluated using filter expressions, similar to the
filter query parameter syntax.Rule values
Each rule can have one of three values:- null (locked)
- Empty string (public)
- Filter expression
Auth rule
TheauthRule is special because it applies after successful authentication:
RecordAuthResponse:
Manage rule
ThemanageRule gives admin-like permissions for auth records:
- Change passwords without requiring the old password
- Directly update the verified state
- Modify email without confirmation
- Ignore email visibility settings when viewing records
Filter expression syntax
Rules use the same syntax as thefilter query parameter:
Special fields
@collection.* and @request.* fields are only available to superusers when used in filter query parameters for security reasons.Operators
Logical operators
Common rule patterns
Public read, authenticated write
Owner-only access
Role-based access
Organization/tenant isolation
Status-based access
Rule validation
PocketBase validates rules during collection save:Checking access programmatically
You can check if a user can access a record using theCanAccessRecord method:
List vs View rule differences
The key difference between List and View rules:- List Rule: Acts as a filter on the query results. Records not matching the rule are excluded from the list.
- View Rule: Acts as a permission check. If the rule doesn’t match, the request is denied with a 403/404 error.
The List rule is applied as a query filter, while the View rule is a binary permission check.
Expansion and rules
When expanding relations, PocketBase applies the View rule of the related collection:Security best practices
Best practices
-
Start restrictive: Begin with
nilrules and open up access as needed. -
Validate both sides: Check both
@request.authand record fields in rules. - Use manage rule carefully: Only grant manage permissions to trusted users.
- Test as different users: Always test rules from the perspective of different user roles.
-
Avoid public write access: Be very cautious about setting Create/Update/Delete rules to
"". - Consider cascading deletes: Ensure delete rules account for related records.
- Audit rule changes: Track changes to collection rules in production.
Custom rule validation
You can add custom rule validation using hooks:Rule migration example
When migrating from v0.22 to later versions:Related topics
Collections
Learn about collection types
Auth overview
Authentication system overview
Query syntax
Filter expression reference
Hooks
Customize behavior with hooks