Skip to main content
You’re viewing developer documentation
This documentation is for developers working with the Base44 developer platform. For information about managing your app data using the app editor, see Managing app data.
Entities support two levels of security:
  • Row Level Security (RLS): Controls which records users can access.
  • Field Level Security (FLS): Controls which fields within records users can access.
Service role access skips these rules: base44.asServiceRole bypasses both RLS and FLS entirely, regardless of how the entity is configured, so you don’t need a matching admin rule for it to read or write a record. It’s only available in Base44-hosted backend functions, and your function is responsible for any access checks it needs.

Permission types

Each security level has different permissions you can set. For each permission, you define who is allowed to perform the action.

Row Level Security (RLS)

  • create - Add new records
  • read - View records
  • update - Modify records
  • delete - Remove records

Field Level Security (FLS)

  • create - Set the field when creating a record
  • read - View the field
  • update - Change the field on an existing record
  • write - Shorthand for both create and update. A create or update key takes priority over write.

Permission values

Each permission accepts one of the following values:
  • true - Allow all users
  • false - Block all users
  • {<condition>} - Allow users matching the condition

How denied reads and writes differ

Denied reads behave as if the data doesn’t exist, so they don’t reveal what’s there. Denied writes throw, so a blocked change never fails silently.
A rule that compares id to a value that isn’t a record ID, such as {{user.email}}, never matches a record. The response depends on the operation:
  • list(), filter(), count, and aggregate calls return an empty result.
  • updateMany() and deleteMany() change nothing.
  • bulkUpdate() throws a 404 not-found error.

Condition syntax

When using {<condition>} as a permission value, you can define rules that check user attributes or roles.
A condition that references {{user.*}} or uses user_condition requires an authenticated caller. An anonymous caller has no user to compare against, so the rule blocks them outright rather than evaluating as false.
1. Entity-to-user comparison Compare record fields to the current user’s values. Entity fields you can reference:
  • id - The record’s ID
  • created_by - Email of user who created the record
  • created_by_id - ID of user who created the record
  • created_date - When the record was created
  • updated_date - When the record was last updated
  • data.* - Any field from your entity schema’s properties
You can’t reference the internal fields listed in Built-in fields in RLS rules. When you add or change a rule that references an internal field, such as the environment field, the request is rejected.
Template variables for user values:
  • {{user.email}} - User’s email
  • {{user.id}} - User’s ID
  • {{user.role}} - User’s role
  • {{user.data.*}} - Additional user fields you define
Example:
2. User condition check Check user properties directly using user_condition. User fields you can check:
  • email - User’s email
  • id - User’s ID
  • role - User’s role
  • data.* - Custom user fields
Example:
3. Complex conditions Combine multiple conditions using operators. Supported operators: $or, $and, $nor, $in, $nin, $all Example:

Row Level Security (RLS) example

Add rls at the entity level:

Field Level Security (FLS) example

Add rls to individual field properties:
Use create and update instead of write when the two need different rules. In this example, anyone can set status when they create a record, but only admins can change it afterward:

How field rules apply

  • Every write: Field rules apply to create(), bulkCreate(), importEntities(), upsert(), update(), updateMany(), and bulkUpdate(). If a write sets or changes a field the caller isn’t allowed to, the request throws a permission error. On update, only fields whose value changes are checked.
  • Reads: A field the caller can’t read is left out of the records they get back, including from get(), list(), filter(), and writes.
  • Admins: App admins aren’t exempt. To let them through, add a condition such as {"user_condition": {"role": "admin"}}. Only service role access skips field rules.
  • Conditions: Field rules use the same condition syntax as RLS, limited to exact matches, $in, $nin, $ne, $or, and $and. Reference your own fields with the data. prefix, such as data.status. Built-in fields such as created_by don’t take the prefix.
  • Conditions on create: A create rule is checked before the submitted values are applied, so a condition on one of your own fields never matches. A rule such as {"data.status": {"$in": ["draft"]}} doesn’t limit the starting value. It blocks every create that sets status. To control who can set a field on create, compare the caller instead, with user_condition or created_by.
  • Conditions on update: An update rule is checked against the record as it was before the change.

Field rules that can’t be saved

Pushing a schema fails if a field rule has one of these problems:
  • An unknown key: Field rules accept only create, read, update, and write. The check runs only on field rules you change, so a rule saved earlier can still have an unknown key, such as a misspelled udpate. Base44 ignores that key, so the field has no restriction where the key was meant to add one.
  • A delete rule: Deleting removes the whole record, so a field can’t restrict it. A field-level delete set to false or a condition is rejected. Put the restriction in the entity-level rls.delete instead.
  • A custom field without data.: A condition on one of your own fields has to name it with the data. prefix.

Complete example with security

Here’s an entity schema with both RLS and FLS:

Deploying security rules

Security rules are part of your entity schema. After adding or updating security rules, deploy using entities push. Security rules are also deployed automatically when you run the deploy command to deploy your entire project.

See also