首页 > 解决方案 > XSS 跨站点脚本不允许在 Spring Boot 应用程序中使用 xls 文件

问题描述

我在我的应用程序中使用 XSS 跨站点脚本。我的应用程序有一个端点,我必须通过邮递员上传 xls 文件。当我尝试到达端点时,XSS 脚本不会让它通过并给出以下错误

2019-08-08 10:47:38|800 [DEBUG] com.vz.stamps.tools.XSSTools - 验证 XSS 的值:[------------------ ----------503127257286871229160750内容处置:表单数据;名称=“文件”;filename="New Microsoft Excel Worksheet.xls"Content-Type: application/vnd.ms-excelPK

这是我的 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;
        }

我从邮递员那里得到的价值是:

----------------------------238658527993479868792963Content-Disposition: form-data; name="file"; filename="New Microsoft Excel Worksheet.xls"Content-Type: application/vnd.ms-excelPK

错误 :

URLDecoder:转义 (%) 模式中的非法十六进制字符 - 对于输入字符串:“¿”

标签: javapostmanxssxssf

解决方案


推荐阅读