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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度