如何解决NodeJs+Express+Mongo:清理时事通讯电子邮件输入和 mongo
我有一个用户在我的“POST”HTTP 方法中输入了他的电子邮件。 我不检查电子邮件中的格式,而是直接向其发送加密链接。 如果用户点击链接,我会将他添加到我的 mongo 数据库中。
我的设置安全吗?
//User provide his email. No check format,I just send mail so it must be valid.
app.use(express.urlencoded({ extended: true }));
const { body,validationResult } = require('express-validator');
app.post('/subscribetonewsletter/',function (req,res) {
body('mail','Empty mail').trim().isLength({ min: 1 }).escape();
let mail = req.body.mail;
let linkToClick = CryptoJS.AES.encrypt(mail);
SendMail(linkToClick).catch(console.error); // Send a mail with an encrypted link that will be decrypted
res.render('pages/subscribe',{})
});
//Here I decrypt link and if it's valid I add it on my mongo db database.
app.get('/mailsub/:data',res) {
var decryptedData = CryptoJS.AES.decrypt(req.params.data);
if (decryptedData) {
res.render('pages/subscribedsuccess',{});
mongoClient.connect(serverUrl,{ useUnifiedTopology: true },function (err,client) {
if (err) throw err;
var db = client.db(useDB);
db.collection("mailing").updateOne({},{ $push: { mailinglist:decryptedData } });
});
}
});
// HTML file
<form action="/subscribetonewsletter/" method="post">
<input type="text" name="mail" placeholder="example@domain.com" id="inputMailHere">
<button type="submit" value="login" class="button" id="submitMailForm">Subscribe it !</button>
</form>
一切正常,我只是想知道我是否需要对其进行更多的安全保护。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。