Is there any way to put malicious code into a regular expression?

前端 未结 6 690
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 04:24

I want to add regular expression search capability to my public web page. Other than HTML encoding the output, do I need to do anything to guard against malicious user input

6条回答
  •  青春惊慌失措
    2020-12-02 04:38

    Adding to tchrist's excellent answer: the same Russ Cox who wrote the "Regular Expression" page has also released code! re2 is a C++ library which guarantees O(length_of_regex) runtime and configurable memory-use limit. It's used within Google so that you can type a regex into google code search -- meaning that it's been battle tested.

提交回复
热议问题