Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kim.hanjie.common:common-xss

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kim.hanjie.common:common-xss

req通过getParameter、getParameterValues获取值,json形式body,转成对象时,xss过滤

  • 1.0.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

common-xss

req通过getParameter、getParameterValues获取值,json形式body,转成对象时,xss过滤

原理

使用StringEscapeUtils中的escapeHtml4来转换html的特殊字符,防止xss攻击

使用

    <dependency>
        <groupId>kim.hanjie.common</groupId>
        <artifactId>common-xss</artifactId>
        <version>1.0.0</version>
    </dependency>

filter使用

@Configuration
public class FilterConfiguration {
    @Bean
    public FilterRegistrationBean<XssFilter> xssFilterFilterRegistration() {
        FilterRegistrationBean<XssFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new XssFilter());
        registration.addUrlPatterns("/*");
        registration.setName("xssFilter");
        return registration;
    }
}

XssStringJsonDeserializer使用

@Configuration
public class JacksonConvertersConfiguration {
    @Bean
    @Primary
    ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        Jackson2ObjectMapperBuilder xmlMapper = builder.createXmlMapper(false);
        xmlMapper.serializationInclusion(JsonInclude.Include.NON_NULL);
        // 设置 String的deserializer Type为XssStringJsonDeserializer
        builder.deserializerByType(String.class, new XssStringJsonDeserializer());
        return xmlMapper.build();
    }
}

例外

对于一些不需要xss处理的文本,如果富文本内容,则可以使用StringEscapeUtils.unescapeHtml4转回来
对于向富文本这种,可以通过Jsoup.clean()方法来获取安全的富文本内容

    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.13.1</version>
    </dependency>

FAQs

Package last updated on 18 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc