0
0
Firebasecloud~20 mins

Rule syntax and structure in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Rule Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Firebase Rule Match Statements
Which of the following Firebase security rule match statements correctly matches all documents in the 'users' collection?
Amatch /users/{userId} { allow read, write: if request.auth != null; }
Bmatch /users { allow read, write: if request.auth != null; }
Cmatch /users/{userId}/profile { allow read, write: if request.auth != null; }
Dmatch /users/{userId}/documents/{docId} { allow read, write: if request.auth != null; }
Attempts:
2 left
💡 Hint
Remember that to match documents inside a collection, you need to specify a wildcard for document IDs.
Configuration
intermediate
2:00remaining
Evaluating Firebase Rule Condition Syntax
Which of the following Firebase rule conditions correctly checks if the authenticated user's ID matches the document ID being accessed?
Aallow read: if request.auth.uid == resource.data.uid;
Ballow read: if request.auth.uid == resource.data.userId;
Callow read: if request.auth.uid == request.resource.id;
Dallow read: if request.auth.uid == resource.id;
Attempts:
2 left
💡 Hint
The document's data field that stores the user ID must be referenced correctly.
Architecture
advanced
3:00remaining
Designing Firebase Rules for Nested Collections
You have a Firestore database with a collection 'projects' and each project has a subcollection 'tasks'. Which rule structure correctly allows authenticated users to read and write only their own projects and tasks?
Amatch /projects/{projectId} { allow read, write: if request.auth.uid == resource.data.ownerId; } match /projects/{projectId}/tasks/{taskId} { allow read, write: if request.auth.uid == resource.data.ownerId; }
B} ;dIrenwo.atad.ecruoser == diu.htua.tseuqer fi :etirw ,daer wolla { }dIksat{/sksat/}dItcejorp{/stcejorp/ hctam } ;dIrenwo.atad.ecruoser == diu.htua.tseuqer fi :etirw ,daer wolla { }dItcejorp{/stcejorp/ hctam
Cmatch /projects/{projectId} { allow read, write: if request.auth.uid == resource.data.ownerId; } match /projects/{projectId}/tasks/{taskId} { allow read, write: if request.auth.uid == resource.data.assigneeId; }
Dmatch /projects/{projectId} { allow read, write: if request.auth.uid == resource.data.ownerId; } match /projects/{projectId}/tasks/{taskId} { allow read, write: if request.auth.uid == resource.data.taskOwnerId; }
Attempts:
2 left
💡 Hint
Tasks may be assigned to different users than the project owner.
security
advanced
2:00remaining
Identifying Security Risks in Firebase Rules
Consider the following Firebase rule snippet:

match /posts/{postId} { allow read: if true; allow write: if request.auth != null; }

What is the main security risk with this rule?
Firebase
match /posts/{postId} { allow read: if true; allow write: if request.auth != null; }
AOnly authenticated users can read and write posts, so no risk exists.
BAnyone can read all posts, but only authenticated users can write, which may allow unauthorized edits.
CNo one can read posts because read is set to true incorrectly.
DThe rule syntax is invalid and will cause a deployment error.
Attempts:
2 left
💡 Hint
Check who can read and who can write with these conditions.
service_behavior
expert
3:00remaining
Predicting Firebase Rule Evaluation Outcome
Given the following Firebase rule snippet:

match /documents/{docId} { allow read: if request.time < timestamp.date(2023, 1, 1); allow write: if request.auth.uid == resource.data.ownerId; }

If a user tries to read a document on February 1, 2023, what will happen?
Firebase
match /documents/{docId} { allow read: if request.time < timestamp.date(2023, 1, 1); allow write: if request.auth.uid == resource.data.ownerId; }
AThe write request will be allowed if the user is the owner, regardless of the date.
BThe read request will be allowed because the user is authenticated.
CThe read request will cause a syntax error due to incorrect timestamp usage.
DThe read request will be denied because the current time is after January 1, 2023.
Attempts:
2 left
💡 Hint
Focus on the read condition and the date comparison.