drxt70655 2012-10-17 10:37
浏览 30
已采纳

让用户通过正则表达式查询是一个好主意吗? [重复]

Possible Duplicate:
Sanitization of User-Supplied Regular Expressions in PHP

Let's say you want to let users search for something and your search function has the ability to accept regular expressions.

Is it OK to let site users to search by regexes that they post? From a user's point of view, I'd love a site which would let me do that :D

Is there any security risk involved? How can I sanitize a regex?

  • 写回答

3条回答 默认 最新

  • doulao2128 2012-10-17 10:41
    关注

    The main risk is that the regular expression is very complex and will run for ages or reach the recursion limit of the engine. See this article. Other risks may occur if you let your users user regex replacement in the wrong places, because that introduces the risk of code injection. But matching itself cannot really do any other harm than DoSing your server.

    There has been a question recently on how to recognize these dangerous regexes and the consensus was that it is not generally possible. See the question.

    You are probably best off by restricting the time your regex search can take and abort it if it takes too long.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里