我有一个云函数,我希望只有当请求来自我的域时才会调用它。
export const createMatch = functionUS.https.onCall(async (data, context) => {
if (context.auth === null || context.auth?.uid == null || data?.userId !== context.auth?.uid)
throw new functions.https.HttpsError("unauthenticated", "not authenticated");
try {
const user = await admin.auth().getUser(context.auth.uid);
if (!user.displayName) throw new functions.https.HttpsError("failed-precondition", "username is missing");
data.username = user.displayName;
const matchRepo = new MatchRepository(new FirestoreMatchProvider("matches"));
const match = Match.fromMap(new Map<string, any>(Object.entries(data)));
if (!match.isValid()) throw new functions.https.HttpsError("failed-precondition", "match data is not valid");
await matchRepo.createMatch(match, context.auth.uid);
} catch (error) {
functions.logger.error(`handleMatchCreate: ${error}`);
}
});我注意到express有主机名选项,我可以从上下文中获取它,但这只是主机名的头。据我所知这可能是伪造的。有没有办法让我知道这些请求是否来自我的域名?
因为有人可以查看代码并获得我的firebase配置,然后为自己创建一个应用程序,该应用程序只在他想要的时候发送请求。这不是我想要的。
发布于 2021-04-19 15:14:46
它是HTTP协议的一部分,你不能改变它。简单地说,不要依赖于网络层(DNS和IP)。你不能再做更多了
https://stackoverflow.com/questions/67154465
复制相似问题