dom型xss漏洞修复方式有哪些

1294
2021/2/7 9:28:32
栏目: 网络安全
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

dom型xss漏洞修复方式有哪些

修复dom型xss漏洞的方式有以下几种

1.使用@InitBinder方法

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;

@Controller

public class BaseController {

@InitBinder

public void webInitBinder(WebDataBinder binder){

binder.registerCustomEditor(String.class, new StringEditor());

}

}

public class StringEditor extends PropertyEditorSupport {

@Override

public void setAsText(String text) throws IllegalArgumentException {

if (StringUtils.isBlank(text)) {

return;

}

try {

//Spring自带html标签转义与反转义

super.setValue(HtmlUtils.htmlEscape(text));

} catch (Exception e) {

throw new IllegalArgumentException(e);

}

}

}

2.使用WebBindingInitializer方法

public class WebBinderInitializerUtils implements WebBindingInitializer{

@Override

public void initBinder(WebDataBinder binder, WebRequest request) {

binder.registerCustomEditor(String.class,new StringEditor());

}

}

public class StringEditor extends PropertyEditorSupport {

@Override

public void setAsText(String text) throws IllegalArgumentException {

if (StringUtils.isBlank(text)) {

return;

}

try {

//Spring自带html标签转义与反转义

super.setValue(HtmlUtils.htmlEscape(text));

} catch (Exception e) {

throw new IllegalArgumentException(e);

}

}

}

3.使用HttpOnly方法

response.setHeader("Set-Cookie", "cookiename=value;

Path=/;Domain=domainvalue;Max-Age=seconds;HTTPOnly");

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: dom型xss漏洞修复方式有哪些