File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
main/java/org/springframework/security/web/server/csrf
test/java/org/springframework/security/web/server/csrf Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ public void setCookieCustomizer(Consumer<ResponseCookie.ResponseCookieBuilder> c
8484 */
8585 public static CookieServerCsrfTokenRepository withHttpOnlyFalse () {
8686 CookieServerCsrfTokenRepository result = new CookieServerCsrfTokenRepository ();
87- result .setCookieCustomizer (( cookie ) -> cookie . httpOnly ( false )) ;
87+ result .cookieHttpOnly = false ;
8888 return result ;
8989 }
9090
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -290,6 +290,21 @@ void loadTokenWhenCookieExistsWithNullValue() {
290290 loadAndAssertExpectedValues ();
291291 }
292292
293+ // gh-16820
294+ @ Test
295+ void withHttpOnlyFalseWhenCookieCustomizerThenStillDefaultsToFalse () {
296+ CookieServerCsrfTokenRepository repository = CookieServerCsrfTokenRepository .withHttpOnlyFalse ();
297+ repository .setCookieCustomizer ((customizer ) -> customizer .maxAge (1000 ));
298+ MockServerHttpRequest .BaseBuilder <?> request = MockServerHttpRequest .get ("/dummy" );
299+ MockServerWebExchange exchange = MockServerWebExchange .from (request );
300+ CsrfToken csrfToken = repository .generateToken (exchange ).block ();
301+ repository .saveToken (exchange , csrfToken ).block ();
302+ ResponseCookie cookie = exchange .getResponse ().getCookies ().getFirst ("XSRF-TOKEN" );
303+ assertThat (cookie ).isNotNull ();
304+ assertThat (cookie .getMaxAge ().getSeconds ()).isEqualTo (1000 );
305+ assertThat (cookie .isHttpOnly ()).isEqualTo (Boolean .FALSE );
306+ }
307+
293308 private void setExpectedHeaderName (String expectedHeaderName ) {
294309 this .csrfTokenRepository .setHeaderName (expectedHeaderName );
295310 this .expectedHeaderName = expectedHeaderName ;
You can’t perform that action at this time.
0 commit comments