قوانین امنیتی Firebase برای ذخیره سازی ابری را بدانید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
به طور سنتی، امنیت یکی از پیچیده ترین بخش های توسعه اپلیکیشن بوده است. در اکثر برنامهها، توسعهدهندگان باید سروری بسازند و اجرا کنند که احراز هویت (چه کسی کاربر است) و مجوز (آنچه کاربر میتواند انجام دهد) را مدیریت میکند. تنظیم احراز هویت و مجوز دشوار است، درست کردن آن دشوارتر است و برای موفقیت محصول شما حیاتی است.
همانند روشی که Firebase Authentication احراز هویت کاربران را برای شما آسان میکند، Firebase Security Rules برای Cloud Storage اجازه دادن به کاربران و تأیید درخواستها را برای شما آسان میکند. Cloud Storage Security Rules با اجازه دادن به شما برای تعیین مجوزهای مبتنی بر مسیر، پیچیدگی را برای شما مدیریت می کند. تنها در چند خط کد، میتوانید قوانین مجوزی بنویسید که درخواستهای Cloud Storage را به یک کاربر خاص محدود میکند یا اندازه آپلود را محدود میکند.
دانستن اینکه کاربران شما چه کسانی هستند بخش مهمی از ساخت یک برنامه کاربردی است، و Firebase Authentication یک راه حل آسان برای استفاده، ایمن و تنها در سمت مشتری برای احراز هویت ارائه می دهد. Firebase Security Rules برای Cloud Storage برای امنیت مبتنی بر کاربر با Firebase Authentication مرتبط است. هنگامی که یک کاربر با Firebase Authentication احراز هویت می شود، متغیر request.auth در Cloud Storage Security Rules به یک شی تبدیل می شود که شامل شناسه منحصر به فرد کاربر ( request.auth.uid ) و سایر اطلاعات کاربر در توکن ( request.auth.token ) است. هنگامی که کاربر احراز هویت نشده است، request.authnull است. این به شما این امکان را میدهد تا دسترسی به دادهها را بهطور ایمن بر اساس هر کاربر کنترل کنید. در بخش احراز هویت می توانید اطلاعات بیشتری کسب کنید.
مجوز
شناسایی کاربر شما تنها بخشی از امنیت است. هنگامی که آنها را شناختید، به راهی برای کنترل دسترسی آنها به فایلها در Cloud Storage نیاز دارید.
Cloud Storage به شما این امکان را می دهد که قوانین مجوز برای هر فایل و مسیر را مشخص کنید که در سرورهای ما وجود دارد و دسترسی به فایل های برنامه خود را تعیین کنید. به عنوان مثال، Cloud Storage Security Rules به Firebase Authentication برای انجام هرگونه عملیات read یا write روی همه فایلها نیاز دارند:
با انتخاب یک برنامه Firebase در کنسول Firebase و مشاهده تب Rules در بخش Storage می توانید این قوانین را ویرایش کنید.
اعتبار سنجی داده ها
Firebase Security Rules برای Cloud Storage همچنین میتواند برای اعتبارسنجی دادهها، از جمله اعتبارسنجی نام فایل و مسیر و همچنین ویژگیهای فراداده فایل مانند contentType و size استفاده شود.
servicefirebase.storage{match/b/{bucket}/o{match/images/{imageId}{//Onlyallowuploadsofanyimagefilethat's less than 5MBallowwrite:ifrequest.resource.size < 5*1024*1024&&request.resource.contentType.matches('image/.*');}}}
مراحل بعدی
شروع به برنامه ریزی توسعه قوانین برای سطل های Cloud Storage خود کنید.
تاریخ آخرین بهروزرسانی 2025-08-22 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-08-22 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\nTraditionally, security has been one of the most complex parts of app\ndevelopment. In most applications, developers must build and run a server that\nhandles authentication (who a user is) and authorization (what a user can do).\nAuthentication and authorization are hard to set up, harder to get right, and\ncritical to the success of your product.\n\nSimilar to how Firebase Authentication makes it easy for you to authenticate your\nusers, Firebase Security Rules for Cloud Storage makes it easy for you to authorize users\nand validate requests. Cloud Storage Security Rules manage the complexity for you by\nallowing you to specify path based permissions. In just a few lines of code, you\ncan write authorization rules that restrict Cloud Storage requests to a\ncertain user or limit the size of an upload.\n| **Note:** If you use Google App Engine and have a default Cloud Storage bucket with a name format of `*.appspot.com`, you may need to consider [how your security rules impact access to App Engine files](/docs/storage/gcp-integration#security-rules-and-app-engine-files).\n\nThe Firebase Realtime Database has a similar feature, called\n[Firebase Realtime Database Security Rules](/docs/database/security)\n\nAuthentication\n\nKnowing who your users are is an important part of building an application, and\nFirebase Authentication provides an easy to use, secure, client side only solution\nto authentication. Firebase Security Rules for Cloud Storage ties in to Firebase Authentication\nfor user based security. When a user is authenticated with Firebase Authentication,\nthe `request.auth` variable in Cloud Storage Security Rules becomes an object that\ncontains the user's unique ID (`request.auth.uid`) and all other user\ninformation in the token (`request.auth.token`). When the user is not\nauthenticated, `request.auth` is `null`. This allows you to securely control\ndata access on a per-user basis. You can learn more in the\n[Authentication](/docs/storage/security/rules-conditions#authentication) section.\n\nAuthorization\n\nIdentifying your user is only part of security. Once you know who they are, you\nneed a way to control their access to files in Cloud Storage.\n\nCloud Storage lets you specify per file and per path authorization\nrules that live on our servers and determine access to the files in your app.\nFor example, the default Cloud Storage Security Rules require Firebase Authentication in\norder to perform any `read` or `write` operations on all files: \n\n```css+lasso\nservice firebase.storage {\n match /b/{bucket}/o {\n match /someFolder/{fileName} {\n allow read, write: if request.auth != null;\n }\n }\n}\n```\n\nYou can edit these rules by selecting a Firebase app in the [Firebase console](//console.firebase.google.com/)\nand viewing the `Rules` tab of the Storage section.\n\nData Validation\n\nFirebase Security Rules for Cloud Storage can also be used for data validation, including\nvalidating file name and path as well as file metadata properties such as\n`contentType` and `size`. \n\n```gdscript\nservice firebase.storage {\n match /b/{bucket}/o {\n match /images/{imageId} {\n // Only allow uploads of any image file that's less than 5MB\n allow write: if request.resource.size \u003c 5 * 1024 * 1024\n && request.resource.contentType.matches('image/.*');\n }\n }\n}\n```\n\nNext steps\n\n- [Get started](/docs/storage/security/get-started) planning rules development\n for your Cloud Storage buckets.\n\n- Learn more about [securing your data](/docs/storage/security/core-syntax)\n using security rules."]]