I am using XSS cross site scripting in my application. My application has an endpoint where I have to upload a xls file through postman. When I try to hit the endpoint, the XSS scripting doesn't let it pass and gives following error
2019-08-08 10:47:38|800 [DEBUG] com.vz.stamps.tools.XSSTools - Value to validate for XSS: [----------------------------503127257286871229160750Content-Disposition: form-data; name="file"; filename="New Microsoft Excel Worksheet.xls"Content-Type: application/vnd.ms-excelPK
This is my code for urlDecode:
public static String urlDecode(String value) {
try {
value = value.replaceAll("%25", " ");
value =URLDecoder.decode(value, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
logger.info("Unable to decode String with UTF8! Trying adifferent encoding", e);
try {
value =URLDecoder.decode(value, StandardCharsets.ISO_8859_1.name());
} catch (UnsupportedEncodingException e1) {
logger.info("Unable to decode String with ISO_8859_1! Trying adifferent encoding", e);
try {
value =URLDecoder.decode(value, StandardCharsets.US_ASCII.name());
} catch (UnsupportedEncodingException e2) {
logger.info("Unable to decode String with US_ASCII! Not trying to decode any further!!!", e);
}
}
} catch (Exception e) {
logger.error("Error decoding String, returning null!!!", e);
return value.replaceAll("%", "");
}
return value;
}
Value I am getting from postman is:
----------------------------238658527993479868792963Content-Disposition: form-data; name="file"; filename="New Microsoft Excel Worksheet.xls"Content-Type: application/vnd.ms-excelPK
error :
URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "¿"