Ruby 关于有空格的文字列的 XSS 对策案

wangp070533 · 2018年12月05日 · 938 次阅读
<%= select_tag "select_name", options_for_select(@name_select_list.collect{|p| [p["name"], p["id"]]}), :style => "width:200px", :prompt => I18n.t('labels.items.all') %>

p["name"] = "   alert(9999)"

期待値:下拉菜单里显示

”   <script>alert(9999)</script>”

対策案:

①<%= select_tag "select_name", options_for_select(@name_select_list.collect{|p| [(sanitize p["name"]), p["id"]]}), :style => "width:200px", :prompt => I18n.t('labels.items.all') %>

結果:下拉菜单里显示

”   alert(9999)”
②<%= select_tag "select_name", options_for_select(@name_select_list.collect{|p| [p["name"], p["id"]]}), :style => "width:200px", :prompt => I18n.t('labels.items.all') %>

結果:下拉菜单里显示

”&nbsp;&nbsp;&nbsp;<script>alert(9999)</script>”

有能完美解决的方案吗?

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号