如何从上传的文件名中删除XSS?

时间:2018-02-12 22:54:56

标签: javascript html security spring-boot xss

我想修复xss漏洞。

情景 - 以下:
1.我&#39;已创建名为<form id="uploadForm"> <div class="form-group"> <div class="custom-file"> <input class="custom-file-input" name="file" id="uploadFile" type="file" /> <label class="custom-file-label" for="uploadFile">Choose CSV file...</label> </div> <div class="" id="uploadSuccess"> <p class="text-success">Success!</p> <p class="text-success" id="successText"></p> </div> <div class="" id="uploadError"> <p class="text-danger">Something has gone wrong!</p> <p class="text-danger" id="errorText"></p> </div> </div> </form> 的文件 2.我的页面上有html输入,我尝试加载在step_1上创建的文件,并查看:

enter image description here

显然,文件名中的恶意代码会执行。

代码:

$("#uploadForm").off('submit').on('submit', (e) => {
        let url = "rest_upload";
        let form = $("#uploadForm")[0];
        let data = new FormData(form);

        e.preventDefault();

        $.ajax({
            method: "POST",
            url: url,
            data: data,
            contentType: false,
            processData: false
        })
            .done((data) => {
                $('#uploadError').hide();
                $('#uploadSuccess').show();
                $('#successText').text(data);
            })
            .fail((err) => {
                if (err.status === 401) return;

                $('#uploadSuccess').hide();
                $('#uploadError').show();
                $('#errorText').text(err.responseText);
            });
    });
}

JS:

@RequestMapping(method=RequestMethod.GET, path="/stair/shippingorders", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<?> getShippingOrder(@RequestBody JsonNode request) throws JsonProcessingException, IOException{
    log.info("get body: " + request);

    // do stuff
    return ResponseEntity.ok(response);
}

如何预防?

是否有可能以某种方式在服务器端阻止它?

0 个答案:

没有答案