-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
39 lines (34 loc) · 1.4 KB
/
Copy pathfirestore.rules
File metadata and controls
39 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isOwner(userId) {
return request.auth != null && request.auth.uid == userId;
}
function isValidPromptRun() {
let data = request.resource.data;
return data.rawPrompt is string && data.rawPrompt.size() < 10000
&& data.targetModel is string && data.targetModel.size() < 100
&& data.thoughts is string && data.thoughts.size() < 50000
&& data.optimizedPrompt is string && data.optimizedPrompt.size() < 50000
&& data.rationale is string && data.rationale.size() < 20000;
}
match /users/{userId} {
// The user document itself (if any)
allow read: if isOwner(userId);
match /history/{docId} {
allow read, delete: if isOwner(userId);
allow create: if isOwner(userId)
&& isValidPromptRun()
&& request.resource.data.createdAt == request.time;
allow update: if isOwner(userId)
&& isValidPromptRun()
&& request.resource.data.createdAt == resource.data.createdAt;
}
// Protect rate limit documents from client tampering
match /rate_limit/{docId} {
allow read: if isOwner(userId);
allow write: if false; // Only accessible via Admin SDK in edge function
}
}
}
}