作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个以 Firebase 作为后端的混合移动应用。我想让用户在墙上发布他们想要的任何消息而无需身份验证,但我担心垃圾邮件的可能性。我的意思是,如果用户不必经过身份验证就可以发帖,我的安全规则基本上是空的,任何获得端点的人都可以发布无限量的内容。而且我看不出我能做些什么来反对它。
所以我知道 anonymous auth ,但我不确定它是否真的解决了这个问题。端点保持打开状态,毕竟只是落后于调用方法之前的必要性。它增加了一点复杂性,但我认为不会太多。
我想知道是否有可能检查调用来源,以确保它来 self 的应用程序而不是其他任何东西。或者,如果您有其他想法使它更安全,我愿意接受一切。谢谢!
最佳答案
您可以使用 recaptcha 的组合来完成此操作在客户端和 firebase cloud functions在后端。
您将要添加到商店的消息连同验证码一起发送到云功能。在云函数中,我们首先验证验证码。如果这个没问题,我们将消息添加到商店。这是有效的,因为当通过云函数将项目添加到商店时,firebase 身份验证规则将被忽略。
这是一个示例云函数:
const functions = require('firebase-functions')
const admin = require('firebase-admin')
const rp = require('request-promise')
const cors = require('cors')({
origin: true,
});
admin.initializeApp();
exports.createUser = functions.https.onRequest(function (req, res) {
cors(req, res, () => {
// the body is a json of form {message: Message, captcha: string}
const body = req.body;
// here we verify whether the captcha is ok. We need a remote server for
// for this so you might need a paid plan
rp({
uri: 'https://recaptcha.google.com/recaptcha/api/siteverify',
method: 'POST',
formData: {
secret: '<SECRET>',
response: body.captcha
},
json: true
}).then(result => {
if (result.success) {
// the captcha is ok! we can now send the message to the store
admin.firestore()
.collection('messages')
.add(body.message)
.then(writeResult => {
res.json({result: `Message with ID: ${writeResult.id} added.`});
});
} else {
res.send({success: false, msg: "Recaptcha verification failed."})
}
}).catch(reason => {
res.send({success: false, msg: "Recaptcha request failed."})
})
});
})
还有更多信息:https://firebase.googleblog.com/2017/08/guard-your-web-content-from-abuse-with.html
关于火力地堡 : How to secure content sent without login?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39332976/
我是一名优秀的程序员,十分优秀!