-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
74 lines (64 loc) · 2.94 KB
/
Copy pathfirestore.rules
File metadata and controls
74 lines (64 loc) · 2.94 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ============================================================
// USERS COLLECTION
// Path: /users/{uid}
// ============================================================
match /users/{uid} {
// Users can only read/write their own document
allow read, write: if request.auth != null && request.auth.uid == uid;
// ============================================================
// TRIGGERS SUBCOLLECTION
// Path: /users/{uid}/triggers/{triggerId}
// ============================================================
match /triggers/{triggerId} {
// Users can only access their own triggers
allow read, write: if request.auth != null && request.auth.uid == uid;
// Validate trigger document structure on create/update
allow create: if request.auth != null
&& request.auth.uid == uid
&& request.resource.data.keys().hasAll(['nickname', 'nicknameNorm', 'webhookUrl', 'createdAt', 'updatedAt'])
&& request.resource.data.nickname is string
&& request.resource.data.nickname.size() > 0
&& request.resource.data.nickname.size() <= 100
&& request.resource.data.nicknameNorm is string
&& request.resource.data.webhookUrl is string
&& request.resource.data.webhookUrl.matches('^https://.*');
allow update: if request.auth != null
&& request.auth.uid == uid
&& request.resource.data.nickname is string
&& request.resource.data.nickname.size() > 0
&& request.resource.data.nickname.size() <= 100
&& request.resource.data.webhookUrl is string
&& request.resource.data.webhookUrl.matches('^https://.*');
allow delete: if request.auth != null && request.auth.uid == uid;
}
// ============================================================
// RUNS SUBCOLLECTION (audit log)
// Path: /users/{uid}/runs/{runId}
// ============================================================
match /runs/{runId} {
// Users can read their own run history
allow read: if request.auth != null && request.auth.uid == uid;
// Only backend (via Admin SDK) can write runs
// Client-side writes are denied
allow write: if false;
}
}
// ============================================================
// RATE LIMITS COLLECTION (backend-managed)
// Path: /rateLimits/{key}
// ============================================================
match /rateLimits/{key} {
// Only backend (via Admin SDK) can access rate limits
allow read, write: if false;
}
// ============================================================
// DEFAULT: Deny everything else
// ============================================================
match /{document=**} {
allow read, write: if false;
}
}
}