用户输入的正则表达式安全吗?

发布于 2024-07-20 12:03:03 字数 178 浏览 6 评论 0原文

我正在开发一个需要接受用户的正则表达式的应用程序,为此我使用以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一江春梦 2024-07-27 12:03:03

如果正则表达式的语法无效,您可能会收到错误;或者如果在某些特定字符串上测试所谓的病态正则表达式,则在处理时可能会消耗指数级的时间和空间。

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.

握住你手 2024-07-27 12:03:03

用户输入总是邪恶的。 “安全”是什么意思。 它是否包含会使您的代码抛出异常或以其他方式失败的错误? 是的,当然可以,所以您当然应该为此做好准备。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文