繁体   English   中英

在URL中传递查询的安全性如何

[英]how secure is passing query in url

我正在网上销售一些课程,因此对于付款车,我实现了一种方法,该方法通过以下网址中的查询从firestore中获取课程数据,例如: localhost:5000/?product=course1

所以,我想知道它在注入或其他漏洞方面有多安全

我实施了简单的验证。 但没什么大不了的。

这是产品发布请求:

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
    }
  });
});

请让我知道是否存在任何漏洞以及如何修复它们。 如果找不到任何漏洞,请发表评论。 谢谢!

您显示的代码中没有任何漏洞。 通常,为了避免进行任何注入,您应该正确地验证所有输入。 即,如果您希望product为数字,则应检查它是否为数字。 另外,避免SQL注入的一般做法是不对SQL查询使用字符串插值(并且不要使用),而应使用准备好的语句或/和ORM。

因此,在采取所有预防措施的同时,在URL查询中发送参数与发送任何其他种类的参数一样安全。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM