【发布时间】:2020-09-17 00:21:25
【问题描述】:
我有一个用 Python 3 编写的 Google App Engine 标准环境应用程序,使用 Flask 作为框架,使用原生模式的 firestore 作为数据库。所有数据库调用都在 App Engine 代码中完成,隐藏在 Flask 端点/视图/处理程序后面。客户端浏览器不执行任何直接调用 firestore 数据库的 javascript。客户端javascript基本上是用于化妆品的“愚蠢”代码。客户端 JavaScript 执行“任何操作”的唯一时间是用户创建新帐户或使用 firebase auth ui 登录时。
话虽如此,我注意到一些在线资源提到保护 firestore 数据库是绝对必要的,因为安全规则不允许的任何事情基本上都是允许的(即 firestore 数据库默认情况下是不安全的),但是,我怀疑这仅适用于具有胖客户端的应用程序(即客户端代码或 javascript 负责执行查询和写入 firestore 的繁重工作)。
所以我的问题是,是否只需要为移动/Web 客户端编写这些安全规则,而不是仅由服务器端代码访问的 Firestore 数据库? 或者是否所有 Firestore 项目都需要定义这些安全规则安全规则?如果是这样,那么我将不胜感激任何关于在哪里可以找到合理的默认安全规则以开始保护我的 firestore 数据库的指针。
我附上了我的烧瓶 main.py 文件的漫画以供参考。
# main.py
from google.cloud import firestore
from mylibrary import function_that_fetches_user_data
from mylibrary2 import function_that_writes_user_content
def validate_cookie(protected_function):
def wrapper(*args, **kwargs):
# handle cookie validation
# run protected function
return wrapper
# The dashboard is meant to display user data and user content to the user.
# It is not meant to be seen by other users.
@app.route("/user_dashboard")
@validate_cookie
def dashboard():
user_id = get_uid_from_cookie
firestore_client = firestore.Client()
user_data = function_that_fetches_user_data(user_id, firestore_client)
return render_template('dashboard.html', user_data)
# The write function creates user content that should only be accessible to the author
# and the system/app.
@app.route("/write_user_content")
@validate_cookie
def write_user_content():
user_id = get_uid_from_cookie
firestore_client = firestore.Client()
result = function_that_writes_user_content(user_id, firestore_client)
return render_template('success.html', result)
【问题讨论】:
标签: python google-app-engine flask google-cloud-firestore firebase-security