Skip to content

Commit

Permalink
#921: read CSP (connect.src) from Properties
Browse files Browse the repository at this point in the history
  • Loading branch information
clean-coder committed Jul 11, 2024
1 parent 19ef323 commit ee7ae43
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions backend/src/main/java/ch/puzzle/okr/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.nimbusds.jwt.proc.JWTProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -36,9 +37,14 @@
public class SecurityConfig {
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);

private String connectSrc;

@Bean
@Order(1) // Must be First order! Otherwise unauthorized Requests are sent to Controllers
public SecurityFilterChain apiSecurityFilterChain(HttpSecurity http) throws Exception {
public SecurityFilterChain apiSecurityFilterChain(HttpSecurity http, @Value("${connect.src}") String connectSrc)
throws Exception {
this.connectSrc = connectSrc;

setHeaders(http);
http.addFilterAfter(new ForwardFilter(), BasicAuthenticationFilter.class);
logger.debug("*** apiSecurityFilterChain reached");
Expand Down Expand Up @@ -93,7 +99,7 @@ private String okrContentSecurityPolicy() {
+ " style-src 'self' 'unsafe-inline';" //
+ " object-src 'none';" //
+ " base-uri 'self';" //
+ " connect-src 'self' https://sso.puzzle.ch http://localhost:8544;" //
+ " connect-src 'self' " + connectSrc + ";" //
+ " font-src 'self';" //
+ " frame-src 'self';" //
+ " img-src 'self' data: ;" //
Expand Down
3 changes: 3 additions & 0 deletions backend/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ spring.flyway.locations=classpath:db/migration,classpath:db/data-migration,class
okr.tenant-ids=pitc,acme
okr.datasource.driver-class-name=org.postgresql.Driver

# security
connect.src=http://localhost:8544 http://localhost:8545

# hibernate
hibernate.connection.url=jdbc:postgresql://localhost:5432/okr
hibernate.connection.username=user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ spring.flyway.locations=classpath:db/h2-db/database-h2-schema,classpath:db/h2-db
okr.tenant-ids=pitc,acme
okr.datasource.driver-class-name=org.h2.Driver

# security
connect.src=http://localhost:8544 http://localhost:8545

# hibernate
hibernate.connection.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;
hibernate.connection.username=user
Expand Down
3 changes: 3 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ okr.clientcustomization.title=Puzzle OKR

okr.quarter.business.year.start=7
okr.quarter.label.format=GJ xx/yy-Qzz

# security
connect.src=https://sso.puzzle.ch

0 comments on commit ee7ae43

Please sign in to comment.