Overview
SnackBase security operates on multiple layers to ensure data protection:Authentication vs Authorization
Understanding the distinction is critical:Example Scenario
Role-Based Access Control (RBAC)
SnackBase uses RBAC as the foundation of authorization.RBAC Hierarchy
Default Roles
Custom Roles
You can create custom roles for any purpose:Permission System
Permissions define what operations a user can perform on which collections.Permission Matrix
For a role with permissions:Permission Structure
Wildcard Collections
Use* to grant permissions on all collections:
Permission Caching
Permissions are cached for 5 minutes to improve performance:Rule Engine
SnackBase includes a powerful rule engine for fine-grained access control.Rule Syntax
Rules use a custom DSL (Domain Specific Language):Built-in Functions
Rule Evaluation Context
Rules have access to:Permission Rules Example
- They created the post AND status is draft/pending, OR
- They have admin role
Field-Level Security
SnackBase supports field-level access control to hide sensitive data.Field Visibility
Restrict which fields a role can see:Field-Level Rules
Apply rules to specific fields:Account Isolation
Account isolation is the foundation of SnackBase security.Multi-Tenant Isolation
All data is automatically isolated byaccount_id:
Enforcement Layers
Account isolation is enforced at multiple layers:Cross-Account Access Prevention
Attempting to access another account’s data:account_id parameters.
Security Best Practices
1. Principle of Least Privilege
Grant minimum required permissions:2. Use Rules for Fine-Grained Control
Leverage the rule engine for complex scenarios:3. Implement Field-Level Security
Hide sensitive fields by default:4. Regular Permission Audits
Periodically review and update permissions:- Remove unused roles
- Tighten overly permissive rules
- Document permission rationale
- Use audit logs (when available) to track access
5. Use Wildcards Carefully
Wildcard permissions (*) are powerful but dangerous:
6. Test Permission Changes
Always test permission changes in development:7. Monitor and Alert
Monitor for suspicious activity:- Repeated failed authorization attempts
- Unusual access patterns
- Permission escalation attempts
- Cross-account access attempts
Common Security Scenarios
Scenario 1: User Can Only Edit Their Own Posts
Scenario 2: Moderators Can Edit All Comments
Scenario 3: Public Read, Private Write
Security Headers
SnackBase implements defense-in-depth security by automatically setting HTTP security headers on all responses.Automatic Headers
All responses include the following security headers:Content Security Policy (CSP)
The default CSP is designed for maximum security while supporting the Admin UI:default-src 'self': Only load resources from same originscript-src 'self': Block inline scripts and external scriptsstyle-src 'self' 'unsafe-inline': Allow inline styles (for React)img-src 'self' data:: Allow images from same origin and data URIsframe-ancestors 'none': Prevent iframe embedding
Customization
Customize security headers via environment variables:Environment-Aware Behavior
Security headers adapt to the environment:
This prevents HSTS issues during local development while enforcing HTTPS in production.