Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main/frontend/app/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import variables from '../../environment/environment'

export function apiUrl(path: string): string {
return `${variables.apiBaseUrl}/api${path}`
return `/api${path}`
}

const getAnonymousSessionId = () => {
Expand Down
9 changes: 0 additions & 9 deletions src/main/frontend/environment/base.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/frontend/environment/development.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/main/frontend/environment/environment.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/frontend/environment/production.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ export default defineConfig({
},
server: {
port: 3000,
proxy: {
'/api': 'http://localhost:8080',
},
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.frankframework.flow.common.config;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.jspecify.annotations.NonNull;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.web.filter.OncePerRequestFilter;

/**
* Forces the deferred {@link CsrfToken} to load on every request so the XSRF-TOKEN cookie is
* written. Otherwise the cookie is only minted when something reads the token, leaving a SPA with no
* token to echo back as X-XSRF-TOKEN.
*/
public class CsrfCookieFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull FilterChain filterChain
) throws ServletException, IOException {
CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
if (csrfToken != null) {
csrfToken.getToken();
}

filterChain.doFilter(request, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.annotation.web.configurers.FormLoginConfigurer;
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer;
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;

@Configuration
Expand All @@ -49,14 +51,7 @@ public void setEnvironment(Environment environment) {
public SecurityFilterChain configureChain(IAuthenticator authenticator, HttpSecurity http) throws Exception {
configureAuthenticator(authenticator);
http.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin));
http.csrf(csrf -> {
if (csrfEnabled) {
csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
csrf.csrfTokenRequestHandler(new SpaCsrfTokenRequestHandler());
return;
}
csrf.disable();
});
configureCsrf(http);
http.securityMatcher(AnyRequestMatcher.INSTANCE);
http.formLogin(FormLoginConfigurer::disable);
http.logout(LogoutConfigurer::disable);
Expand All @@ -75,4 +70,18 @@ private void configureAuthenticator(IAuthenticator authenticator) {
servletConfig.setUrlMapping("/*");
authenticator.registerServlet(servletConfig);
}

private void configureCsrf(HttpSecurity http) {
if (!csrfEnabled) {
http.csrf(AbstractHttpConfigurer::disable);
return;
}

http.csrf(csrf -> {
csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
csrf.csrfTokenRequestHandler(new SpaCsrfTokenRequestHandler());
});

http.addFilterAfter(new CsrfCookieFilter(), CsrfFilter.class);
}
}
Loading