如何在rails中避免html、iframe和跨站注入?

How to avoid html, iframe and cross site injection in rails?

我已将数据作为 html 内容存储在我的数据库中。

每当用户提供输入时,它都会注入我的 html。

在存储到数据库之前我应该​​做什么我需要清理我的数据。或者我可以存储任何数据。仅在视图中显示时,我需要做一些注入。

我建议你参考 XSS Cross Site Scripting cheatsheet

特别是 Rails,如前所述:

The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements.

<%= sanitize @comment.body, tags: %w(strong em a), attributes: %w(href) %>