【问题标题】:Is a python appengine app with no firestore security rules insecure?没有firestore安全规则的python appengine应用程序不安全吗?
【发布时间】: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


    【解决方案1】:

    安全规则仅用于控制来自网络和移动客户端的访问。访问 Firestore 的后端 SDK 实际上完全绕过了安全规则,因此编写任何规则根本不会改变后端代码的行为。

    如果您只是不直接从网络或移动设备访问数据库,那么您可以设置安全规则以拒绝所有访问,这很好。

    match /{document=**} {
      allow read, write: if false;
    }
    

    【讨论】:

    • 感谢您的回答。那我就用这个。但为了澄清一下,如果没有定义安全规则,我假设 firestore 数据库是完全开放的并且容易受到攻击?
    • 不可能没有规则。您至少需要一条规则才能生效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 2018-10-19
    • 2019-07-05
    • 2018-03-17
    • 2020-06-19
    • 2021-04-09
    • 1970-01-01
    相关资源
    最近更新 更多