XSS防御(@requestBody)
JSONではXSS防止のシーブレットフィルタで使用されるコードも適用される.
@Configuration
@ConditionalOnClass(name="com.fasterxml.jackson.databind.ObjectMapper")
protected static class JacksonCustomizerConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer objectMapperBuilderCustomizer() {
return customizer -> customizer.findModulesViaServiceLoader(true);
}
}
@Configuration
@ConditionalOnClass(name="com.fasterxml.jackson.databind.module.SimpleModule")
public static class JacksonModuleProvider {
@Bean
public SimpleModule xssProtectionModule() {
return new SimpleModule("XssProtectionModule", Version.unknownVersion(), ImmutableMap.of(String.class, new XssProtectionJsonDeserializer()));
}
}
static class XssProtectionJsonDeserializer extends StringDeserializer implements ContextualDeserializer {
private static final long serialVersionUID = 1L;
@Override
public JsonDeserializer<String> createContextual(final DeserializationContext c, final BeanProperty bp) {
return this;
}
@Nullable @Override
public String deserialize(final JsonParser p, final DeserializationContext c) throws IOException {
return com.nhncorp.lucy.security.xss.XssPreventer.escape(super.deserialize(p, c));
}
}
Reference
この問題について(XSS防御(@requestBody)), 我々は、より多くの情報をここで見つけました https://velog.io/@looniverse/xss-방어-RequestBodyテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol