简体   繁体   English

某些带有括号的字符串会导致Ajax POST操作失败,并显示403错误(禁止)

[英]Certain strings with parenthesis cause Ajax POST operation to fail with 403 error (forbidden)

When attempting to add an entry to a database via a form submission using Ajax, certain strings containing parenthesis will cause the POST operation to fail, but not in a consistent way. 当尝试使用Ajax通过表单提交将条目添加到数据库时,某些包含括号的字符串将导致POST操作失败,但不会以一致的方式失败。

The relevant POST operation looks like this: 相关的POST操作如下所示:

$.ajax(
{
  type: "POST",
  url: "SubmitAnswer.php",
  data: datastring,
  dataType: "json",
  cache: false,
  success: function(data)
  {
    ...
  }
}

The datastring contains a bunch of stuff including a string containing a mathematical expression. 数据datastring包含一堆东西,其中包括一个包含数学表达式的字符串。 If that string contains parenthesis, in certain very specific cases, it will cause the POST operation to fail with a 403 error when the Submit button is clicked. 如果该字符串包含括号,则在某些特定情况下,如果单击“提交”按钮,它将导致POST操作失败并显示403错误。

Here are some examples of mathematical expression strings that cause a problem: 这是引起问题的数学表达式字符串的一些示例:

(A-B)*C
(A*B)*(C*D)

Here are some examples of mathematical expression strings that do NOT cause a problem: 以下是一些不会引起问题的数学表达式字符串的示例:

(A+B)*C
A*(B-C)
(A*B)+(C*D)

It's almost as though certain permutations trip some kind of "protection" flag preventing them from being posted to the database? 好像某些排列跳出某种“保护”标志阻止它们被发布到数据库一样? Or some kind of bizarre parsing error? 还是某种奇怪的解析错误?

Doesn't look like you are correctly encoding the keys and / or values in datastring for use in an application/x-www-form-urlencoded request payload. 看起来您没有正确编码数据datastring的键和/或值,以便在application/x-www-form-urlencoded请求有效负载中使用。

My advice, let jQuery do the encoding by passing an object, eg 我的建议是,让jQuery通过传递一个对象来进行编码,例如

$.ajax({
  method: 'POST',
  url: 'SubmitAnswer.php',
  dataType: 'json',
  data: {
    edition_id: edition_id,
    nickname: nickname,
    answer: answer,
    email_address: email_address
  }
})

Ok, so following Phil's advice, I checked the server logs to get more information on the 403 error those very specific strings were causing and the problem has to do with those strings being "seen" as SQL injection attacks by a security mechanism on the server. 好的,因此按照Phil的建议,我检查了服务器日志以获取有关那些非常具体的字符串所引起的403错误的更多信息,并且问题与服务器上的安全机制将这些字符串“视为” SQL注入攻击有关。 I'll post a new question on how that can be addressed (apparently there is an exception list that you can configure) as that is a very different question than the original. 我将发布一个有关如何解决该问题的新问题(显然,您可以配置一个例外列表),因为这与原始问题完全不同。

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

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