Spaces:
Sleeping
Sleeping
Update src/main/java/com/example/config/SecurityConfig.java
Browse files
src/main/java/com/example/config/SecurityConfig.java
CHANGED
|
@@ -32,7 +32,43 @@ public class SecurityConfig {
|
|
| 32 |
.defaultSuccessUrl("/secure", true)
|
| 33 |
)
|
| 34 |
.logout(logout -> logout.logoutSuccessUrl("/"))
|
| 35 |
-
.oidcLogout(oidc -> oidc.backChannel(Customizer.withDefaults()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
return http.build();
|
| 38 |
}
|
|
|
|
| 32 |
.defaultSuccessUrl("/secure", true)
|
| 33 |
)
|
| 34 |
.logout(logout -> logout.logoutSuccessUrl("/"))
|
| 35 |
+
.oidcLogout(oidc -> oidc.backChannel(Customizer.withDefaults()))
|
| 36 |
+
.headers(headers -> headers
|
| 37 |
+
// 1. Content Security Policy (Hardened)
|
| 38 |
+
.contentSecurityPolicy(csp -> csp
|
| 39 |
+
.policyDirectives("default-src 'self'; " +
|
| 40 |
+
"script-src 'self' 'unsafe-inline' 'unsafe-eval'; " +
|
| 41 |
+
"style-src 'self' 'unsafe-inline'; " +
|
| 42 |
+
"img-src 'self' data:; " +
|
| 43 |
+
"connect-src 'self' " +
|
| 44 |
+
"https://8080-firebase-auth-java-1771681085208.cluster-c36dgv2kibakqwbbbsgmia3fny.cloudworkstations.dev " +
|
| 45 |
+
"https://4200-firebase-auth-java-1771681085208.cluster-c36dgv2kibakqwbbbsgmia3fny.cloudworkstations.dev " +
|
| 46 |
+
"https://learnifymedhub-kc.hf.space; " +
|
| 47 |
+
"frame-ancestors 'self' https://*.cloudworkstations.dev https://*.google.com; " +
|
| 48 |
+
"form-action 'self';")
|
| 49 |
+
)
|
| 50 |
+
// 2. HTTP Strict Transport Security (HSTS)
|
| 51 |
+
.httpStrictTransportSecurity(hsts -> hsts
|
| 52 |
+
.includeSubDomains(true)
|
| 53 |
+
.preload(true)
|
| 54 |
+
.maxAgeInSeconds(31536000) // 1 year
|
| 55 |
+
)
|
| 56 |
+
// 3. X-Content-Type-Options: nosniff
|
| 57 |
+
.contentTypeOptions(Customizer.withDefaults())
|
| 58 |
+
|
| 59 |
+
// 4. X-Frame-Options: SAMEORIGIN
|
| 60 |
+
.frameOptions(frame -> frame.sameOrigin())
|
| 61 |
+
|
| 62 |
+
// 5. Referrer Policy
|
| 63 |
+
.referrerPolicy(referrer -> referrer
|
| 64 |
+
.policy(org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN)
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
// 6. Permissions Policy (FIXED: Using the new permissionsPolicyHeader method)
|
| 68 |
+
.permissionsPolicyHeader(permissions -> permissions
|
| 69 |
+
.policy("geolocation=(), microphone=(), camera=(), payment=(), usb=()")
|
| 70 |
+
)
|
| 71 |
+
);
|
| 72 |
|
| 73 |
return http.build();
|
| 74 |
}
|