🔥

firebase

آمن

构建安全的 Firebase 应用

Firebase 简化了后端开发,但安全规则和数据建模需要专业知识以避免安全漏洞和成本超支。此技能提供 Firebase 最佳实践的专业指导。

يدعم: Claude Codex Code(CC)
🥉 73 برونزي
1

تنزيل ZIP المهارة

2

رفع في Claude

اذهب إلى Settings → Capabilities → Skills → Upload skill

3

فعّل وابدأ الاستخدام

اختبرها

استخدام "firebase". 为 'tasks' 集合生成安全规则,团队成员可以读取所有任务但只能编辑自己的任务

النتيجة المتوقعة:

rules version 2;

service cloud.firestore {
match /databases/{database}/documents {
match /tasks/{taskId} {
allow read: if request.auth != null;
allow write: if request.auth.uid == resource.data.ownerId;
}
}
}

استخدام "firebase". 如何在 Firestore 中为包含聊天室和消息的聊天应用建模?

النتيجة المتوقعة:

推荐结构:
- rooms/{roomId}: { name, createdAt, memberIds[] }
- rooms/{roomId}/messages/{messageId}: { text, senderId, sentAt }

关键决策:
1. 消息使用子集合可保持聊天室文档较小
2. 去规范化 memberIds 以便权限检查
3. 使用 sentAt 进行排序,而不是使用文档 ID

التدقيق الأمني

آمن
v1 • 2/25/2026

Static analysis flagged external_commands and weak_crypto patterns, but manual review confirms these are false positives. The backtick syntax on line 57 is markdown code formatting, not shell execution. The cryptographic algorithm flags on lines 3, 15, 39, 45, 60 are triggered by generic words like 'security' and 'design', not actual weak crypto usage. This is a legitimate Firebase development skill with no security issues.

1
الملفات التي تم فحصها
61
الأسطر التي تم تحليلها
2
النتائج
1
إجمالي عمليات التدقيق
مشكلات متوسطة المخاطر (2)
False Positive: Shell Command Detection
Static scanner detected backtick syntax at SKILL.md:57 as Ruby/shell command execution. Manual review confirms these are markdown inline code formatting backticks (`nextjs-app-router`), not command execution.
False Positive: Weak Cryptographic Algorithm
Static scanner flagged 'weak cryptographic algorithm' at multiple lines. Manual review shows these are false positives triggered by generic words like 'security', 'design', and 'Firebase' - no actual cryptographic algorithms are present.
تم تدقيقه بواسطة: claude

درجة الجودة

38
الهندسة المعمارية
100
قابلية الصيانة
87
المحتوى
50
المجتمع
95
الأمان
91
الامتثال للمواصفات

ماذا يمكنك بناءه

保护新的 Firestore 数据库

为具有适当读写权限的用户数据集合生成生产就绪的安全规则

构建社交应用数据模型

为包含帖子、评论和点赞的社交信息流设计 Firestore 集合和查询

设置本地开发环境

配置 Firebase Emulators 以测试 Auth、Firestore 和 Functions,无需部署到生产环境

جرّب هذه الموجهات

基本安全规则
为名为 'users' 的集合生成 Firestore 安全规则,用户只能读取和写入自己的文档
数据模型设计
为包含帖子、评论和点赞的博客设计 Firestore 数据模型。展示集合结构和示例文档
Cloud Function 设置
编写一个 Firebase Cloud Function,当 Authentication 中创建新用户时触发,并在 Firestore 中创建默认个人资料文档
成本优化
审查此 Firestore 查询模式并建议优化以减少读取成本:collection('posts').where('author', '==', userId).get()

أفضل الممارسات

  • 始终围绕查询模式而不是关系来设计数据模型
  • 在将任何集合部署到生产环境之前先编写安全规则
  • 在所有开发和 CI 测试中使用 Firebase Emulators

تجنب

  • 跳过安全规则,仅依赖客户端验证
  • 像关系数据库一样对 Firestore 建模并进行深层嵌套
  • 在没有分页或限制的情况下将整个集合附加到监听器

الأسئلة المتكررة

Firestore 和 Realtime Database 有什么区别?
Firestore 更新且具备更好的查询和可扩展性。Realtime Database 在简单同步场景中更快。为大多数新项目选择 Firestore。
如何保护 Firebase functions 的安全?
使用 Firebase Authentication 验证调用者。验证所有输入数据。避免泄露服务账号凭据。仅在需要时使用 --public 标志部署。
我可以将 Firebase 与我自己的后端一起使用吗?
可以,在服务器端使用 Firebase Admin SDK 可绕过安全规则进行受信任的操作,同时为用户保留客户端规则。
如何防止 Firestore 成本失控?
为查询添加限制,明智地使用复合索引,设置计费警报,并定期监控使用仪表板。
什么是 Firebase Emulators?
模拟 Firestore、Auth、Cloud Functions 和其他服务的本地开发服务器。使用它们进行测试,无需产生成本或影响生产环境。
如何在 Firebase 中处理用户角色?
将角色存储在 Firestore 用户文档中,或在 ID 令牌中使用自定义声明。在客户端安全规则和 Cloud Functions 中都检查角色。

تفاصيل المطور

المؤلف

sickn33

الترخيص

MIT

مرجع

main

بنية الملفات

📄 SKILL.md