Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#476 from catenax-ng/fix/TRI-1095-…
Browse files Browse the repository at this point in the history
…add-missing-security-headers

fix(irs-api): [TRI-1095] Lack of HTTP security headers
  • Loading branch information
ds-ext-kmassalski authored Aug 18, 2023
2 parents 0a38dfe + 2dd3954 commit 84ed3ec
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.header.writers.ContentSecurityPolicyHeaderWriter;
import org.springframework.security.web.header.writers.PermissionsPolicyHeaderWriter;
import org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter;
import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
Expand Down Expand Up @@ -69,6 +71,7 @@ public class SecurityConfiguration {
};
private static final long HSTS_MAX_AGE_DAYS = 365;
private static final String ONLY_SELF_SCRIPT_SRC = "script-src 'self'";
private static final String PERMISSION_POLICY = "microphone=(), geolocation=(), camera=()";

@SuppressWarnings("PMD.SignatureDeclareThrowsException")
@Bean
Expand All @@ -92,6 +95,9 @@ public class SecurityConfiguration {
httpSecurity.headers(headers -> headers.addHeaderWriter(new ContentSecurityPolicyHeaderWriter(ONLY_SELF_SCRIPT_SRC)));

httpSecurity.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin));
httpSecurity.headers(headers -> headers.addHeaderWriter(new ReferrerPolicyHeaderWriter(
ReferrerPolicyHeaderWriter.ReferrerPolicy.SAME_ORIGIN)));
httpSecurity.headers(headers -> headers.addHeaderWriter(new PermissionsPolicyHeaderWriter(PERMISSION_POLICY)));

httpSecurity.sessionManagement(sessionManagement -> sessionManagement
.sessionCreationPolicy(STATELESS));
Expand Down

0 comments on commit 84ed3ec

Please sign in to comment.