Why is %e9 or %fd invalid string to decode using the decodeURIComponent from Javascript?
These characters appear in the middle of a string and I can't understand where the problem is. They are valid hexadecimal characters.
Full string (this is part of a string sent by client app to server and that was being blocked by modsec):
%61%e9%3d%36%7f%00%00%01%00%00%43%fd%a1%5a%00%00%00%43
Sample to decode:
decodeURIComponent("%61%e9%3d%36%7f%00%00%01%00%00%43%fd%a1%5a%00%00%00%43")
Error:
VM222:1 Uncaught URIError: URI malformed
at decodeURIComponent (<anonymous>)
at <anonymous>:1:1
I am using these two functions to encode base64 and decode from base64 (from here:Mozilla):
function c64(t) {
return btoa(encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,
(match, p1) => {
return String.fromCharCode('0x' + p1);
}));
}
function d64(t) {
return decodeURIComponent(atob(t).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
The original string is in base64:
d64("Yek9Nn8AAAEAAEP9oVoAAABDYek9Nn8AAAEAAEP9oVoAAABD")
returns:
...js:1 Uncaught URIError: URI malformed
at decodeURIComponent (<anonymous>)