我使用这个Grails 3插件对用户输入的XSS进行消毒。它使用正则表达式过滤掉不需要的内容。其中一个表达方式是:
<(.*?)form(.*?)>(.*?)</(.*?)form(.*?)>它的目的是消除注入的恶意形式。“守则”写道:
// Avoid any form injection with <...form ...> ... </form ...> tag然而,这一表述过于宽泛。例如,它匹配以下无害字符串:
<p>Refactoring is the disciplined process of improving design qualities without changing the external behaviour of the code. To refactor a big piece of code means to apply small transformation that keep the behavior unchanged. When refactoring, the code should work every 5-7 minutes. It's not refactoring if you can't run the code for hours or days.</p><p><br></p><p>In this session, we will take a deep dive into the refactoring transformations. I will demonstrate:</p><p> how to pick the next transformation</p><p> how small the transformations are</p><p> how to use tools to make refactoring faster and</p><p> how local transformations lead to unexpected improvements in design</p>问题是:,去掉表单的更好的正则表达式是什么?当然,像上面这样的字符串应该保持原样。
发布于 2018-01-23 11:08:06
作为免责声明,我们一般不应该使用regex来过滤嵌套的HTML内容(实际上也包括任何HTML)内容。但是,由于OP似乎使用的是一个工具来实现这一点,所以可能没有一个简单的解决办法。
下面的模式似乎有效,并且只在<form>标记上触发:
<([^<>]*)form([^<>]*)>(.*?)<\/([^<>]*)form([^<>]*)>我对您原来的模式所做的主要更改是使标签内的匹配尽可能不贪婪和谨慎。您的示例文本是一个很好的文本,因为它包含了单词transformations,它与您的原始模式导致错误的结果。
https://stackoverflow.com/questions/48399676
复制相似问题