🔥

firebase

آمن

建立安全的 Firebase 應用程式

Firebase 簡化了後端開發,但安全規則和資料模型需要專業知識才能避免資料外洩和成本超支。此技能提供 Firebase 最佳實踐的專業指導。

يدعم: Claude Codex Code(CC)
📊 70 كافٍ
1

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

2

رفع في Claude

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

3

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

اختبرها

استخدام "firebase". Generate security rules for a 'tasks' collection where team members can read all tasks but only edit their own

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

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". How should I model a chat application with rooms and messages in Firestore?

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

Recommended structure:
- rooms/{roomId}: { name, createdAt, memberIds[] }
- rooms/{roomId}/messages/{messageId}: { text, senderId, sentAt }

Key decisions:
1. Subcollection for messages keeps room documents small
2. Denormalize memberIds for permission checks
3. Use sentAt for ordering, not document IDs

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

آمن
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
المحتوى
31
المجتمع
95
الأمان
91
الامتثال للمواصفات

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

保護新的 Firestore 資料庫

為使用者擁有的資料集合產生可立即部署的安全規則,包含正確的讀取/寫入權限

建立社交應用程式資料模型

為具有貼文、留言和按讚功能的動態牆設計 Firestore 集合和查詢

設定本機開發環境

設定 Firebase Emulators 以測試 Auth、Firestore 和 Functions,無需部署到正式環境

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

基本安全規則
產生 Firestore 安全規則,針對名為 'users' 的集合,讓使用者只能讀取和寫入自己的文件
資料模型設計
為部落格設計 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