This is the full reference for everything you can use inside Lark security rule expressions. If you’re new to rules, start with the security rules overview first.
These variables are available in every rule expression.
Variable
Type
Description
auth
object | null
The authenticated user. null if the client is unauthenticated.
auth.uid
string
The unique ID of the authenticated user.
auth.provider
string
The authentication provider (e.g., "google", "anonymous", "password", "facebook", "github", "twitter").
auth.token
object
The contents of the auth token, including any custom claims.
data
snapshot
A snapshot of the current data at this path, before the write.
newData
snapshot
A snapshot of the data that would exist after the write. The merged result of new data and existing data. Only available in .write and .validate rules.
root
snapshot
A snapshot of the root of the entire database. Use this to read data at other paths.
now
number
The current server timestamp in milliseconds since epoch.
$wildcards
string
Path segment captures. For example, a rule at /users/$userId makes $userId available as a string variable containing the matched key.
lark.projectId
string
The ID of the current project.
lark.databaseId
string
The ID of the current database (the database name, not including the project prefix).
data and newData are scoped to the current path where the rule is defined. Use root when you need to look up data elsewhere in your database.
The data, newData, and root variables are all snapshots. You can call these methods on any snapshot.
Method
Returns
Description
val()
any
Returns the primitive value (string, number, boolean, null) at this snapshot. For snapshots with children, use child() to access nested values.
exists()
boolean
Returns true if this snapshot contains any data. Equivalent to val() != null.
hasChild(path)
boolean
Returns true if the specified child path exists. path can be a single key or a slash-separated path.
hasChildren(keys)
boolean
Returns true if all of the specified child keys exist. keys is an array of strings. With no arguments, returns true if the snapshot has any children.
parent()
snapshot
Returns a snapshot of the parent node. Fails if called on the root.
child(path)
snapshot
Returns a snapshot of the child at the given path. path can be a single key or a deeper slash-separated path (e.g., 'address/city'). If the child doesn’t exist, returns an empty snapshot.
getPriority()
string | number | null
Returns the priority of the data at this snapshot.
// Check if the current data existsdata.exists()// Check if the incoming data has both 'name' and 'score' childrennewData.hasChildren(['name', 'score'])// Read a sibling valuedata.parent().child('status').val() === 'active'// Look up data at another path entirelyroot.child('admins/' + auth.uid).exists()// Check a deeply nested childdata.child('stats/hp').val() > 0// Type-check incoming datanewData.child('name').isString() && newData.child('score').isNumber()
// Validate that a username is at least 3 charactersnewData.child('username').val().length >= 3// Check that an email looks validnewData.child('email').val().matches(/^[^@]+@[^@]+\.[^@]+$/)// Check a string prefixauth.token.identifier.beginsWith('internal-')// Escape periods for use as keysnewData.child('email').val().replace('.', '%2E')// Case-insensitive lookuproot.child('users').child(auth.token.identifier.toLowerCase()).exists()
You can restrict what queries clients are allowed to run by referencing query. expressions in your rules. This lets you enforce that clients include certain filters or limits.