diff --git a/Dockerfile b/Dockerfile index c8b1442f..d5626955 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM eclipse-temurin:17.0.18_8-jre-noble +FROM eclipse-temurin:17.0.21_9-jre-noble WORKDIR /app diff --git a/pom.xml b/pom.xml index be9f502d..9c2c9ff9 100644 --- a/pom.xml +++ b/pom.xml @@ -62,22 +62,23 @@ - 3.8.1 - 3.4.1 - 3.5.11 - 3.4.2 - 2.41.32 - 7.1.16 - 2.1.4 + 3.11.0 + 3.5.1 + 4.1.2 + 4.2.2 + 2.59.0 + 7.2.0 + 2.1.5 2.2.3 2.2.3 2.0.1 2.1.3 - 5.3.2 - 1.22.1 - 0.8.14 - 1.84 - 9.9.1 + 5.5.1 + 6.3.0 + 1.24.1 + 0.8.16 + 1.87 + 9.11.1 pass-core eclipse-pass_pass-core ${project.build.directory}/site/jacoco/jacoco.xml @@ -111,16 +112,15 @@ pom import - - - org.springframework.security - spring-security-bom - 6.5.9 + io.rest-assured + rest-assured-bom + ${rest-assured.version} pom import + org.springframework.boot spring-boot-dependencies @@ -157,26 +157,11 @@ bcpkix-jdk18on ${bouncycastle.version} - - org.apache.httpcomponents - httpclient - 4.5.14 - - - org.apache.commons - commons-compress - 1.28.0 - org.apache.commons commons-text 1.15.0 - - org.antlr - antlr4-runtime - 4.13.2 - org.ow2.asm asm @@ -205,63 +190,34 @@ commons-io commons-io - 2.21.0 - - - commons-beanutils - commons-beanutils - 1.11.0 + 2.22.0 com.google.guava guava - 33.4.8-jre + 33.8.0-jre com.google.errorprone error_prone_annotations - 2.42.0 - - - com.google.protobuf - protobuf-java - 4.27.5 + 2.52.0 org.checkerframework checker-qual - 3.52.0 + 4.4.0 - - - - - - - - org.apache.activemq - artemis-jakarta-server - 2.53.0 - - - commons-logging - commons-logging - - + org.apache.commons + commons-collections4 + 4.6.0 - org.apache.activemq - artemis-jakarta-client - 2.53.0 - - - commons-logging - commons-logging - - + org.jooq + joou-java-6 + 0.9.5 - + @@ -277,6 +233,11 @@ ch.qos.logback logback-classic + + org.slf4j + jcl-over-slf4j + runtime + @@ -315,14 +276,14 @@ - org.springframework.security - spring-security-saml2-service-provider + org.springframework.boot + spring-boot-starter-security-saml2 - org.liquibase - liquibase-core + org.springframework.boot + spring-boot-starter-liquibase com.h2database @@ -349,8 +310,14 @@ - org.apache.activemq + org.apache.artemis artemis-jakarta-server + + + commons-logging + commons-logging + + com.amazonaws @@ -437,6 +404,12 @@ org.springframework.boot spring-boot-starter-test test + + + commons-logging + commons-logging + + io.rest-assured @@ -451,12 +424,12 @@ org.testcontainers - localstack + testcontainers-localstack test org.testcontainers - junit-jupiter + testcontainers-junit-jupiter test @@ -578,7 +551,7 @@ io.ocfl:ocfl-java-api: com.google.code.findbugs:jsr305: - org.apache.activemq:artemis-jakarta-server: + org.apache.artemis:artemis-jakarta-server: org.mockito:: org.junit.jupiter:junit-jupiter-api: @@ -605,11 +578,12 @@ ch.qos.logback:logback-classic: - org.liquibase:liquibase-core: com.h2database:h2: org.postgresql:postgresql: + + org.slf4j:jcl-over-slf4j: - org.apache.activemq:artemis-jakarta-server: + org.apache.artemis:artemis-jakarta-server: jakarta.json:jakarta.json-api: com.fasterxml.jackson.core:jackson-databind: diff --git a/src/main/java/org/eclipse/pass/file/service/storage/StorageProperties.java b/src/main/java/org/eclipse/pass/file/service/storage/StorageProperties.java index b2224c95..e5202848 100644 --- a/src/main/java/org/eclipse/pass/file/service/storage/StorageProperties.java +++ b/src/main/java/org/eclipse/pass/file/service/storage/StorageProperties.java @@ -101,7 +101,7 @@ public Optional getS3RepoPrefix() { * @return The S3 bucket name of the File Service */ public Optional getBucketName() { - return Optional.of(s3BucketName); + return Optional.ofNullable(s3BucketName); } /** diff --git a/src/main/java/org/eclipse/pass/main/Main.java b/src/main/java/org/eclipse/pass/main/Main.java index b66fbbe1..e7f962ab 100644 --- a/src/main/java/org/eclipse/pass/main/Main.java +++ b/src/main/java/org/eclipse/pass/main/Main.java @@ -17,7 +17,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.persistence.autoconfigure.EntityScan; import org.springframework.context.annotation.ComponentScan; import org.springframework.jms.annotation.EnableJms; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/src/main/java/org/eclipse/pass/main/security/SecurityConfiguration.java b/src/main/java/org/eclipse/pass/main/security/SecurityConfiguration.java index 12ab9143..826861c1 100644 --- a/src/main/java/org/eclipse/pass/main/security/SecurityConfiguration.java +++ b/src/main/java/org/eclipse/pass/main/security/SecurityConfiguration.java @@ -31,7 +31,7 @@ import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository; import org.springframework.security.saml2.provider.service.web.DefaultRelyingPartyRegistrationResolver; import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver; -import org.springframework.security.saml2.provider.service.web.authentication.OpenSaml4AuthenticationRequestResolver; +import org.springframework.security.saml2.provider.service.web.authentication.OpenSaml5AuthenticationRequestResolver; import org.springframework.security.saml2.provider.service.web.authentication.Saml2AuthenticationRequestResolver; import org.springframework.security.saml2.provider.service.web.authentication.Saml2WebSsoAuthenticationFilter; import org.springframework.security.web.SecurityFilterChain; @@ -41,7 +41,7 @@ import org.springframework.security.web.header.writers.ContentSecurityPolicyHeaderWriter; import org.springframework.security.web.header.writers.DelegatingRequestMatcherHeaderWriter; import org.springframework.security.web.savedrequest.HttpSessionRequestCache; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher; import org.springframework.security.web.util.matcher.OrRequestMatcher; @@ -88,7 +88,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { // Ensure that GET requests to the doi service are protected since they have side effects http.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .requireCsrfProtectionMatcher(new OrRequestMatcher(CsrfFilter.DEFAULT_CSRF_MATCHER, - new AntPathRequestMatcher("/doi/**"))) + PathPatternRequestMatcher.withDefaults().matcher("/doi/**"))) .csrfTokenRequestHandler(new SpaCsrfTokenRequestHandler())); // Set Content Security Policy header only for /app/ @@ -96,7 +96,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { cspHeaderWriter.setPolicyDirectives(contentSecurityPolicy); DelegatingRequestMatcherHeaderWriter appCspHeaderWriter = new DelegatingRequestMatcherHeaderWriter( - new AntPathRequestMatcher("/app/**"), cspHeaderWriter); + PathPatternRequestMatcher.withDefaults().matcher("/app/**"), cspHeaderWriter); http.headers(h -> h.addHeaderWriter(appCspHeaderWriter)); @@ -156,8 +156,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { Saml2AuthenticationRequestResolver authenticationRequestResolver(RelyingPartyRegistrationRepository registrations) { RelyingPartyRegistrationResolver registrationResolver = new DefaultRelyingPartyRegistrationResolver(registrations); - OpenSaml4AuthenticationRequestResolver authenticationRequestResolver = - new OpenSaml4AuthenticationRequestResolver(registrationResolver); + OpenSaml5AuthenticationRequestResolver authenticationRequestResolver = + new OpenSaml5AuthenticationRequestResolver(registrationResolver); authenticationRequestResolver.setAuthnRequestCustomizer((context) -> context .getAuthnRequest().setForceAuthn(true)); return authenticationRequestResolver; diff --git a/src/test/java/org/eclipse/pass/file/service/storage/FileStorageServiceS3Test.java b/src/test/java/org/eclipse/pass/file/service/storage/FileStorageServiceS3Test.java index 7cdb305d..f2f24212 100644 --- a/src/test/java/org/eclipse/pass/file/service/storage/FileStorageServiceS3Test.java +++ b/src/test/java/org/eclipse/pass/file/service/storage/FileStorageServiceS3Test.java @@ -37,7 +37,7 @@ @ActiveProfiles("test-S3") class FileStorageServiceS3Test extends FileStorageServiceTest { private static final DockerImageName LOCALSTACK_IMG = - DockerImageName.parse("localstack/localstack:3.8.1"); + DockerImageName.parse("localstack/localstack:4.14.0"); private static final LocalStackContainer localStack = new LocalStackContainer(LOCALSTACK_IMG) diff --git a/src/test/java/org/eclipse/pass/main/AwsParamStoreConfigTest.java b/src/test/java/org/eclipse/pass/main/AwsParamStoreConfigTest.java index e220cc74..7fff7620 100644 --- a/src/test/java/org/eclipse/pass/main/AwsParamStoreConfigTest.java +++ b/src/test/java/org/eclipse/pass/main/AwsParamStoreConfigTest.java @@ -50,7 +50,7 @@ @Testcontainers class AwsParamStoreConfigTest { private static final DockerImageName LOCALSTACK_IMG = - DockerImageName.parse("localstack/localstack:3.8.1"); + DockerImageName.parse("localstack/localstack:4.14.0"); @Container private static final LocalStackContainer localStack = new LocalStackContainer(LOCALSTACK_IMG).withServices(SSM); diff --git a/src/test/java/org/eclipse/pass/main/security/SecurityRequestMatcherTest.java b/src/test/java/org/eclipse/pass/main/security/SecurityRequestMatcherTest.java new file mode 100644 index 00000000..64c96da1 --- /dev/null +++ b/src/test/java/org/eclipse/pass/main/security/SecurityRequestMatcherTest.java @@ -0,0 +1,125 @@ +/* + * Copyright 2026 Johns Hopkins University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.eclipse.pass.main.security; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.eclipse.pass.main.SimpleIntegrationTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests the request matchers in {@link SecurityConfiguration}: the CSRF rule that applies to GET requests + * under /doi/ and the Content-Security-Policy header that is only set under /app/. + */ +class SecurityRequestMatcherTest extends SimpleIntegrationTest { + private static final String CSP_HEADER = "Content-Security-Policy"; + + /** + * GET requests to the DOI service have side effects, so they must be rejected without a CSRF token. + * Includes variations with a trailing slash since these depend on how the path is matched. + * + * @param path request path relative to the base URL + * @throws IOException if the request fails + */ + @ParameterizedTest + @ValueSource(strings = {"doi", "doi/", "doi/journal", "doi/journal/", "doi/manuscript"}) + void doiGetWithoutCsrfTokenIsForbidden(String path) throws IOException { + try (Response response = get(newOkhttpClient(), path, null)) { + assertEquals(403, response.code(), "Expected CSRF rejection for GET /" + path); + } + } + + /** + * A GET to the DOI service with a valid CSRF token gets past the CSRF check. An invalid DOI is + * used so that no external service is called. + * + * @throws IOException if the request fails + */ + @Test + void doiGetWithCsrfTokenIsNotRejected() throws IOException { + OkHttpClient client = newOkhttpClient(); + String token = getCsrfToken(client); + try (Response response = get(client, "doi/journal?doi=moo", token)) { + assertEquals(400, response.code()); + } + } + + /** + * GET requests outside the DOI service do not need a CSRF token. This includes a path that only + * starts with the same characters as /doi. + * + * @param path request path relative to the base URL + * @throws IOException if the request fails + */ + @ParameterizedTest + @ValueSource(strings = {"data/grant", "doiother"}) + void nonDoiGetWithoutCsrfTokenIsNotForbidden(String path) throws IOException { + try (Response response = get(newOkhttpClient(), path, null)) { + assertNotEquals(403, response.code(), "Unexpected CSRF rejection for GET /" + path); + } + } + + /** + * The Content-Security-Policy header is set for requests under /app/, whatever the response status. + * + * @param path request path relative to the base URL + * @throws IOException if the request fails + */ + @ParameterizedTest + @ValueSource(strings = {"app", "app/", "app/index.html"}) + void cspHeaderIsSetUnderApp(String path) throws IOException { + try (Response response = get(newOkhttpClient(), path, null)) { + String csp = response.header(CSP_HEADER); + assertNotNull(csp, "Expected " + CSP_HEADER + " for GET /" + path); + assertTrue(csp.contains("default-src"), "Unexpected policy: " + csp); + } + } + + /** + * The Content-Security-Policy header is not set for requests outside /app/, including a path + * that only starts with the same characters as /app. + * + * @param path request path relative to the base URL + * @throws IOException if the request fails + */ + @ParameterizedTest + @ValueSource(strings = {"data/grant", "application", "doi/journal?doi=moo"}) + void cspHeaderIsNotSetOutsideApp(String path) throws IOException { + try (Response response = get(newOkhttpClient(), path, null)) { + assertNull(response.header(CSP_HEADER), "Unexpected " + CSP_HEADER + " for GET /" + path); + } + } + + private Response get(OkHttpClient client, String path, String csrfToken) throws IOException { + Request.Builder builder = new Request.Builder().url(getBaseUrl() + path) + .header("Authorization", BACKEND_CREDENTIALS); + if (csrfToken != null) { + builder.header("X-XSRF-TOKEN", csrfToken); + } + return client.newCall(builder.get().build()).execute(); + } +}