Firebase on Call 函数 htpps.oncall 不会向安全规则发送上下文信息



Firebase on call function(functions.https.onCall) 不会将上下文参数值发送到安全规则。这意味着,如果我们从 UI 调用 firebase on call 函数来更新 firestore db 的内容,我需要在该函数中进行所有安全检查并使用管理员 SDK 更新 firestore db。我无法使用 Firebase sdk 和 firestore 安全规则进行经过身份验证的更新。

export const registerOrganizationTest = functions.https.onCall(async (data, context) => {
try {   firebase.firestore().collection('Organizations').doc('counts').get()
await firebase.firestore().collection('Organizations').doc('counts').set(orgcounts, { merge: true })
await firebase.firestore().collection('Organizations').
doc((orgcounts.organizationCount).toString()).
set(organization, { merge: true })
}
catch (err) {
throw new functions.https.HttpsError("internal", err);
}
})

Firestore 会因违反安全规则而停止更新。但是,如果相同的语句从 UI 运行,则它们作为上下文参数传递给安全规则。

安全规则不适用于后端代码。 当您为后端组件调用云函数或其他一些使用 Admin SDK 或其他云 SDK 的后端代码时,来自该代码的所有访问都会完全绕过安全规则。 仅当直接从移动和Web客户端SDK(Android,iOS,Unity等)访问Firestore时,安全规则才适用。

最新更新