Nguyên tắc bảo mật chung cho nhiều môi trường quy trình phát triển
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này mô tả các phương pháp hay nhất và quan trọng nhất để bảo mật trên
nhưng hãy xem xét
Danh sách kiểm tra bảo mật để biết thêm chi tiết và
hướng dẫn kỹ lưỡng về bảo mật và Firebase.
Bảo mật cho môi trường trước khi phát hành công khai
Một lợi ích của việc phân tách các môi trường trong nhiều dự án Firebase là
đối tượng xấu có thể truy cập vào môi trường trước khi sản xuất sẽ không thể
truy cập vào dữ liệu người dùng thực. Sau đây là các biện pháp bảo mật quan trọng nhất mà bạn cần thực hiện
đối với môi trường trước khi phát hành công khai:
Hạn chế quyền truy cập vào môi trường thử nghiệm. Đối với ứng dụng dành cho thiết bị di động, hãy sử dụng
App Distribution (hoặc tên tương tự) để phân phối
một ứng dụng cho một nhóm người cụ thể. Khó hạn chế các ứng dụng web hơn; hãy cân nhắc thiết lập một hàm chặn cho các môi trường thử nghiệm trước khi phát hành để hạn chế quyền truy cập của những người dùng có địa chỉ email dành riêng cho miền của bạn. Hoặc, nếu bạn đang sử dụng
Firebase Hosting thân mến, hãy thiết lập quy trình công việc trước khi sản xuất
URL xem trước tạm thời.
Khi một môi trường không cần được duy trì và chỉ có một môi trường sử dụng
người (hoặc trong trường hợp thử nghiệm là bằng một máy), hãy sử dụng
Firebase Local Emulator Suite. Những trình mô phỏng này an toàn hơn
và nhanh hơn vì chúng có thể hoạt động hoàn toàn trên máy chủ cục bộ thay vì sử dụng đám mây
của chúng tôi.
Đảm bảo rằng bạn đã thiết lập Firebase Security Rules trong môi trường trước khi phát hành, giống như trong môi trường phát hành chính thức. Nhìn chung, Rules phải giống nhau trên các môi trường, với lưu ý là vì các quy tắc thay đổi theo mã, nên có thể có các quy tắc trước đó trong quy trình chưa tồn tại trong môi trường phát hành chính thức.
Bảo mật cho môi trường thực tế
Dữ liệu phát hành chính thức luôn là mục tiêu, ngay cả khi ứng dụng không rõ ràng. Đang làm theo
các nguyên tắc này không ngăn hành vi xấu xa lấy được dữ liệu của bạn,
nhưng điều này khiến việc này khó khăn hơn:
Bật và thực thi App Check cho tất cả sản phẩm
mà bạn đang sử dụng phần hỗ trợ đó. App Check đảm bảo rằng các yêu cầu đến
các dịch vụ phụ trợ đến từ ứng dụng chính thống của bạn. Để sử dụng công cụ này, bạn
cần đăng ký từng phiên bản ứng dụng với App Check. Cách này dễ hơn
thiết lập trước khi bạn có người dùng, vì vậy, hãy thiết lập càng sớm càng tốt.
Viết Firebase Security Rules mạnh mẽ. Realtime Database, Cloud Firestore và Cloud Storage đều dựa vào Rules do nhà phát triển định cấu hình để thực thi những người có thể và không thể truy cập vào dữ liệu. Cần phải
bảo mật mà bạn viết Rules tốt. Nếu không biết cách làm,
hãy bắt đầu từ lớp học lập trình này.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[],[],null,["This page describes the most important best practices for security across\nenvironments, but review the\n[*Security checklist*](/support/guides/security-checklist) for more detailed and\nthorough guidance about security and Firebase.\n\nSecurity for pre-production environments\n\nOne benefit of separating environments in different Firebase projects is that a\nmalicious actor who is able to access your pre-prod environments won't be able\naccess real user data. Here are the most important security precautions to take\nfor pre-production environments:\n\n- Limit access to pre-prod environments. For mobile apps, use\n [App Distribution](/docs/app-distribution) (or something similar) to distribute\n an app to a specific set of people. Web applications are harder to restrict;\n consider setting up a\n [blocking function](https://cloud.google.com/identity-platform/docs/blocking-functions)\n for the pre-prod environments that restricts access to users with email\n addresses that are specific to your domain. Or, if you're using\n Firebase Hosting, set up your pre-prod workflows to use\n [temporary preview URLs](/docs/hosting/test-preview-deploy).\n\n- When an environment doesn't need to be persisted and is only being used by one\n person (or in the case of tests, by one machine) use the\n [Firebase Local Emulator Suite](/docs/emulator-suite). These emulators are safer\n and faster because they can work entirely on localhost instead of using cloud\n resources.\n\n- Make sure that you have [Firebase Security Rules](/docs/rules) set up in pre-production\n environments, just as you do in prod. In general, the Rules should\n be the same across environments, with the caveat that since rules change with\n code, there may be rules earlier in the pipeline that don't yet exist in\n production.\n\nSecurity for production environments\n\nProduction data is always a target, even if the app is obscure. Following these\nguidelines doesn't make it impossible for a malicious actor to get your data,\nbut it makes it more difficult:\n\n- Enable and enforce [App Check](/docs/app-check) for all the products\n you're using that support it. App Check makes sure that requests to your\n backend services are coming from your genuine apps. In order to use it, you\n need to register each version of your app with App Check. It's easier to\n set up before you have users, so set it up as soon as possible.\n\n- Write robust [Firebase Security Rules](/docs/rules). Realtime Database, Cloud Firestore, and\n Cloud Storage all rely on developer-configured Rules to\n enforce who should and shouldn't be able to access data. It's essential to\n your security that you write good Rules. If you're not sure how,\n start with this [codelab](/codelabs/firebase-rules).\n\n- Review the [*Security checklist*](/support/guides/security-checklist) for more\n recommendations about security for production environments.\n\nNext steps\n\n- Review the [Firebase launch checklist](/support/guides/launch-checklist)."]]