유연하고 확장 가능한 Firebase 보안 규칙을 사용하여 Cloud Firestore, Firebase Realtime Database, Cloud Storage의 데이터를 보호하세요.
Firebase Security Rules은 데이터를 악의적인 사용자로부터 보호하기 위해 제공됩니다. 간단하거나 복잡한 규칙을 작성하여 특정 앱에 필요한 세부 수준으로 앱의 데이터를 보호할 수 있습니다.
Firebase Security Rules은 확장 가능하고 유연한 구성 언어를 활용하여 사용자가 Realtime Database, Cloud Firestore, Cloud Storage에서 액세스할 수 있는 데이터를 정의합니다. Firebase Realtime Database Security Rules은 규칙 정의에서 JSON을 활용하는 반면 Cloud Firestore Security Rules 및 Cloud Storage용 Firebase Security Rules은 더 복잡한 규칙별 구조를 수용할 수 있도록 빌드된 고유 언어를 활용합니다.
앱에서 사용하는 특정 Firebase 제품의 Rules을 설정하는 방법과 Firebase 간에 Rules 동작이 어떻게 다른지에 대해 자세히 알아보세요.
앱의 구조 및 동작에 적합한 맞춤 규칙을 작성합니다. Rules은 자신의 데이터를 활용하여 액세스를 승인할 수 있는 언어를 사용합니다.
세부사항
규칙은 요구에 따라 넓히거나 좁힐 수 있습니다.
독립적인 보안
Rules이 앱 외부(Firebase Console 또는 Firebase CLI)에서 정의되기 때문에 클라이언트는 보안 적용에 책임이 없으며, 버그로 데이터가 손상되지 않고, 데이터가 항상 보호됩니다.
작동 방식
Firebase Security Rules은 패턴을 데이터베이스 경로와 대조한 후 커스텀 조건을 적용하여 해당 경로의 데이터에 액세스를 허용합니다. Firebase 제품의 모든 Rules에는 경로 일치 구성요소와 읽기 또는 쓰기 액세스를 허용하는 조건문이 있습니다. 앱에서 사용하는 각 Firebase 제품에 Rules을 정의해야 합니다.
Cloud Firestore 및 Cloud Storage의 경우 Rules은 다음 구문을 사용합니다.
service <<name>> { // Match the resource path. match <<path>> { // Allow the request if the following conditions are true. allow <<methods>> : if <<condition>> } }
Realtime Database의 경우 JSON 기반 Rules은 다음 구문을 사용합니다.
{ "rules": { "<<path>>": { // Allow the request if the condition for each method is true. ".read": <<condition>>, ".write": <<condition>> } } }
Rules은 AND 문이 아니라 OR 문으로 적용됩니다. 결과적으로 여러 규칙이 경로와 일치하고 일치 조건이 액세스를 허용하면 Rules은 해당 경로에 있는 데이터 액세스를 허용합니다. 따라서 광범위한 규칙이 데이터 액세스를 허용하는 경우 더 구체적인 규칙으로 제한할 수 없습니다. 하지만 Rules이 너무 겹치지 않도록 하면 이 문제를 피할 수 있습니다. Firebase Security Rules 플래그는 컴파일러 경고와 일치하는 경로에서 겹칩니다.
Firebase Security Rules은 Authentication을 활용하여 사용자 기반 권한을 부여할 수 있으며, 설정한 조건이 정말 기본적이거나 엄청나게 복잡해질 수 있습니다. Rules 작성을 시작하기 전에 Rules언어 및 동작에 대해 자세히 알아보세요.
[[["이해하기 쉬움","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-24(UTC)"],[],[],null,["Firebase Security Rules \nplat_ios plat_android plat_web plat_flutter plat_node \nUse our flexible, extensible Firebase Security Rules to\nsecure your data in Cloud Firestore, Firebase Realtime Database, and\nCloud Storage.\n\nFirebase Security Rules stand between your data and malicious users. You can write simple or\ncomplex rules that protect your app's data to the level of granularity that\nyour specific app requires.\n\nFirebase Security Rules leverage\nextensible, flexible configuration languages to define what data your users\ncan access for Realtime Database, Cloud Firestore, and Cloud Storage.\nFirebase Realtime Database Security Rules leverage JSON in rule definitions, while\nCloud Firestore Security Rules and Firebase Security Rules for Cloud Storage leverage a unique\nlanguage built to accommodate more complex rules-specific structures.\n\nLearn more about how to set up Rules for the specific Firebase products\nyou use in your app, and how Rules behavior differs across Firebase\nproducts.\n\n[Get started](/docs/rules/get-started)\n\nKey capabilities\n\n|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Flexibility | Write custom rules that make sense for your app's structure and behavior. Rules use languages that allow you to leverage your own data to authorize access. |\n| Granularity | Your rules can be as broad or as narrow as you need. |\n| Independent security | Because Rules are defined outside of your app (in the Firebase console or Firebase CLI), clients aren't responsible for enforcing security, bugs don't compromise data, and your data is always protected. |\n\nHow do they work?\n\nFirebase Security Rules work by matching a pattern against database paths, and then applying\ncustom conditions to allow access to data at those paths. All Rules\nacross Firebase products have a path-matching component and a conditional\nstatement allowing read or write access. You must define Rules for\neach Firebase product you use in your app.\n\nFor Cloud Firestore and Cloud Storage, Rules use the following\nsyntax: \n\n service \u003c\u003cname\u003e\u003e {\n // Match the resource path.\n match \u003c\u003cpath\u003e\u003e {\n // Allow the request if the following conditions are true.\n allow \u003c\u003cmethods\u003e\u003e : if \u003c\u003ccondition\u003e\u003e\n }\n }\n\nFor Realtime Database, JSON-based Rules use the following syntax: \n\n {\n \"rules\": {\n \"\u003c\u003cpath\u003e\u003e\": {\n // Allow the request if the condition for each method is true.\n \".read\": \u003c\u003ccondition\u003e\u003e,\n \".write\": \u003c\u003ccondition\u003e\u003e\n }\n }\n }\n\nRules are applied as `OR` statements, not `AND` statements.\nConsequently, if multiple rules match a path, and any of the matched\nconditions grants access, Rules grant access to the data at that\npath. Therefore, if a broad rule grants access to data, you can't restrict with\na more specific rule. You can, however, avoid this problem by making sure your\nRules don't overlap too much. Firebase Security Rules flag overlaps in your\nmatched paths as compiler warnings.\n\nFirebase Security Rules can also leverage Authentication to grant user-based permissions, and the\nconditions you set can be very basic or incredibly complex. Learn more\nabout Rules [language](/docs/rules/rules-language) and [behavior](/docs/rules/rules-behavior)\nbefore you start writing Rules.\n\nImplementation path\n\n|---|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Integrate the product SDKs | Set up [Cloud Firestore](/docs/firestore), [Cloud Storage](/docs/storage), or [Realtime Database](/docs/database) for your app. |\n| | Write your Firebase Security Rules | Learn more about [how Rules work](/docs/rules/rules-behavior) and [set up some basic Rules](/docs/rules/basics) |\n| | Test your Firebase Security Rules | Use the Realtime Database and Cloud Firestore emulators to test your app's behavior and validate your rules before you deploy them to production. |\n| | Deploy your Firebase Security Rules | Use the Firebase console or the Firebase CLI to deploy your rules to production. |\n\nNext steps\n\n- [Understand the Firebase Security Rules language](/docs/rules/rules-language).\n- Learn more about [how Firebase Security Rules work](/docs/rules/rules-behavior).\n- Explore the [common mistakes you should avoid](/docs/rules/insecure-rules)."]]