Challenge - 5 Problems
Firebase Rules Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Firebase Realtime Database: What does this rule allow?
Given the following Firebase Realtime Database security rule, what does it allow users to do?
{
"rules": {
"messages": {
"$messageId": {
".read": "auth != null",
".write": "auth != null && auth.uid == data.child('owner').val()"
}
}
}
}Attempts:
2 left
💡 Hint
Look at the conditions for .read and .write separately.
✗ Incorrect
The .read rule requires the user to be authenticated (auth != null), so any signed-in user can read messages. The .write rule requires the user to be authenticated and their uid to match the message's owner field, so only owners can write.
❓ Architecture
intermediate2:00remaining
Firebase Firestore: How to structure rules for user profiles?
You want to allow users to read any profile but only edit their own profile in Firestore. Which rule structure achieves this?
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
// Fill in read and write rules
}
}
}Attempts:
2 left
💡 Hint
Think about who should read and who should write.
✗ Incorrect
Allowing read if true means anyone can read profiles. Allowing write only if the authenticated user's uid matches the userId means only owners can edit their profiles.
❓ security
advanced2:00remaining
Firebase Realtime Database: What error occurs with this rule?
Consider this Firebase Realtime Database rule snippet:
What error will this cause when deploying?
{
"rules": {
"posts": {
"$postId": {
".write": "auth.uid == newData.child('author').val()"
}
}
}
}What error will this cause when deploying?
Attempts:
2 left
💡 Hint
Check if 'newData' usage requires existence checks.
✗ Incorrect
'newData' can be null if the write is a delete. The rule must check if 'newData' exists before accessing child values to avoid errors.
✅ Best Practice
advanced2:00remaining
Firestore Rules: Preventing unauthorized document deletion
Which Firestore rule best prevents users from deleting documents they do not own, while allowing them to update other fields?
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /items/{itemId} {
allow update: if request.auth.uid == resource.data.owner;
allow delete: ???
}
}
}Attempts:
2 left
💡 Hint
Who should be allowed to delete documents?
✗ Incorrect
Only the owner should delete their document. Checking resource.data.owner ensures the user owns the existing document before deletion.
🧠 Conceptual
expert2:00remaining
Firebase Security Rules: What is the effect of this rule order?
Consider these Firebase Realtime Database rules:
What is the effective read permission for the path /users/123 if the user is authenticated but their uid is not '123'?
{
"rules": {
".read": "auth != null",
"users": {
"$uid": {
".read": "auth.uid == $uid",
".write": "auth.uid == $uid"
}
}
}
}What is the effective read permission for the path /users/123 if the user is authenticated but their uid is not '123'?
Attempts:
2 left
💡 Hint
Remember how Firebase merges rules at different levels.
✗ Incorrect
In Firebase Realtime Database, rules cascade and the most permissive rule applies. The top-level .read allows any authenticated user to read all data, so the user can read /users/123 even if not owner.