File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
src/main/java/clap/server/config Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ package clap .server .config .jackson ;
2+
3+ import com .fasterxml .jackson .core .JsonParser ;
4+ import com .fasterxml .jackson .databind .DeserializationContext ;
5+ import com .fasterxml .jackson .databind .JsonDeserializer ;
6+ import com .fasterxml .jackson .databind .ObjectMapper ;
7+ import com .fasterxml .jackson .databind .module .SimpleModule ;
8+ import lombok .extern .slf4j .Slf4j ;
9+ import org .jsoup .Jsoup ;
10+ import org .jsoup .safety .Safelist ;
11+ import org .springframework .context .annotation .Bean ;
12+ import org .springframework .context .annotation .Configuration ;
13+
14+ import java .io .IOException ;
15+
16+ // XSS 방지를 위한 Jackson 설정
17+ @ Slf4j
18+ @ Configuration
19+ public class JacksonConfig {
20+
21+ @ Bean
22+ public ObjectMapper objectMapper () {
23+ ObjectMapper mapper = new ObjectMapper ();
24+ SimpleModule module = new SimpleModule ();
25+ module .addDeserializer (String .class , new JsonHtmlXssDeserializer ());
26+ mapper .registerModule (module );
27+ return mapper ;
28+ }
29+
30+ public static class JsonHtmlXssDeserializer extends JsonDeserializer <String > {
31+ @ Override
32+ public String deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException {
33+ String value = p .getText ();
34+ return Jsoup .clean (value , Safelist .basic ());
35+ }
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ package clap .server .config .web ;
2+
3+ import clap .server .adapter .inbound .xss .XssPreventionFilter ;
4+ import org .springframework .boot .web .servlet .FilterRegistrationBean ;
5+ import org .springframework .context .annotation .Bean ;
6+ import org .springframework .context .annotation .Configuration ;
7+ import org .springframework .core .Ordered ;
8+
9+ @ Configuration
10+ public class WebConfig {
11+
12+ @ Bean
13+ public FilterRegistrationBean <XssPreventionFilter > xssPreventionFilterRegistrationBean () {
14+ FilterRegistrationBean <XssPreventionFilter > registrationBean = new FilterRegistrationBean <>();
15+ registrationBean .setFilter (new XssPreventionFilter ());
16+ registrationBean .setOrder (Ordered .HIGHEST_PRECEDENCE );
17+ registrationBean .addUrlPatterns ("/*" );
18+ return registrationBean ;
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments