rails 利用UTF-8的 multibyte特性 对textarea 发动 xss 攻击

The blog discusses a security vulnerability in Rails applications where an attacker can exploit UTF-8 multibyte characters to initiate an XSS attack through a textarea input. The attack is possible due to the inability of the `html_escape` method to handle UTF-8 multi-byte data effectively. A solution is provided by modifying the `html_escape` method to properly escape multibyte characters.
摘要由CSDN通过智能技术生成

UTF-8的 multibyte特性:

1个文字是由复数个字节组成的.

Shift_JIS情况下,一个"あ"占2个字节.

"あ".tosjis.bytes.to_a #=>[130, 160]

utf-8情况下,一个"あ"占3个字节.

"あ".toutf8.bytes.to_a  #=>[227, 129, 130]


攻击例:

ruby代码

<%= f.text_area :memo, :size =>"100x10" %>


1.http://example.com/...?memo=%c0%3c%2ftextarea%20%c0%3e%c0%3cimg%20src=1%20οnerrοr=alert(0)//

[decode值 http://example.com/...?memo=�</textarea �>�<

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值