Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 Ruby on Rails 3.0.9,出于安全原因,我想知道何时可以、应该和必须使用该sanitize(...)方法。
sanitize(...)
一个使用示例可以是:
sanitize(flash[:notice])
每当您显示用户输入的数据时,您都应该使用它,即它不能被信任。
例如,在聊天应用程序中,用户可以编写帖子,然后将其显示在页面上。在这种情况下,清理输入很重要。
如果您不清理输入,用户可以将 HTML 和 Javascript 代码注入您的页面,这会影响查看同一页面的所有其他用户。通过这种方式,攻击者可以完全控制页面。
另一方面,没有必要清理您的应用程序创建的数据,即在您的示例中 ( sanitize(flash[:notice])) 是不必要的。(假设您flash用于显示应用程序创建的状态消息)
flash