- 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 recordsread- View recordsupdate- Modify recordsdelete- Remove records
Field Level Security (FLS)
create- Set the field when creating a recordread- View the fieldupdate- Change the field on an existing recordwrite- Shorthand for bothcreateandupdate. Acreateorupdatekey takes priority overwrite.
Permission values
Each permission accepts one of the following values:true- Allow all usersfalse- 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()anddeleteMany()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.id- The record’s IDcreated_by- Email of user who created the recordcreated_by_id- ID of user who created the recordcreated_date- When the record was createdupdated_date- When the record was last updateddata.*- 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.{{user.email}}- User’s email{{user.id}}- User’s ID{{user.role}}- User’s role{{user.data.*}}- Additional user fields you define
user_condition.
User fields you can check:
email- User’s emailid- User’s IDrole- User’s roledata.*- Custom user fields
$or, $and, $nor, $in, $nin, $all
Example:
Row Level Security (RLS) example
Addrls at the entity level:
Field Level Security (FLS) example
Addrls to individual field properties:
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(), andbulkUpdate(). 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 thedata.prefix, such asdata.status. Built-in fields such ascreated_bydon’t take the prefix. - Conditions on create: A
createrule 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 setsstatus. To control who can set a field on create, compare the caller instead, withuser_conditionorcreated_by. - Conditions on update: An
updaterule 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, andwrite. The check runs only on field rules you change, so a rule saved earlier can still have an unknown key, such as a misspelledudpate. Base44 ignores that key, so the field has no restriction where the key was meant to add one. - A
deleterule: Deleting removes the whole record, so a field can’t restrict it. A field-leveldeleteset tofalseor a condition is rejected. Put the restriction in the entity-levelrls.deleteinstead. - A custom field without
data.: A condition on one of your own fields has to name it with thedata.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 usingentities push. Security rules are also deployed automatically when you run the deploy command to deploy your entire project.
See also
- Entities Overview: Learn about database schema configuration
- Entity Schemas: Define your entity structure
- User Schema: Special built-in entity for user authentication
- Service role data access: Read and write data without access rules applying
- Project Structure: How entity schemas fit into your project