我正在网上销售一些类(class),因此对于付款购物车,我实现了一种通过 URL 中的查询从 firestore 获取类(class)数据的方法,例如:localhost:5000/?product=course1
.
所以,我想知道它在注入(inject)或其他漏洞方面有多安全
我实现了简单的验证。但没什么大不了的。
这是产品发布请求:
router.post("/courses", (req, res) => {
const product = req.body.product;
res.redirect("/payment?product=" + product);
});
这是付款页面:
router.get("/payment", async (req, res) => {
console.log(req.query.product);
const snapshot = await db.collection("products").get();
const products = await snapshot.docs.map(doc => {
return {
name: doc.id,
price: doc.data().price
};
});
thisProduct = products.find(product => {
return req.query.product === product.name;
});
console.log(thisProduct);
if (typeof thisProduct == "undefined") {
return res.send("product not found");
}
res.render("payment", {
key: "pk_test_fVJwSNZpMoCwrF7Zs48PsLR100zpmBhXrc",
user: true,
title: "Pay for a course",
product: {
name: thisProduct.name,
price: thisProduct.price
}
});
});
如果存在任何漏洞,请告诉我以及如何修复它们。 如果您没有发现任何漏洞,请发表评论。 谢谢!
最佳答案
我在您展示的代码中没有发现任何漏洞。一般来说,为了避免任何类型的注入(inject),您应该正确验证所有输入。 IE。如果您希望产品
是一个数字,您应该检查它是否是一个数字。此外,避免 SQL 注入(inject)的一般做法是不对 SQL 查询使用字符串插值(而且您也不会这样做👍),而是使用准备好的语句或/和 ORM。
因此,在采取一切预防措施的情况下,在 URL 查询中发送参数与发送任何其他类型的参数一样安全。
关于javascript - 在 url 中传递查询的安全性如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57236806/