Skip to content

Commit 02f2be6

Browse files
committed
prevented xss() from crashing when attempting to URI-decode a string
that is not URI-encoded
1 parent d2d2e77 commit 02f2be6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/xss.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ exports.clean = function(str, is_image) {
6464

6565
//Decode just in case stuff like this is submitted:
6666
//<a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
67-
str = decodeURIComponent(str);
67+
try{
68+
str = decodeURIComponent(str);
69+
}
70+
catch(error){
71+
// str was not actually URI-encoded
72+
}
6873

6974
//Convert character entities to ASCII - this permits our tests below to work reliably.
7075
//We only convert entities that are within tags since these are the ones that will pose security problems.

0 commit comments

Comments
 (0)