用户输入的正则表达式安全吗?
我正在开发一个需要接受用户的正则表达式的应用程序,为此我使用以下代码:
Regex user_searchPattern = new Regex(this.userInput_regEx.Text);
这样做安全吗?
是否需要清理用户输入,如果需要,如何清理?
I'm working on an app that needs to accept a RegEx from the user, to do so I'm using the following code:
Regex user_searchPattern = new Regex(this.userInput_regEx.Text);
Is doing this safe?
Is there a need to sanitize the user input, and if so how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果正则表达式的语法无效,您可能会收到错误;或者如果在某些特定字符串上测试所谓的病态正则表达式,则在处理时可能会消耗指数级的时间和空间。
You might get an error if the regular expression has an invalid syntax or it might consume a exponential amount of time and space when processed if a so-called pathological regular expression is tested on some particular string.
用户输入总是邪恶的。 “安全”是什么意思。 它是否包含会使您的代码抛出异常或以其他方式失败的错误? 是的,当然可以,所以您当然应该为此做好准备。
User input is always evil. What do you mean with "safe". Can it contain errors that will make your code throw an exception or fail in some other way? Yes, it certainly can, so you should be prepared for that of course.