HtmlSanitizer icon indicating copy to clipboard operation
HtmlSanitizer copied to clipboard

Sanitize - Null Byte payload

Open heldersantovisma opened this issue 4 years ago • 5 comments

Hey! Can anyone explain me how to sanitize Null Byte payloads ? Ex: "><%00img src=1 onerror=alert(1)> This example is not being sanitized.

heldersantovisma avatar May 17 '21 10:05 heldersantovisma

So the input is this?

><%00img src=1 onerror=alert(1)>

I'm getting this as output:

&gt;&lt;%00img src=1 onerror=alert(1)&gt;

Do you expect a different output?

mganss avatar May 17 '21 11:05 mganss

Yes that can be exploited because it can result in "><img src=1 onerror=alert(1)> I'm not really familiarized with Null Byte injection, but it's exploting url enconding. Any advice ? Should I do url decode before sanitizing ? http://projects.webappsec.org/w/page/13246949/Null%20Byte%20Injection

heldersantovisma avatar May 17 '21 16:05 heldersantovisma

I don't understand where the possible attack vector is here. After sanitizing, there aren't even angle brackets anymore.

mganss avatar May 17 '21 18:05 mganss

Sorry maybe I'm not explaining good enough(please lets forget the vulnerability part). My main goal is to strip all html, but recently we discovered that due to this Null Byte attacks) eg: %00 or \0 we could workaround the html sanitization. So this ><%00img src=1 onerror=alert(1)> will become this ><%00img src=1 onerror=alert(1)> and parsing it as json will result in ><img src=1 onerror=alert(1)>

The vulnerability part is on our side because we were not expecting html and the system was decoding it as such.

Any advice on how to sanitize this ?

heldersantovisma avatar May 18 '21 17:05 heldersantovisma

I took the liberty of adding code formatting to your inline examples.

I'm still confused as to what the actual issue and goals are. Where exactly does the null byte injection get triggered, within C# code or in some other system?

The eventual output &gt;&lt;img src=1 onerror=alert(1)&gt; is not dangerous is it?

What's your desired output?

mganss avatar May 19 '21 10:05 mganss