【发布时间】:2021-06-23 11:31:57
【问题描述】:
我正在使用 Redcarpet 渲染用户介绍的网页数据。
我发现用户很容易引入恶意 HTML 代码。
我正在尝试不同的 Redcarpet 初始化程序选项,以防止在输出中呈现任何可能的恶意代码,但没有任何效果:
尝试filter_html:
markdown =
Redcarpet::Markdown.new(
Redcarpet::Render::HTML,
filter_html: true
)
markdown.render("<style>style</style> <script>alert()</script>")
# => "<p><style>style</style> <script>alert()</script></p>\n"
尝试scape_html:
markdown =
Redcarpet::Markdown.new(
Redcarpet::Render::HTML,
escape_html: true
)
markdown.render("<style>style</style> <script>alert()</script>")
# => "<p><style>style</style> <script>alert()</script></p>\n"
【问题讨论】: