Skip to content

Commit

Permalink
VKT(Backend): Security audit fixes. Added cache no-store and CSP policy
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Jan 30, 2025
1 parent 1b052a8 commit ca6cd98
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.oph.vkt.api.clerk;

import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import fi.oph.vkt.api.dto.clerk.ClerkExamEventCreateDTO;
Expand All @@ -9,9 +10,13 @@
import fi.oph.vkt.service.ClerkExamEventService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.util.List;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public static HttpSecurity commonConfig(final HttpSecurity httpSecurity) throws
.permitAll()
.anyRequest()
.authenticated()
)
.headers(httpSecurityHeadersConfigurer ->
httpSecurityHeadersConfigurer.contentSecurityPolicy(contentSecurityPolicyConfig ->
contentSecurityPolicyConfig.policyDirectives("style-src 'self'; script-src 'self'; form-action 'self'")
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected void buildExcelDocument(
final @NonNull HttpServletResponse response
) {
setFilenameHeader(response, String.format("VKT_tilaisuus_%s_%s.xlsx", data.date(), data.language()));
response.setHeader("Cache-Control", "no-cache, no-store, private, max-age=0, must-revalidate");
writeExcel(workbook);
}

Expand Down

0 comments on commit ca6cd98

Please sign in to comment.