تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر "قواعد الأمان في Firebase" حماية قوية وقابلة للتخصيص بالكامل لبياناتك في
Cloud Firestore وRealtime Database وCloud Storage. يمكنك البدء بسهولة في استخدام Rules باتّباع الخطوات الواردة في هذا الدليل، ما يتيح لك تأمين بياناتك وحماية تطبيقك من المستخدمين الضارين.
فهم لغة "قواعد الأمان في Firebase"
قبل البدء في كتابة القواعد، من المفيد تخصيص بعض الوقت لمراجعة لغة "قواعد الأمان في Firebase" الخاصة بمنتجات Firebase التي تستخدمها.
تستفيد Realtime Database من بنية JSON وبنية مشابهة لبنية JavaScript في Rules.
إذا لم يسبق لك ذلك، أضِف Firebase Authentication إلى تطبيقك.
يتوافق Firebase Authentication مع العديد من طرق المصادقة الشائعة ويتكامل مع
قواعد أمان Firebase لتوفير إمكانات تحقّق شاملة.
يمكنك إعداد معلومات مصادقة إضافية ومخصّصة لتطبيقك.
قد تؤثر طريقة تنظيم بياناتك في طريقة تنظيم قواعدك وتنفيذها. أثناء تحديد هياكل البيانات، ضع في اعتبارك الآثار التي قد تترتب عليها في ما يتعلق ببنية Rules.
على سبيل المثال، في Realtime Database، قد تحتاج إلى تضمين حقل يشير إلى دور محدّد لكل مستخدم. بعد ذلك، يمكن أن تقرأ قواعدك هذا الحقل وتستخدمه لمنح إذن الوصول المستند إلى الأدوار.
أثناء تحديد بنية البيانات والقواعد، ضَع في اعتبارك طريقة تطبيق القواعد أو عدم تطبيقها بشكل متسلسل، وذلك حسب منتجك. في Realtime Database،
تعمل القواعد من الأعلى إلى الأسفل، حيث تلغي القواعد الأقل عمقًا القواعد الأكثر عمقًا. إذا منحت قاعدة أذونات القراءة أو الكتابة في مسار معيّن، فإنّها تمنح أيضًا إذن الوصول إلى جميع العُقد الفرعية ضمن هذا المسار. في المقابل، مع Cloud Firestore وCloud Storage، لا تنطبق القواعد إلا على مستويات محدّدة من التدرّج الهرمي للبيانات، وتكتب قواعد صريحة للتحكّم في الوصول إلى مستويات مختلفة.
الوصول إلى قواعدك
للاطّلاع على Rules الحالي، استخدِم إما واجهة سطر الأوامر Firebase أو وحدة تحكّم Firebase. احرص على تعديل قواعدك باستخدام الطريقة نفسها بشكل متّسق لتجنُّب استبدال التعديلات عن طريق الخطأ. إذا لم تكن متأكدًا مما إذا كانت القواعد المحدّدة محليًا تعكس آخر التحديثات، تعرض وحدة تحكّم Firebase دائمًا أحدث إصدار تم نشره من "قواعد أمان Firebase".
للوصول إلى قواعدك من وحدة تحكّم Firebase، اختَر مشروعك، ثم انقر على Realtime Database في لوحة التنقّل اليمنى. انقر على Rules بعد الانتقال إلى قاعدة البيانات أو حزمة التخزين الصحيحة.
للوصول إلى قواعدك من واجهة سطر الأوامر Firebase، انتقِل إلى ملف القواعد المذكور في ملف firebase.json.
كتابة قواعد أساسية
أثناء تطوير تطبيقك وفهم Rules، جرِّب تنفيذ Rules لتلبية بعض حالات الاستخدام الأساسية، بما في ذلك ما يلي:
مالك المحتوى فقط: يمكنك حظر وصول المستخدمين إلى المحتوى.
الوصول المختلط: حظر إذن الكتابة حسب المستخدم، ولكن السماح بالوصول العام للقراءة
الوصول المستند إلى السمات: يمكنك حظر الوصول إلى مجموعة أو نوع من المستخدمين.
اختبار القواعد
إذا كنت بصدد إعداد "قواعد الأمان في Firebase" في Firebaseوحدة التحكّم، يمكنك استخدام Firebase Rules Playground للتحقّق بسرعة من السلوك. ومع ذلك، ننصحك بإجراء اختبار أكثر شمولاً باستخدام
Local Emulator Suite قبل نشر تغييراتك في مرحلة الإنتاج.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["\u003cbr /\u003e\n\nFirebase Security Rules provide robust, completely customizable protection for your data in\nCloud Firestore, Realtime Database, and Cloud Storage. You can easily get\nstarted with Rules following the steps in this guide, securing your\ndata and protecting your app from malicious users.\n\nUnderstand the Firebase Security Rules language\n\nBefore you start writing rules, it's worthwhile to take some time to review\nthe specific Firebase Security Rules language for the Firebase products you're using.\nRealtime Database leverages a JavaScript-like syntax and JSON structure for its\nRules.\n\nStart by learning the [core syntax of the Firebase Security Rules language](/docs/database/security/core-syntax).\n\nSet up Authentication\n\nIf you haven't done it already, add [Firebase Authentication to your app](/docs/auth).\nFirebase Authentication supports many common authentication methods and integrates with\nFirebase Security Rules to provide comprehensive verification capabilities.\n\nYou can set up additional, custom authentication information for your app.\n\nLearn more about [Firebase Security Rules and Firebase Authentication](/docs/rules/rules-and-auth).\n\nDefine your data and rules structures\n\nDefine data for security\n\nThe way you structure your data might affect the way you structure and\nimplement your rules. As you define your data structures, consider the\nimplications they might have on your Rules structure.\n\nFor example, in Realtime Database, you might want to include\na field that denotes a specific role for each user. Then, your rules can read\nthat field and use it to grant role-based access.\n\nAs you define your data and rules architectures, keep in mind the way that\nrules cascade or don't cascade, depending on your product. With Realtime Database,\nrules work from top-down, with shallower rules overriding deeper rules. If a\nrule grants read or write permissions at a particular path, then it also grants\naccess to all child nodes under it. In contrast, with Cloud Firestore and\nCloud Storage, rules apply only at specified levels of the data hierarchy,\nand you write explicit rules to control access to different levels.\n\nAccess your rules\n\nTo view your existing Rules, use either the Firebase CLI or the\nFirebase console. Make sure you edit your rules using the same method,\nconsistently, to avoid mistakenly overwriting updates. If you're not sure\nwhether your locally defined rules reflect the most recent updates, the Firebase\nconsole always shows the most recently deployed version of your Firebase Security Rules.\n\nTo access your rules from the [Firebase console](//console.firebase.google.com/), select your\nproject, then in the left-hand navigation panel, click\n**Realtime Database** . Click **Rules** once you're\nin the correct database or storage bucket.\n\nTo access your rules from the Firebase CLI, go to the\nrules file noted in your [firebase.json file](/docs/cli#the_firebasejson_file).\n\nWrite basic rules\n\nAs you're developing your app and understanding Rules, try\nimplementing Rules to address a few [basic use cases](/docs/rules/basics),\nincluding the following:\n\n- **Content-owner only:** Restrict access to content by user.\n- **Mixed access:** Restrict write access by user, but allow public read access.\n- **Attribute-based access:** Restrict access to a group or type of user.\n\nTest your rules\n\nIf you're setting up your Firebase Security Rules in the Firebase console, you can use\nthe [Firebase Rules Playground](/docs/rules/simulator) to quickly validate\nbehavior. However, we recommend more thorough testing with the\n[Local Emulator Suite](/docs/rules/emulator-setup) before you deploy your\nchanges to production.\n\nDeploy rules\n\nUse the Firebase console or the Firebase CLI to deploy your rules\nto production. Follow the steps outlined in\n[Manage and deploy Firebase Security Rules](/docs/rules/manage-deploy)."]]