Skip to content

Commit 4d88a37

Browse files
Copilotcommjoen
andcommitted
Fix Spotless formatting violations in security header files
Co-authored-by: commjoen <[email protected]>
1 parent 27f48c2 commit 4d88a37

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

src/main/java/org/owasp/wrongsecrets/SecurityConfig.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ public SecurityFilterChain security(
3030
configureBasicAuthentication(http, auths);
3131
configureCsrf(http);
3232
// Disable default security headers since we handle them in SecurityHeaderAddingFilter
33-
http.headers(headers ->
34-
headers.frameOptions(frameOptions -> frameOptions.sameOrigin())
35-
.contentTypeOptions(Customizer.withDefaults()));
33+
http.headers(
34+
headers ->
35+
headers
36+
.frameOptions(frameOptions -> frameOptions.sameOrigin())
37+
.contentTypeOptions(Customizer.withDefaults()));
3638
return http.build();
3739
}
3840

src/main/java/org/owasp/wrongsecrets/SecurityHeaderAddingFilter.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
1414
throws IOException, ServletException {
1515
HttpServletResponse res = (HttpServletResponse) response;
1616
res.addHeader("Server", "WrongSecrets - Star us!");
17-
res.setHeader("X-Frame-Options", "SAMEORIGIN"); // Override Spring Security's default DENY
17+
res.setHeader("X-Frame-Options", "SAMEORIGIN"); // Override Spring Security's default DENY
1818
res.setHeader("X-Content-Type-Options", "nosniff");
19-
19+
2020
// Improved Content Security Policy - more restrictive than wildcard
2121
res.setHeader(
2222
"Content-Security-Policy",
23-
"default-src 'self'; script-src 'self' 'unsafe-inline' https://buttons.github.io https://api.github.com; " +
24-
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; " +
25-
"font-src 'self' https://fonts.gstatic.com; " +
26-
"img-src 'self' data: https:; " +
27-
"connect-src 'self' https://api.github.com");
28-
23+
"default-src 'self'; script-src 'self' 'unsafe-inline' https://buttons.github.io"
24+
+ " https://api.github.com; style-src 'self' 'unsafe-inline'"
25+
+ " https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src"
26+
+ " 'self' data: https:; connect-src 'self' https://api.github.com");
27+
2928
// Add Permissions Policy header
3029
res.setHeader("Permissions-Policy", "geolocation=(), microphone=(), camera=()");
31-
30+
3231
// Add cache control headers to prevent caching of sensitive content
3332
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
3433
res.setHeader("Pragma", "no-cache");
3534
res.setHeader("Expires", "0");
36-
35+
3736
chain.doFilter(request, res);
3837
}
3938
}

src/test/java/org/owasp/wrongsecrets/SecurityHeaderTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ void shouldHaveContentSecurityPolicyHeader() throws Exception {
4343
void shouldHavePermissionsPolicyHeader() throws Exception {
4444
mvc.perform(get("/"))
4545
.andExpect(status().isOk())
46-
.andExpect(header().string("Permissions-Policy", "geolocation=(), microphone=(), camera=()"));
46+
.andExpect(
47+
header().string("Permissions-Policy", "geolocation=(), microphone=(), camera=()"));
4748
}
4849

4950
@Test
@@ -59,11 +60,13 @@ void shouldHaveCacheControlHeaders() throws Exception {
5960
void shouldNotHaveWildcardInCSP() throws Exception {
6061
mvc.perform(get("/"))
6162
.andExpect(status().isOk())
62-
.andExpect(result -> {
63-
String csp = result.getResponse().getHeader("Content-Security-Policy");
64-
if (csp != null && csp.contains("default-src *")) {
65-
throw new AssertionError("CSP should not contain wildcard directive 'default-src *'");
66-
}
67-
});
63+
.andExpect(
64+
result -> {
65+
String csp = result.getResponse().getHeader("Content-Security-Policy");
66+
if (csp != null && csp.contains("default-src *")) {
67+
throw new AssertionError(
68+
"CSP should not contain wildcard directive 'default-src *'");
69+
}
70+
});
6871
}
69-
}
72+
}

0 commit comments

Comments
 (0)