Skip to main content
PocketBase uses rule-based access control to determine who can access and modify your data. Rules are written as filter expressions and applied at the collection level.

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:
Effect: Only superusers can perform this action. Regular users and guests are denied access.
Use nil to completely lock down an action. This is the most restrictive setting.

Auth rule

The authRule is special because it applies after successful authentication:
Common use cases:
The auth rule check happens in RecordAuthResponse:

Manage rule

The manageRule gives admin-like permissions for auth records:
What manage rule allows:
  • Change passwords without requiring the old password
  • Directly update the verified state
  • Modify email without confirmation
  • Ignore email visibility settings when viewing records
Example configurations:
The manage rule enables email visibility for matched records:
The manage rule is executed in addition to the Create and Update API rules. Use it carefully as it grants elevated permissions.

Filter expression syntax

Rules use the same syntax as the filter 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:
System collection rules cannot be changed:
You cannot modify API rules for system collections like _superusers, _mfas, _otps, etc.

Checking access programmatically

You can check if a user can access a record using the CanAccessRecord 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

Always test your rules thoroughly. Incorrect rules can expose sensitive data or prevent legitimate access.

Best practices

  1. Start restrictive: Begin with nil rules and open up access as needed.
  2. Validate both sides: Check both @request.auth and record fields in rules.
  3. Use manage rule carefully: Only grant manage permissions to trusted users.
  4. Test as different users: Always test rules from the perspective of different user roles.
  5. Avoid public write access: Be very cautious about setting Create/Update/Delete rules to "".
  6. Consider cascading deletes: Ensure delete rules account for related records.
  7. 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:

Collections

Learn about collection types

Auth overview

Authentication system overview

Query syntax

Filter expression reference

Hooks

Customize behavior with hooks