-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.rules.json
More file actions
50 lines (44 loc) · 1.82 KB
/
Copy pathdatabase.rules.json
File metadata and controls
50 lines (44 loc) · 1.82 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
{
"rules": {
"chats": {
"$roomId": {
// La lectura sigue siendo pública, arreglar esto requeriría cambios en la app.
// Es el siguiente paso de seguridad a futuro.
".read": "true",
// NO hay regla de escritura general aquí. Se define en cada hijo.
"lastActive": {
// Esta regla ya es buena, permite actualizar la marca de tiempo.
".write": "newData.val() == now"
},
"messages": {
// SIN ".write": true aquí.
"$messageId": {
// SOLO se permite ESCRIBIR si el mensaje NO existía antes.
// Esto previene que alguien modifique o borre mensajes.
".write": "!data.exists()",
// Tu validación actual, ¡que es muy buena!, se mantiene.
".validate": "newData.hasChildren(['text']) && newData.child('text').isString() && newData.child('text').val().length < 10000"
}
},
"presences": {
// SIN ".write": true aquí.
"$presenceId": {
// Se permite escribir en cada nodo de presencia individualmente.
// Esto previene que alguien borre el nodo "presences" completo.
".write": "true",
// Tu validación actual también es excelente.
".validate": "newData.hasChildren(['alias']) && newData.child('alias').isString() && newData.child('alias').val().length > 0 && newData.child('alias').val().length < 50"
}
},
"keyCheck": {
// Esta regla ya es perfecta, ¡no se toca!
".write": "!data.exists()",
".validate": "newData.isString()"
},
// MEJORA ADICIONAL: No se permite escribir ninguna otra propiedad
// en la raíz de la sala (ej: /chats/$roomId/basura).
"$other": { ".validate": false }
}
}
}
}