feat(core): add opt-in Private Network Access for CORS preflights (#1530)

This commit is contained in:
Jongsic Choi authored and GitHub committed 2026-06-25 00:56:42 -05:00
1 parent 05d050190e
commit 398535ed55
5 files changed
+95 -3

No files matched your search

@@ -41,6 +41,32 @@ class GlobalCorsFilterIntegrationTest {
.header("Vary", containsString("Origin"));
}
@Test
void preflightRequestingPrivateNetworkAccessIsGranted() {
given()
.header("Origin", "http://localhost:3000")
.header("Access-Control-Request-Method", "POST")
.header("Access-Control-Request-Private-Network", "true")
.when()
.options("/")
.then()
.statusCode(204)
.header("Access-Control-Allow-Origin", equalTo("http://localhost:3000"))
.header("Access-Control-Allow-Private-Network", equalTo("true"));
}
@Test
void preflightWithoutPrivateNetworkRequestOmitsAllowHeader() {
given()
.header("Origin", "http://localhost:3000")
.header("Access-Control-Request-Method", "POST")
.when()
.options("/")
.then()
.statusCode(204)
.header("Access-Control-Allow-Private-Network", nullValue());
}
@Test
void actualRequestFromExtraAllowedOriginGetsCorsHeaders() {
given()
@@ -77,7 +103,40 @@ class GlobalCorsFilterIntegrationTest {
return Map.of(
"floci.security.extra-cors-allowed-origins", "http://localhost:3000,https://ui.example.test",
"floci.security.extra-cors-allowed-headers", "x-added-header",
"floci.security.extra-cors-expose-headers", "x-visible-header");
"floci.security.extra-cors-expose-headers", "x-visible-header",
"floci.security.cors-allow-private-network", "true");
}
}
@QuarkusTest
@TestProfile(PrivateNetworkDefaultOffTest.CorsPnaDefaultProfile.class)
static class PrivateNetworkDefaultOffTest {
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void privateNetworkAccessNotGrantedByDefault() {
given()
.header("Origin", "http://localhost:3000")
.header("Access-Control-Request-Method", "POST")
.header("Access-Control-Request-Private-Network", "true")
.when()
.options("/")
.then()
.statusCode(204)
.header("Access-Control-Allow-Origin", equalTo("http://localhost:3000"))
.header("Access-Control-Allow-Private-Network", nullValue());
}
// Only origins set — cors-allow-private-network left at its (off) default.
public static final class CorsPnaDefaultProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of("floci.security.extra-cors-allowed-origins", "http://localhost:3000");
}
}
}
}