【问题标题】:Can not read property length when adding escape in Node.js在 Node.js 中添加转义时无法读取属性长度
【发布时间】:2019-03-16 08:18:53
【问题描述】:

报告错误:

1。说明:

var con = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "",
  database: "db"
});
con.connect(function(err) {
  if (err) throw err;
  console.log("Database Connected!");
});

当像这样添加转义时:

var sql =
  "SELECT * FROM tb WHERE col_1 = '"
  +con.escape(req.params.val_1)
  +"' AND col_2 = '"+con.escape(req.params.val_2)
  +"' "

2。问题:

调用result.length 时无法读取属性长度并且它退出。

这里面有什么幕后的东西吗?

【问题讨论】:

    标签: node.js sql-injection


    【解决方案1】:

    req.params 将得到结果:value BUT con.escape(req.params.val_1) ... get 'value' -> 所以会发生错误。替换'就可以了!

    【讨论】:

      猜你喜欢
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      相关资源
      最近更新 更多