Consider the following Firebase security rule snippet using a custom function:
function isOwner() { return request.auth.uid == resource.data.ownerId; }What does the isOwner() function check?
Look at what request.auth.uid and resource.data.ownerId represent.
The function compares the user ID of the person making the request with the owner ID stored in the data. If they match, the user is the owner.
Given this Firebase rule custom function:
function canEdit() { return isOwner() && request.time < resource.data.expiry; }Which of the following is true about canEdit()?
Focus on the logical AND operator && in the function.
The function returns true only if both conditions are true: the user is the owner and the request time is before the expiry time.
Which of the following statements best describes how custom functions affect Firebase security rule evaluation?
Think about how repeated calls to functions affect processing.
While custom functions help organize rules, complex logic or multiple calls can slow down evaluation because each call runs the function code.
What is a potential security risk when a custom function in Firebase rules uses request.resource.data without validation?
Consider what request.resource.data represents and who controls it.
request.resource.data is data sent by the client. Without validation, malicious users can send crafted data to trick rules.
Given these Firebase security rules:
function isAdmin() { return request.auth.token.admin == true; }
function canDelete() { return isAdmin() || isOwner(); }
function isOwner() { return request.auth.uid == resource.data.ownerId; }
allow delete: if canDelete();If a user with request.auth.uid = 'user123' and request.auth.token.admin = false tries to delete a document with resource.data.ownerId = 'user123', what will be the result?
Check the logic of canDelete() and the user's attributes.
The canDelete() function allows deletion if the user is admin or owner. Here, the user is not admin but is the owner, so deletion is allowed.