Skip to main content
SnackBase provides a comprehensive security model with role-based access control, field-level permissions, and a powerful rule engine. This guide explains the security architecture, authorization flows, and best practices.

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:
This grants admin full access to ALL collections, including future ones.

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

Translation: Users can update posts if:
  • 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:
Users with this role will receive:

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 by account_id:
Users cannot see or access data from other accounts.

Enforcement Layers

Account isolation is enforced at multiple layers:

Cross-Account Access Prevention

Attempting to access another account’s data:
The system ignores malicious 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:
Key Directives:
  • default-src 'self': Only load resources from same origin
  • script-src 'self': Block inline scripts and external scripts
  • style-src 'self' 'unsafe-inline': Allow inline styles (for React)
  • img-src 'self' data:: Allow images from same origin and data URIs
  • frame-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.

Summary