This is an automated email from the ASF dual-hosted git repository.
sergehuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new 2442ed817 Limit credentialed CORS on admin REST and GraphQL to listed
origins (#952)
2442ed817 is described below
commit 2442ed81757cfa31c2045e5389331c48661a6951
Author: Serge Huber <[email protected]>
AuthorDate: Thu Nov 12 08:33:34 2026 +0100
Limit credentialed CORS on admin REST and GraphQL to listed origins (#952)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
THREAT_MODEL.md | 1 +
.../unomi/api/services/AdminCorsService.java | 33 ++++++
.../unomi/geonames/rest/GeonamesEndPoint.java | 2 +-
.../groovy/actions/rest/GroovyActionsEndPoint.java | 2 +-
.../unomi/schema/rest/JsonSchemaEndPoint.java | 2 +-
.../unomi/lists/rest/UserListServiceEndPoint.java | 2 +-
.../unomi/privacy/rest/PrivacyServiceEndPoint.java | 2 +-
.../rest/ExportConfigurationServiceEndPoint.java | 2 +-
.../rest/ImportConfigurationServiceEndPoint.java | 2 +-
.../org/apache/unomi/sfdc/rest/SFDCEndPoint.java | 2 +-
.../unomi/graphql/servlet/GraphQLServlet.java | 31 ++++--
.../unomi/graphql/servlet/GraphQLServletTest.java | 51 ++++++++++
manual/src/main/asciidoc/configuration.adoc | 16 +++
.../asciidoc/migrations/migrate-3.0-to-4.0.adoc | 4 +
.../main/resources/etc/custom.system.properties | 4 +
.../apache/unomi/rest/cors/AdminCorsSettings.java | 85 ++++++++++++++++
.../unomi/rest/cors/PublicTrackerCorsFilter.java | 65 ++++++++----
.../unomi/rest/cors/PublicTrackerCorsPolicy.java | 2 +-
.../rest/endpoints/CampaignsServiceEndPoint.java | 2 +-
.../rest/endpoints/ClusterServiceEndPoint.java | 2 +-
.../rest/endpoints/DefinitionsServiceEndPoint.java | 2 +-
.../unomi/rest/endpoints/EventServiceEndpoint.java | 2 +-
.../unomi/rest/endpoints/GoalsServiceEndPoint.java | 2 +-
.../unomi/rest/endpoints/PatchServiceEndPoint.java | 2 +-
.../rest/endpoints/ProfileServiceEndPoint.java | 2 +-
.../unomi/rest/endpoints/QueryServiceEndPoint.java | 2 +-
.../unomi/rest/endpoints/RulesServiceEndPoint.java | 2 +-
.../unomi/rest/endpoints/ScopeServiceEndPoint.java | 2 +-
.../rest/endpoints/ScoringServiceEndPoint.java | 2 +-
.../rest/endpoints/SegmentServiceEndPoint.java | 2 +-
.../apache/unomi/rest/endpoints/TestEndPoint.java | 2 +-
.../rest/endpoints/UserListServiceEndPoint.java | 2 +-
.../apache/unomi/rest/scheduler/TaskEndpoint.java | 2 +-
.../org/apache/unomi/rest/server/RestServer.java | 16 ++-
.../apache/unomi/rest/tenants/TenantEndpoint.java | 2 +-
.../rest/config/ShippedAdminCorsConfigTest.java | 59 +++++++++++
.../unomi/rest/cors/AdminCorsSettingsTest.java | 112 +++++++++++++++++++++
.../rest/cors/PublicTrackerCorsFilterTest.java | 68 ++++++++++++-
.../unomi/rest/cors/PublicTrackerSettingsTest.java | 4 +-
.../unomi/rest/endpoints/AdminRestCorsTest.java | 60 +++++++++++
.../org/apache/unomi/web/servlets/WebConfig.java | 6 ++
.../src/main/resources/org.apache.unomi.web.cfg | 3 +
.../apache/unomi/web/servlets/WebConfigTest.java | 3 +
43 files changed, 608 insertions(+), 63 deletions(-)
diff --git a/THREAT_MODEL.md b/THREAT_MODEL.md
index e39ce6145..0e1a8b660 100644
--- a/THREAT_MODEL.md
+++ b/THREAT_MODEL.md
@@ -128,6 +128,7 @@ Per-surface trust table *(all inferred unless noted):*
- Secure the Elasticsearch/OpenSearch backend + its network. *(inferred)*
- Restrict who holds condition/rule/scripting authoring authority — it is
equivalent to server-side code definition. *(inferred)*
- Put the public endpoint behind rate-limiting / a CDN/WAF appropriate to
public exposure. *(inferred)*
+- **CORS:** public tracker credentialed CORS (visitor cookie) is opt-in via
`org.apache.unomi.public.cors.allowedOrigins` (and optional tenant lists).
Admin REST/GraphQL credentialed CORS (operator Basic auth in the browser) is a
separate opt-in via `org.apache.unomi.admin.cors.allowedOrigins`; the default
is empty. Same-origin admin UIs need no entry. CORS response headers alone do
not stop simple credentialed **writes** from another origin — keep the admin UI
same-origin or add CSRF controls.
## §11 Known misuse patterns
diff --git
a/api/src/main/java/org/apache/unomi/api/services/AdminCorsService.java
b/api/src/main/java/org/apache/unomi/api/services/AdminCorsService.java
new file mode 100644
index 000000000..ed68db5a1
--- /dev/null
+++ b/api/src/main/java/org/apache/unomi/api/services/AdminCorsService.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.unomi.api.services;
+
+/**
+ * Origins that may use credentialed CORS against the admin REST API and
GraphQL. The default list is
+ * empty: cross-origin browsers do not get {@code
Access-Control-Allow-Credentials} on those surfaces
+ * until the operator lists the admin UI origin.
+ */
+public interface AdminCorsService {
+
+ /**
+ * Whether a browser {@code Origin} is listed for credentialed admin CORS.
+ *
+ * @param origin the request {@code Origin} header, may be {@code null}
+ * @return {@code true} only when the origin is present and listed
+ */
+ boolean allows(String origin);
+}
diff --git
a/extensions/geonames/rest/src/main/java/org/apache/unomi/geonames/rest/GeonamesEndPoint.java
b/extensions/geonames/rest/src/main/java/org/apache/unomi/geonames/rest/GeonamesEndPoint.java
index 9bb5bf25a..a8684a8f0 100644
---
a/extensions/geonames/rest/src/main/java/org/apache/unomi/geonames/rest/GeonamesEndPoint.java
+++
b/extensions/geonames/rest/src/main/java/org/apache/unomi/geonames/rest/GeonamesEndPoint.java
@@ -40,7 +40,7 @@ import java.util.Locale;
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/geonames")
@Component(service=GeonamesEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/extensions/groovy-actions/rest/src/main/java/org/apache/unomi/groovy/actions/rest/GroovyActionsEndPoint.java
b/extensions/groovy-actions/rest/src/main/java/org/apache/unomi/groovy/actions/rest/GroovyActionsEndPoint.java
index 635dfe3d4..0a8b05f93 100644
---
a/extensions/groovy-actions/rest/src/main/java/org/apache/unomi/groovy/actions/rest/GroovyActionsEndPoint.java
+++
b/extensions/groovy-actions/rest/src/main/java/org/apache/unomi/groovy/actions/rest/GroovyActionsEndPoint.java
@@ -35,7 +35,7 @@ import javax.ws.rs.core.Response;
import java.io.IOException;
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
-@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = true)
+@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = false)
@Path("/groovyActions")
@RequiresRole(UnomiRoles.ADMINISTRATOR)
@Component(service = GroovyActionsEndPoint.class, property =
"osgi.jaxrs.resource=true")
diff --git
a/extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java
b/extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java
index 2c221d0d3..6bdc3b74f 100644
---
a/extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java
+++
b/extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java
@@ -35,7 +35,7 @@ import java.util.Map;
import java.util.Set;
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
-@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = true)
+@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = false)
@Path("/jsonSchema")
@Component(service = JsonSchemaEndPoint.class, property =
"osgi.jaxrs.resource=true")
public class JsonSchemaEndPoint {
diff --git
a/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java
b/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java
index b151398e6..59d7c5ee4 100644
---
a/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java
+++
b/extensions/lists-extension/rest/src/main/java/org/apache/unomi/lists/rest/UserListServiceEndPoint.java
@@ -38,7 +38,7 @@ import javax.ws.rs.core.MediaType;
@Produces(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/lists")
@Component(service=UserListServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java
b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java
index defe0dcc1..aca43bede 100644
---
a/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java
+++
b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java
@@ -35,7 +35,7 @@ import java.util.List;
@Produces(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/privacy")
@Component(service=PrivacyServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
index db02500ec..ffe43ff1a 100644
---
a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
+++
b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
@@ -49,7 +49,7 @@ import java.util.List;
*/
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/exportConfiguration")
@RequiresRole(UnomiRoles.ADMINISTRATOR)
diff --git
a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
index 2fba3797b..96b605d25 100644
---
a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
+++
b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
@@ -55,7 +55,7 @@ import java.util.List;
*/
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/importConfiguration")
@RequiresRole(UnomiRoles.ADMINISTRATOR)
diff --git
a/extensions/salesforce-connector/rest/src/main/java/org/apache/unomi/sfdc/rest/SFDCEndPoint.java
b/extensions/salesforce-connector/rest/src/main/java/org/apache/unomi/sfdc/rest/SFDCEndPoint.java
index e68239bc4..9bbc4d3d0 100644
---
a/extensions/salesforce-connector/rest/src/main/java/org/apache/unomi/sfdc/rest/SFDCEndPoint.java
+++
b/extensions/salesforce-connector/rest/src/main/java/org/apache/unomi/sfdc/rest/SFDCEndPoint.java
@@ -40,7 +40,7 @@ import java.util.Map;
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/sfdc")
@Component(service=SFDCEndPoint.class,property = "osgi.jaxrs.resource=true")
diff --git
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
index cf4e8e26d..c76aab10c 100644
---
a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
+++
b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/servlet/GraphQLServlet.java
@@ -23,6 +23,7 @@ import graphql.GraphQL;
import graphql.introspection.IntrospectionQuery;
import org.apache.unomi.api.ExecutionContext;
import org.apache.unomi.api.security.SecurityService;
+import org.apache.unomi.api.services.AdminCorsService;
import org.apache.unomi.api.services.ExecutionContextManager;
import org.apache.unomi.api.tenants.AdminTenantConfig;
import org.apache.unomi.api.tenants.TenantService;
@@ -68,6 +69,8 @@ public class GraphQLServlet extends WebSocketServlet {
private AdminTenantConfig adminTenantConfig;
+ private AdminCorsService adminCorsService;
+
private GraphQLServletSecurityValidator validator;
@Reference
@@ -75,6 +78,13 @@ public class GraphQLServlet extends WebSocketServlet {
this.serviceManager = serviceManager;
}
+ // Mandatory: an optional static reference is never bound if the rest
bundle registers it later,
+ // which would silently refuse every listed admin origin.
+ @Reference
+ public void setAdminCorsService(AdminCorsService adminCorsService) {
+ this.adminCorsService = adminCorsService;
+ }
+
@Reference
public void setAdminTenantConfig(AdminTenantConfig adminTenantConfig) {
this.adminTenantConfig = adminTenantConfig;
@@ -390,17 +400,20 @@ public class GraphQLServlet extends WebSocketServlet {
}
HttpServletResponse httpServletResponse = (HttpServletResponse)
response;
-
- httpServletResponse.setHeader("Access-Control-Allow-Origin",
getOriginHeaderFromRequest(httpServletRequest));
- httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin,
X-Requested-With, Content-Type, Accept, X-Apollo-Tracing");
+ String origin = httpServletRequest != null ?
httpServletRequest.getHeader("Origin") : null;
+ if (origin == null) {
+ // Same-origin or non-browser: no CORS headers needed.
+ return;
+ }
+ if (adminCorsService == null || !adminCorsService.allows(origin)) {
+ // Fail closed: unlisted cross-origin callers get no CORS grant.
+ return;
+ }
+ httpServletResponse.setHeader("Access-Control-Allow-Origin", origin);
+ httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin,
X-Requested-With, Content-Type, Accept, X-Apollo-Tracing, Authorization");
httpServletResponse.setHeader("Access-Control-Allow-Credentials",
"true");
httpServletResponse.setHeader("Access-Control-Allow-Methods",
"OPTIONS, POST, GET");
- }
-
- private String getOriginHeaderFromRequest(final HttpServletRequest
httpServletRequest) {
- return httpServletRequest != null &&
httpServletRequest.getHeader("Origin") != null
- ? httpServletRequest.getHeader("Origin")
- : "*";
+ httpServletResponse.addHeader("Vary", "Origin");
}
private void cleanupSecurityContext() {
diff --git
a/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
b/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
index a6dab3341..fcf8259b6 100644
---
a/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
+++
b/graphql/cxs-impl/src/test/java/org/apache/unomi/graphql/servlet/GraphQLServletTest.java
@@ -45,6 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
@@ -256,6 +257,56 @@ class GraphQLServletTest {
/**
* Overrides HTTP fall-through so tests can assert upgrade failures never
reach it.
*/
+ /** A listed admin UI origin gets credentialed CORS, named explicitly and
varying on Origin. */
+ @Test
+ void cors_listedOrigin_getsCredentials() throws Exception {
+ servlet.setAdminCorsService("https://admin.example"::equals);
+ when(request.getHeader("Origin")).thenReturn("https://admin.example");
+
+ servlet.doOptions(request, response);
+
+ verify(response).setHeader("Access-Control-Allow-Origin",
"https://admin.example");
+ verify(response).setHeader("Access-Control-Allow-Credentials", "true");
+ verify(response).setHeader(eq("Access-Control-Allow-Headers"),
contains("Authorization"));
+ verify(response).addHeader("Vary", "Origin");
+ }
+
+ /** An unlisted origin gets no CORS grant at all: the browser then refuses
to expose the response. */
+ @Test
+ void cors_unlistedOrigin_getsNoCorsHeaders() throws Exception {
+ servlet.setAdminCorsService("https://admin.example"::equals);
+
when(request.getHeader("Origin")).thenReturn("https://evil.example.com");
+
+ servlet.doOptions(request, response);
+
+ verify(response, never()).setHeader(anyString(), anyString());
+ verify(response, never()).addHeader(anyString(), anyString());
+ }
+
+ /** No Origin (same-origin GET or a non-browser client): no CORS headers
are needed. */
+ @Test
+ void cors_noOrigin_getsNoCorsHeaders() throws Exception {
+ servlet.setAdminCorsService(origin -> true);
+ when(request.getHeader("Origin")).thenReturn(null);
+
+ servlet.doOptions(request, response);
+
+ verify(response, never()).setHeader(anyString(), anyString());
+ verify(response, never()).addHeader(anyString(), anyString());
+ }
+
+ /** Before 4.0 any origin was echoed with credentials; the default empty
list must no longer do that. */
+ @Test
+ void cors_emptyList_neverEchoesOrigin() throws Exception {
+ servlet.setAdminCorsService(origin -> false);
+ when(request.getHeader("Origin")).thenReturn("https://admin.example");
+
+ servlet.doOptions(request, response);
+
+ verify(response, never()).setHeader(eq("Access-Control-Allow-Origin"),
anyString());
+ verify(response,
never()).setHeader(eq("Access-Control-Allow-Credentials"), anyString());
+ }
+
private static final class TrackingGraphQLServlet extends GraphQLServlet {
private final AtomicBoolean nonUpgradeCalled = new
AtomicBoolean(false);
diff --git a/manual/src/main/asciidoc/configuration.adoc
b/manual/src/main/asciidoc/configuration.adoc
index 4aa8c00b8..cef9b3e48 100644
--- a/manual/src/main/asciidoc/configuration.adoc
+++ b/manual/src/main/asciidoc/configuration.adoc
@@ -743,6 +743,22 @@ Other behaviour that changed:
A deployment that does not need the visitor cookie can set `sendCredentials:
false` in the tracker's `wemInitConfig` (tracker 2.0.0 or later, see
<<_unomi_web_tracker_reference,the web tracker>>). Requests are then sent
without cookies and work with the default settings, but each request starts a
new anonymous profile.
+[[_admin_cors_origins]]
+==== Admin UI origins (credentialed CORS)
+
+The admin REST API under `/cxs` (other than the public tracker endpoints
above) and GraphQL under `/graphql` do not advertise credentialed CORS by
default. A browser on another origin therefore cannot read admin responses
using the operator's HTTP Basic credentials.
+
+If an admin UI is served from a different origin than Unomi, list that origin:
+
+[source]
+----
+org.apache.unomi.admin.cors.allowedOrigins=${env:UNOMI_ADMIN_CORS_ALLOWED_ORIGINS:-}
+----
+
+Example: `https://admin.example.com`. Same-origin deployments (a reverse proxy
serving the UI and Unomi together) need no entry. This list is separate from
`org.apache.unomi.public.cors.allowedOrigins`, which only covers the visitor
cookie on public tracker endpoints.
+
+This list covers HTTP requests only. GraphQL subscriptions over WebSocket
accept only handshakes from the same host as Unomi (or with no `Origin`),
whether or not the origin is listed here.
+
=== Scripting security
==== Multi-layer scripting filtering system
diff --git a/manual/src/main/asciidoc/migrations/migrate-3.0-to-4.0.adoc
b/manual/src/main/asciidoc/migrations/migrate-3.0-to-4.0.adoc
index 32267c552..2eef06f6e 100644
--- a/manual/src/main/asciidoc/migrations/migrate-3.0-to-4.0.adoc
+++ b/manual/src/main/asciidoc/migrations/migrate-3.0-to-4.0.adoc
@@ -463,6 +463,10 @@ In addition to tenant API keys, Unomi 4.0 hardens several
contracts that can bre
|Public endpoints answered any origin with credentialed CORS and never checked
where a request came from. A page on another subdomain could use the visitor
cookie. A website on another site never received it (the cookie was always
`SameSite=Lax`), so it kept the profile id itself and sent it as body
`profileId`.
|Only origins listed in `org.apache.unomi.public.cors.allowedOrigins`
(`UNOMI_PUBLIC_CORS_ALLOWED_ORIGINS`), or in the requesting tenant's
`publicCorsAllowedOrigins` property, get credentialed CORS and have the cookie
used and set; other pages get a new anonymous profile and their cookie is left
untouched. The default is empty. A website served from Unomi's own origin
through a reverse proxy needs no change. One on another subdomain must be
listed. One on another site must be listed and, [...]
+|Admin UI on another origin
+|Admin REST and GraphQL answered any origin with credentialed CORS, so a page
on another site could reuse the operator's browser credentials to read admin
responses.
+|Only origins listed in `org.apache.unomi.admin.cors.allowedOrigins`
(`UNOMI_ADMIN_CORS_ALLOWED_ORIGINS`) get credentialed CORS on admin REST and
GraphQL. The default is empty. A same-origin admin UI needs no change. See
<<_admin_cors_origins,Admin UI origins>>.
+
|Profile cookie `HttpOnly`
|Often defaulted to `false` (JS could read `document.cookie`)
|Default **`true`**. Prefer `profileId` from the JSON response. Opt out with
`org.apache.unomi.profile.cookie.httpOnly=false` only if you accept the
tradeoff.
diff --git a/package/src/main/resources/etc/custom.system.properties
b/package/src/main/resources/etc/custom.system.properties
index 7960fa1ea..29c4664ee 100644
--- a/package/src/main/resources/etc/custom.system.properties
+++ b/package/src/main/resources/etc/custom.system.properties
@@ -350,6 +350,10 @@
org.apache.unomi.public.cors.matchReferer=${env:UNOMI_PUBLIC_CORS_MATCH_REFERER:
# administrator through /cxs/tenants). Tenant origins only apply to requests
made with that tenant's key.
# Only false turns this off.
org.apache.unomi.public.cors.tenantOrigins=${env:UNOMI_PUBLIC_CORS_TENANT_ORIGINS:-true}
+# Origins of admin UIs that may use credentialed CORS against the admin REST
API and GraphQL.
+# Example: https://admin.example.com
+# Leave empty (the default) so no other origin may reuse the operator's
browser credentials cross-origin.
+org.apache.unomi.admin.cors.allowedOrigins=${env:UNOMI_ADMIN_CORS_ALLOWED_ORIGINS:-}
#Allowed profile download formats, actually only csv (horizontal and
vertical), json, text and yaml are allowed.
org.apache.unomi.profile.download.formats=${env:UNOMI_PROFILE_DOWNLOAD_FORMATS:-csv,yaml,json,text}
# This setting allow for request size (Content-length) protection. Checking
that the requests do not exceed the limit.
diff --git
a/rest/src/main/java/org/apache/unomi/rest/cors/AdminCorsSettings.java
b/rest/src/main/java/org/apache/unomi/rest/cors/AdminCorsSettings.java
new file mode 100644
index 000000000..bbb132a4f
--- /dev/null
+++ b/rest/src/main/java/org/apache/unomi/rest/cors/AdminCorsSettings.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.unomi.rest.cors;
+
+import org.apache.unomi.api.services.AdminCorsService;
+import org.apache.unomi.api.services.ConfigSharingService;
+import org.apache.unomi.api.services.ConfigSharingService.ConfigChangeEvent;
+import org.apache.unomi.api.services.ConfigSharingService.ConfigChangeListener;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Operator allow-list of origins that may use credentialed CORS against admin
REST and GraphQL.
+ * Published by {@code WebConfig} through {@link ConfigSharingService}; parsed
when set, not per request.
+ */
+@Component(service = {AdminCorsSettings.class, AdminCorsService.class,
ConfigChangeListener.class})
+public class AdminCorsSettings implements AdminCorsService,
ConfigChangeListener {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(AdminCorsSettings.class);
+
+ /** ConfigSharingService key published by WebConfig from
org.apache.unomi.admin.cors.allowedOrigins. */
+ public static final String ALLOWED_ORIGINS_PROPERTY =
"adminCorsAllowedOrigins";
+
+ @Reference
+ private ConfigSharingService configSharingService;
+
+ private volatile PublicTrackerCorsPolicy policy =
PublicTrackerCorsPolicy.parse(null);
+
+ /** Used by OSGi Declarative Services. */
+ public AdminCorsSettings() {
+ }
+
+ /** For tests. */
+ public AdminCorsSettings(String allowedOrigins) {
+ this.policy = PublicTrackerCorsPolicy.parse(allowedOrigins);
+ }
+
+ @Activate
+ void activate() {
+ reload();
+ }
+
+ @Override
+ public void configChanged(ConfigChangeEvent event) {
+ if (ALLOWED_ORIGINS_PROPERTY.equals(event.getName())) {
+ reload();
+ }
+ }
+
+ private synchronized void reload() {
+ List<String> warnings = new ArrayList<>();
+ Object raw =
configSharingService.getProperty(ALLOWED_ORIGINS_PROPERTY);
+ String configured = raw == null ? null : String.valueOf(raw);
+ PublicTrackerCorsPolicy next =
PublicTrackerCorsPolicy.parse(configured, false, warnings);
+ for (String warning : warnings) {
+ LOGGER.warn(warning);
+ }
+ this.policy = next;
+ }
+
+ @Override
+ public boolean allows(String origin) {
+ return policy.allows(origin);
+ }
+}
diff --git
a/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilter.java
b/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilter.java
index 4af2e5d73..c75c9f514 100644
--- a/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilter.java
+++ b/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilter.java
@@ -24,14 +24,16 @@ import javax.ws.rs.core.MultivaluedMap;
import java.util.List;
/**
- * CXF's CORS filter, with cookies allowed on public tracker responses only
for origins the operator listed.
+ * CXF's CORS filter, with credentials only for origins the operator listed.
* <p>
- * CXF answers preflights and grants the public tracker endpoints to any
origin without credentials. This
- * subclass rewrites that grant right after CXF writes it, in the same
response filter call, so the result
- * does not depend on filter ordering. That matters because CXF 3.x only reads
{@code javax.annotation.Priority}:
- * a separate filter annotated with {@code jakarta.annotation.Priority} gets
the default priority and runs
- * before CXF's, which then overwrites it. Request handling, {@code
@PreMatching} and the priority are CXF's own.
- * A response CXF did not grant is left alone.
+ * On public tracker paths, CXF answers preflights and grants any origin
without credentials; this
+ * subclass upgrades listed origins to credentialed CORS (visitor cookie). On
other (admin) paths,
+ * annotations advertise no credentials by default; listed admin UI origins
are upgraded the same way.
+ * <p>
+ * Rewrites run in the same response filter call as CXF's grant so the result
does not depend on filter
+ * ordering. That matters because CXF 3.x only reads {@code
javax.annotation.Priority}: a separate filter
+ * annotated with {@code jakarta.annotation.Priority} gets the default
priority and runs before CXF's,
+ * which then overwrites it. A response CXF did not grant is left alone.
*/
public class PublicTrackerCorsFilter extends CrossOriginResourceSharingFilter {
@@ -39,12 +41,20 @@ public class PublicTrackerCorsFilter extends
CrossOriginResourceSharingFilter {
static final String ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
private final PublicTrackerSettings settings;
+ private final AdminCorsSettings adminCors;
/**
- * @param settings the resolved list of website origins that may use the
visitor cookie
+ * @param settings the resolved list of website origins that may use the
visitor cookie
+ * @param adminCors the resolved list of origins that may use credentialed
admin CORS
*/
- public PublicTrackerCorsFilter(PublicTrackerSettings settings) {
+ public PublicTrackerCorsFilter(PublicTrackerSettings settings,
AdminCorsSettings adminCors) {
this.settings = settings;
+ this.adminCors = adminCors;
+ }
+
+ /** For tests that only cover the public tracker path. */
+ public PublicTrackerCorsFilter(PublicTrackerSettings settings) {
+ this(settings, new AdminCorsSettings(null));
}
@Override
@@ -54,37 +64,50 @@ public class PublicTrackerCorsFilter extends
CrossOriginResourceSharingFilter {
}
void restrictCredentials(ContainerRequestContext requestContext,
ContainerResponseContext responseContext) {
- if (!isPublic(requestContext)) {
- return;
- }
String origin = requestContext.getHeaderString("Origin");
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
if (origin == null || !headers.containsKey(ALLOW_ORIGIN)) {
return;
}
- if (allowsCredentials(requestContext, origin)) {
- headers.putSingle(ALLOW_ORIGIN, origin);
- headers.putSingle(ALLOW_CREDENTIALS, "true");
- if (!variesOnOrigin(headers)) {
- headers.add("Vary", "Origin");
+ if (isPublic(requestContext)) {
+ if (allowsPublicCredentials(requestContext, origin)) {
+ grantCredentials(headers, origin);
+ return;
}
+ denyCredentials(headers);
return;
}
- // Never echo an unlisted origin and never advertise cookies to it.
- headers.putSingle(ALLOW_ORIGIN, "*");
- headers.remove(ALLOW_CREDENTIALS);
+ if (adminCors.allows(origin)) {
+ grantCredentials(headers, origin);
+ return;
+ }
+ denyCredentials(headers);
}
/**
* A preflight carries no API key, so any origin the operator or a tenant
lists is accepted there; the
* actual request, which carries the key, is checked against its own
tenant.
*/
- private boolean allowsCredentials(ContainerRequestContext requestContext,
String origin) {
+ private boolean allowsPublicCredentials(ContainerRequestContext
requestContext, String origin) {
boolean preflight = "OPTIONS".equals(requestContext.getMethod())
&&
requestContext.getHeaderString("Access-Control-Request-Method") != null;
return preflight ? settings.allowsPreflight(origin) :
settings.policyForTenant(requestTenantId()).allows(origin);
}
+ private static void grantCredentials(MultivaluedMap<String, Object>
headers, String origin) {
+ headers.putSingle(ALLOW_ORIGIN, origin);
+ headers.putSingle(ALLOW_CREDENTIALS, "true");
+ if (!variesOnOrigin(headers)) {
+ headers.add("Vary", "Origin");
+ }
+ }
+
+ private static void denyCredentials(MultivaluedMap<String, Object>
headers) {
+ // Never echo an unlisted origin and never advertise cookies / Basic
reuse to it.
+ headers.putSingle(ALLOW_ORIGIN, "*");
+ headers.remove(ALLOW_CREDENTIALS);
+ }
+
/** The tenant of the current request; replaced in tests. */
String requestTenantId() {
return RequestTenant.id();
diff --git
a/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsPolicy.java
b/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsPolicy.java
index 86d9f540b..3faad2cd3 100644
--- a/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsPolicy.java
+++ b/rest/src/main/java/org/apache/unomi/rest/cors/PublicTrackerCorsPolicy.java
@@ -73,7 +73,7 @@ public final class PublicTrackerCorsPolicy {
}
String origin = normalizeEntry(entry);
if (origin == null) {
- warnings.add("Ignoring public CORS allowed origin '" + entry +
"': expected scheme://host[:port] "
+ warnings.add("Ignoring CORS allowed origin '" + entry + "':
expected scheme://host[:port] "
+ "with http or https, no path and no wildcard");
continue;
}
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/CampaignsServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/CampaignsServiceEndPoint.java
index 91397d3ac..45cd19c4f 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/CampaignsServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/CampaignsServiceEndPoint.java
@@ -42,7 +42,7 @@ import java.util.Set;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/campaigns")
@Component(service=CampaignsServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java
index 05b3ee935..d34363358 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ClusterServiceEndPoint.java
@@ -39,7 +39,7 @@ import java.util.List;
@Produces(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/cluster")
@Component(service=ClusterServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/DefinitionsServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/DefinitionsServiceEndPoint.java
index 42522a745..a62341b20 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/DefinitionsServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/DefinitionsServiceEndPoint.java
@@ -41,7 +41,7 @@ import java.util.*;
@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/definitions")
@Component(service=DefinitionsServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/EventServiceEndpoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/EventServiceEndpoint.java
index bff09b231..812c71aec 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/EventServiceEndpoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/EventServiceEndpoint.java
@@ -35,7 +35,7 @@ import java.util.Set;
@Produces(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/events")
@Component(service=EventServiceEndpoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/GoalsServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/GoalsServiceEndPoint.java
index f5a3c15b1..2c6e59076 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/GoalsServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/GoalsServiceEndPoint.java
@@ -39,7 +39,7 @@ import java.util.Set;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/goals")
@Component(service=GoalsServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/PatchServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/PatchServiceEndPoint.java
index 00429f82e..94d66ecd1 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/PatchServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/PatchServiceEndPoint.java
@@ -33,7 +33,7 @@ import javax.ws.rs.core.MediaType;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/patches")
@Component(service=PatchServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ProfileServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ProfileServiceEndPoint.java
index 305a7bb55..2f31eeeed 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ProfileServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ProfileServiceEndPoint.java
@@ -49,7 +49,7 @@ import java.util.*;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/profiles")
@Component(service=ProfileServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/QueryServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/QueryServiceEndPoint.java
index 36b5a5fa3..d19f0743f 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/QueryServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/QueryServiceEndPoint.java
@@ -42,7 +42,7 @@ import java.util.Map;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/query")
@Component(service=QueryServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/RulesServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/RulesServiceEndPoint.java
index 018afb51f..3e85a4dcd 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/RulesServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/RulesServiceEndPoint.java
@@ -41,7 +41,7 @@ import java.util.Set;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/rules")
@Component(service=RulesServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ScopeServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ScopeServiceEndPoint.java
index 6b0a5b4df..f057138ab 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ScopeServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ScopeServiceEndPoint.java
@@ -35,7 +35,7 @@ import java.util.List;
*/
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
-@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = true)
+@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = false)
@Path("/scopes")
@Component(service = ScopeServiceEndPoint.class, property =
"osgi.jaxrs.resource=true")
public class ScopeServiceEndPoint {
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ScoringServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ScoringServiceEndPoint.java
index a5315c798..3eb61c853 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/ScoringServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/ScoringServiceEndPoint.java
@@ -41,7 +41,7 @@ import java.util.List;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/scoring")
@Component(service=ScoringServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
index f6b19ac3c..560f2e169 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/SegmentServiceEndPoint.java
@@ -41,7 +41,7 @@ import java.util.List;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/segments")
@Component(service=SegmentServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/TestEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/TestEndPoint.java
index 29f90efca..c9f53844b 100644
--- a/rest/src/main/java/org/apache/unomi/rest/endpoints/TestEndPoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/endpoints/TestEndPoint.java
@@ -33,7 +33,7 @@ import javax.ws.rs.core.MediaType;
*/
@Produces(MediaType.TEXT_PLAIN + ";charset=UTF-8")
@Path("/test")
-@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = true)
+@CrossOriginResourceSharing(allowAllOrigins = true, allowCredentials = false)
@Component(service = TestEndPoint.class, property = "osgi.jaxrs.resource=true")
public class TestEndPoint {
diff --git
a/rest/src/main/java/org/apache/unomi/rest/endpoints/UserListServiceEndPoint.java
b/rest/src/main/java/org/apache/unomi/rest/endpoints/UserListServiceEndPoint.java
index c79ac9fd3..72653b2c6 100644
---
a/rest/src/main/java/org/apache/unomi/rest/endpoints/UserListServiceEndPoint.java
+++
b/rest/src/main/java/org/apache/unomi/rest/endpoints/UserListServiceEndPoint.java
@@ -39,7 +39,7 @@ import java.util.List;
@Consumes(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Path("/userList")
@Component(service=UserListServiceEndPoint.class,property =
"osgi.jaxrs.resource=true")
diff --git
a/rest/src/main/java/org/apache/unomi/rest/scheduler/TaskEndpoint.java
b/rest/src/main/java/org/apache/unomi/rest/scheduler/TaskEndpoint.java
index 5fbba51f0..ae36312e1 100644
--- a/rest/src/main/java/org/apache/unomi/rest/scheduler/TaskEndpoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/scheduler/TaskEndpoint.java
@@ -37,7 +37,7 @@ import java.util.List;
@Produces(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Component(service = TaskEndpoint.class, property = "osgi.jaxrs.resource=true")
@Path("/tasks")
diff --git a/rest/src/main/java/org/apache/unomi/rest/server/RestServer.java
b/rest/src/main/java/org/apache/unomi/rest/server/RestServer.java
index e53bc7de0..a323c442b 100644
--- a/rest/src/main/java/org/apache/unomi/rest/server/RestServer.java
+++ b/rest/src/main/java/org/apache/unomi/rest/server/RestServer.java
@@ -39,6 +39,7 @@ import org.apache.unomi.api.tenants.ApiKey;
import org.apache.unomi.api.tenants.TenantService;
import org.apache.unomi.persistence.spi.CustomObjectMapper;
import org.apache.unomi.rest.cors.PublicTrackerCorsFilter;
+import org.apache.unomi.rest.cors.AdminCorsSettings;
import org.apache.unomi.rest.cors.PublicTrackerSettings;
import org.apache.unomi.rest.authentication.AuthenticationFilter;
import org.apache.unomi.rest.authentication.AuthorizingInterceptor;
@@ -85,6 +86,7 @@ public class RestServer {
private List<ExceptionMapper> exceptionMappers = new ArrayList<>();
private ConfigSharingService configSharingService;
private PublicTrackerSettings publicTrackerSettings;
+ private AdminCorsSettings adminCorsSettings;
private SchemaService schemaService;
private TenantService tenantService;
private SecurityService securityService;
@@ -149,6 +151,16 @@ public class RestServer {
this.publicTrackerSettings = publicTrackerSettings;
}
+ /**
+ * Sets the admin CORS origin allow-list.
+ *
+ * @param adminCorsSettings the parsed origins that may use credentialed
admin CORS
+ */
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ public void setAdminCorsSettings(AdminCorsSettings adminCorsSettings) {
+ this.adminCorsSettings = adminCorsSettings;
+ }
+
/**
* Sets the the tenant service.
*
@@ -412,8 +424,8 @@ public class RestServer {
jaxrsServerFactoryBean.setAddress("/");
jaxrsServerFactoryBean.setBus(serverBus);
jaxrsServerFactoryBean.setProvider(new
JacksonJaxbJsonProvider(objectMapper,
JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS));
- // CXF's CORS filter, restricted so that only listed origins may send
the visitor cookie.
- jaxrsServerFactoryBean.setProvider(new
PublicTrackerCorsFilter(publicTrackerSettings));
+ // CXF's CORS filter, restricted so that only listed origins get
credentialed CORS.
+ jaxrsServerFactoryBean.setProvider(new
PublicTrackerCorsFilter(publicTrackerSettings, adminCorsSettings));
jaxrsServerFactoryBean.setProvider(new
RetroCompatibilityParamConverterProvider(objectMapper));
// Authentication and Security filters in order of priority
diff --git
a/rest/src/main/java/org/apache/unomi/rest/tenants/TenantEndpoint.java
b/rest/src/main/java/org/apache/unomi/rest/tenants/TenantEndpoint.java
index 2dd4ad8e3..0f5bcbe45 100644
--- a/rest/src/main/java/org/apache/unomi/rest/tenants/TenantEndpoint.java
+++ b/rest/src/main/java/org/apache/unomi/rest/tenants/TenantEndpoint.java
@@ -48,7 +48,7 @@ import java.util.Map;
@Produces(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(
allowAllOrigins = true,
- allowCredentials = true
+ allowCredentials = false
)
@Component(service= TenantEndpoint.class,property = "osgi.jaxrs.resource=true")
@Path("/tenants")
diff --git
a/rest/src/test/java/org/apache/unomi/rest/config/ShippedAdminCorsConfigTest.java
b/rest/src/test/java/org/apache/unomi/rest/config/ShippedAdminCorsConfigTest.java
new file mode 100644
index 000000000..0cb0af249
--- /dev/null
+++
b/rest/src/test/java/org/apache/unomi/rest/config/ShippedAdminCorsConfigTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.unomi.rest.config;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Pins the shipped empty default for admin credentialed CORS origins.
+ */
+class ShippedAdminCorsConfigTest {
+
+ private static final String WEB_CFG_PATH =
"web-servlets/src/main/resources/org.apache.unomi.web.cfg";
+ private static final String SYSTEM_PROPERTIES_PATH =
"package/src/main/resources/etc/custom.system.properties";
+
+ @Test
+ void adminCorsOrigins_defaultToEmpty() throws Exception {
+ String webCfg = Files.readString(repoFile(WEB_CFG_PATH));
+
assertTrue(webCfg.contains("admin.cors.allowedOrigins=${org.apache.unomi.admin.cors.allowedOrigins:-}"),
+ "admin CORS origin list should default to empty in " +
WEB_CFG_PATH);
+
+ String systemProperties =
Files.readString(repoFile(SYSTEM_PROPERTIES_PATH));
+ assertTrue(systemProperties.contains(
+
"org.apache.unomi.admin.cors.allowedOrigins=${env:UNOMI_ADMIN_CORS_ALLOWED_ORIGINS:-}"),
+ "admin CORS origin list should default to empty and be
reachable from the environment");
+ }
+
+ private static Path repoFile(String relativePath) throws IOException {
+ Path candidate = Paths.get("").toAbsolutePath();
+ while (candidate != null) {
+ if (Files.isRegularFile(candidate.resolve(WEB_CFG_PATH))
+ &&
Files.isRegularFile(candidate.resolve(SYSTEM_PROPERTIES_PATH))) {
+ return candidate.resolve(relativePath);
+ }
+ candidate = candidate.getParent();
+ }
+ throw new IOException("Could not find the Unomi repository root from "
+ Paths.get("").toAbsolutePath());
+ }
+}
diff --git
a/rest/src/test/java/org/apache/unomi/rest/cors/AdminCorsSettingsTest.java
b/rest/src/test/java/org/apache/unomi/rest/cors/AdminCorsSettingsTest.java
new file mode 100644
index 000000000..9e78270d0
--- /dev/null
+++ b/rest/src/test/java/org/apache/unomi/rest/cors/AdminCorsSettingsTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.unomi.rest.cors;
+
+import org.apache.unomi.api.services.ConfigSharingService;
+import org.apache.unomi.api.services.ConfigSharingService.ConfigChangeEvent;
+import
org.apache.unomi.api.services.ConfigSharingService.ConfigChangeEvent.ConfigChangeEventType;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.lang.reflect.Field;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class AdminCorsSettingsTest {
+
+ private static final String ADMIN = "https://admin.example";
+
+ @Mock
+ private ConfigSharingService configSharingService;
+
+ private AdminCorsSettings settings;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ settings = new AdminCorsSettings();
+ Field field =
AdminCorsSettings.class.getDeclaredField("configSharingService");
+ field.setAccessible(true);
+ field.set(settings, configSharingService);
+ }
+
+ /** The shipped default is empty: no origin gets credentialed admin CORS.
*/
+ @Test
+ void emptyByDefault() {
+
when(configSharingService.getProperty(AdminCorsSettings.ALLOWED_ORIGINS_PROPERTY)).thenReturn("");
+ settings.activate();
+
+ assertFalse(settings.allows(ADMIN));
+ assertFalse(settings.allows(null));
+ }
+
+ /** WebConfig may publish the setting after this component activates; the
change event picks it up. */
+ @Test
+ void picksUpLaterPublishedOrigins() {
+
when(configSharingService.getProperty(AdminCorsSettings.ALLOWED_ORIGINS_PROPERTY)).thenReturn(null,
ADMIN);
+ settings.activate();
+ assertFalse(settings.allows(ADMIN));
+
+ settings.configChanged(new
ConfigChangeEvent(ConfigChangeEventType.ADDED,
+ AdminCorsSettings.ALLOWED_ORIGINS_PROPERTY, null, ADMIN));
+
+ assertTrue(settings.allows(ADMIN));
+ assertFalse(settings.allows("https://evil.example"));
+ }
+
+ /** Removing an origin from the list revokes it without a restart. */
+ @Test
+ void revokesRemovedOrigins() {
+
when(configSharingService.getProperty(AdminCorsSettings.ALLOWED_ORIGINS_PROPERTY)).thenReturn(ADMIN,
"");
+ settings.activate();
+ assertTrue(settings.allows(ADMIN));
+
+ settings.configChanged(new
ConfigChangeEvent(ConfigChangeEventType.UPDATED,
+ AdminCorsSettings.ALLOWED_ORIGINS_PROPERTY, ADMIN, ""));
+
+ assertFalse(settings.allows(ADMIN));
+ }
+
+ /** Other settings changing does not reload (or reset) the admin list. */
+ @Test
+ void ignoresUnrelatedChanges() {
+
when(configSharingService.getProperty(AdminCorsSettings.ALLOWED_ORIGINS_PROPERTY)).thenReturn(ADMIN);
+ settings.activate();
+
+ settings.configChanged(new
ConfigChangeEvent(ConfigChangeEventType.UPDATED,
+ "publicCorsAllowedOrigins", null, "https://shop.example"));
+
+ assertTrue(settings.allows(ADMIN));
+ }
+
+ /** Wildcards and malformed entries are dropped, never treated as
match-all. */
+ @Test
+ void rejectsWildcardsAndMalformedEntries() {
+
when(configSharingService.getProperty(AdminCorsSettings.ALLOWED_ORIGINS_PROPERTY))
+ .thenReturn("*, admin.example, https://admin.example/path, " +
ADMIN);
+ settings.activate();
+
+ assertTrue(settings.allows(ADMIN));
+ assertFalse(settings.allows("https://evil.example"));
+ assertFalse(settings.allows("null"));
+ }
+}
diff --git
a/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilterTest.java
b/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilterTest.java
index 74aac4ed1..4b11ca912 100644
---
a/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilterTest.java
+++
b/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerCorsFilterTest.java
@@ -159,17 +159,77 @@ class PublicTrackerCorsFilterTest {
}
@Test
- void nonPublicPathIsLeftAlone() {
- // A listed origin, so only the path check keeps the CXF grant as it
is.
+ void adminPathUnlistedOriginGetsNoCredentials() {
when(uriInfo.getPath()).thenReturn("profiles/search");
listed("https://shop.example");
-
lenient().when(request.getHeaderString("Origin")).thenReturn("https://shop.example");
+
when(request.getHeaderString("Origin")).thenReturn("https://shop.example");
grantedByCxf();
filter.restrictCredentials(request, response);
assertEquals("*", headers.getFirst("Access-Control-Allow-Origin"));
- assertEquals(Boolean.FALSE,
headers.getFirst("Access-Control-Allow-Credentials"));
+ assertNull(headers.getFirst("Access-Control-Allow-Credentials"));
+ }
+
+ @Test
+ void adminPathListedOriginGetsCredentials() {
+ when(uriInfo.getPath()).thenReturn("rules");
+ filter = new PublicTrackerCorsFilter(new PublicTrackerSettings(null,
null),
+ new AdminCorsSettings("https://admin.example"));
+
when(request.getHeaderString("Origin")).thenReturn("https://admin.example");
+ grantedByCxf();
+
+ filter.restrictCredentials(request, response);
+
+ assertEquals("https://admin.example",
headers.getFirst("Access-Control-Allow-Origin"));
+ assertEquals("true",
headers.getFirst("Access-Control-Allow-Credentials"));
+ assertEquals("Origin", headers.getFirst("Vary"));
+ }
+
+ /** The browser sends a preflight before a credentialed admin call; it
must be upgraded too. */
+ @Test
+ void adminPathPreflightFromListedOriginGetsCredentials() {
+ when(uriInfo.getPath()).thenReturn("rules");
+ filter = new PublicTrackerCorsFilter(new PublicTrackerSettings(null,
null),
+ new AdminCorsSettings("https://admin.example"));
+
when(request.getHeaderString("Origin")).thenReturn("https://admin.example");
+ lenient().when(request.getMethod()).thenReturn("OPTIONS");
+
lenient().when(request.getHeaderString("Access-Control-Request-Method")).thenReturn("POST");
+ grantedByCxf();
+
+ filter.restrictCredentials(request, response);
+
+ assertEquals("https://admin.example",
headers.getFirst("Access-Control-Allow-Origin"));
+ assertEquals("true",
headers.getFirst("Access-Control-Allow-Credentials"));
+ }
+
+ /** With the default (empty) admin list, an admin preflight never
advertises credentials. */
+ @Test
+ void adminPathPreflightWithDefaultListGetsNoCredentials() {
+ when(uriInfo.getPath()).thenReturn("rules");
+
when(request.getHeaderString("Origin")).thenReturn("https://admin.example");
+ lenient().when(request.getMethod()).thenReturn("OPTIONS");
+
lenient().when(request.getHeaderString("Access-Control-Request-Method")).thenReturn("POST");
+ grantedByCxf();
+
+ filter.restrictCredentials(request, response);
+
+ assertEquals("*", headers.getFirst("Access-Control-Allow-Origin"));
+ assertNull(headers.getFirst("Access-Control-Allow-Credentials"));
+ }
+
+ /** The admin list does not leak into the public tracker: the two lists
stay separate. */
+ @Test
+ void adminListedOriginGetsNoCredentialsOnPublicPath() {
+ filter = new PublicTrackerCorsFilter(new PublicTrackerSettings(null,
null),
+ new AdminCorsSettings("https://admin.example"));
+
when(request.getHeaderString("Origin")).thenReturn("https://admin.example");
+ grantedByCxf();
+
+ filter.restrictCredentials(request, response);
+
+ assertEquals("*", headers.getFirst("Access-Control-Allow-Origin"));
+ assertNull(headers.getFirst("Access-Control-Allow-Credentials"));
}
@Test
diff --git
a/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerSettingsTest.java
b/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerSettingsTest.java
index ce9923faf..554fa1813 100644
---
a/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerSettingsTest.java
+++
b/rest/src/test/java/org/apache/unomi/rest/cors/PublicTrackerSettingsTest.java
@@ -195,8 +195,8 @@ class PublicTrackerSettingsTest {
lenient().when(configSharingService.getProperty(PublicTrackerSettings.ALLOWED_ORIGINS_PROPERTY)).thenReturn("shop.example,
*");
settings.activate();
assertFalse(settings.policy().allows("https://shop.example"));
- assertTrue(hasWarning("Ignoring public CORS allowed origin
'shop.example'"));
- assertTrue(hasWarning("Ignoring public CORS allowed origin '*'"));
+ assertTrue(hasWarning("Ignoring CORS allowed origin 'shop.example'"));
+ assertTrue(hasWarning("Ignoring CORS allowed origin '*'"));
assertTrue(hasWarning("None of the public CORS allowed origins"));
}
diff --git
a/rest/src/test/java/org/apache/unomi/rest/endpoints/AdminRestCorsTest.java
b/rest/src/test/java/org/apache/unomi/rest/endpoints/AdminRestCorsTest.java
new file mode 100644
index 000000000..5191f370e
--- /dev/null
+++ b/rest/src/test/java/org/apache/unomi/rest/endpoints/AdminRestCorsTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.unomi.rest.endpoints;
+
+import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
+import org.apache.unomi.rest.scheduler.TaskEndpoint;
+import org.apache.unomi.rest.tenants.TenantEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Admin REST endpoints advertise any origin without credentials; the CORS
filter then grants
+ * credentials only for origins listed in the admin allow-list.
+ */
+class AdminRestCorsTest {
+
+ @Test
+ void rulesEndpointDoesNotAdvertiseCredentials() {
+ assertAdminCors(RulesServiceEndPoint.class);
+ }
+
+ @Test
+ void profilesEndpointDoesNotAdvertiseCredentials() {
+ assertAdminCors(ProfileServiceEndPoint.class);
+ }
+
+ @Test
+ void tenantsEndpointDoesNotAdvertiseCredentials() {
+ assertAdminCors(TenantEndpoint.class);
+ }
+
+ @Test
+ void tasksEndpointDoesNotAdvertiseCredentials() {
+ assertAdminCors(TaskEndpoint.class);
+ }
+
+ private static void assertAdminCors(Class<?> endpoint) {
+ CrossOriginResourceSharing cors =
endpoint.getAnnotation(CrossOriginResourceSharing.class);
+ assertNotNull(cors, endpoint.getSimpleName() + " must declare CORS");
+ assertTrue(cors.allowAllOrigins());
+ assertFalse(cors.allowCredentials(), endpoint.getSimpleName() + " must
not advertise credentials");
+ }
+}
diff --git
a/web-servlets/src/main/java/org/apache/unomi/web/servlets/WebConfig.java
b/web-servlets/src/main/java/org/apache/unomi/web/servlets/WebConfig.java
index 247a2662e..a2d557305 100644
--- a/web-servlets/src/main/java/org/apache/unomi/web/servlets/WebConfig.java
+++ b/web-servlets/src/main/java/org/apache/unomi/web/servlets/WebConfig.java
@@ -43,6 +43,7 @@ public class WebConfig {
private String publicCorsAllowedOrigins;
private String publicCorsMatchReferer;
private String publicCorsTenantOrigins;
+ private String adminCorsAllowedOrigins;
private String allowedProfileDownloadFormats;
private int publicPostRequestBytesLimit;
@@ -79,6 +80,9 @@ public class WebConfig {
@AttributeDefinition
String public_cors_tenantOrigins() default "true";
+ @AttributeDefinition
+ String admin_cors_allowedOrigins() default "";
+
@AttributeDefinition
String allowed_profile_download_formats() default "csv,yaml,json,text";
@@ -101,6 +105,7 @@ public class WebConfig {
this.publicCorsAllowedOrigins = config.public_cors_allowedOrigins();
this.publicCorsMatchReferer = config.public_cors_matchReferer();
this.publicCorsTenantOrigins = config.public_cors_tenantOrigins();
+ this.adminCorsAllowedOrigins = config.admin_cors_allowedOrigins();
this.allowedProfileDownloadFormats =
config.allowed_profile_download_formats();
this.publicPostRequestBytesLimit =
config.public_post_request_bytes_limit();
@@ -113,6 +118,7 @@ public class WebConfig {
configSharingService.setProperty("publicCorsAllowedOrigins",
publicCorsAllowedOrigins);
configSharingService.setProperty("publicCorsMatchReferer",
publicCorsMatchReferer);
configSharingService.setProperty("publicCorsTenantOrigins",
publicCorsTenantOrigins);
+ configSharingService.setProperty("adminCorsAllowedOrigins",
adminCorsAllowedOrigins);
configSharingService.setProperty("profileIdCookieSameSite",
contextserverProfileIdCookieSameSite);
configSharingService.setProperty("publicPostRequestBytesLimit",
publicPostRequestBytesLimit);
configSharingService.setProperty("allowedProfileDownloadFormats",
allowedProfileDownloadFormats);
diff --git a/web-servlets/src/main/resources/org.apache.unomi.web.cfg
b/web-servlets/src/main/resources/org.apache.unomi.web.cfg
index 2dd63cf31..84dd8b96e 100644
--- a/web-servlets/src/main/resources/org.apache.unomi.web.cfg
+++ b/web-servlets/src/main/resources/org.apache.unomi.web.cfg
@@ -37,6 +37,9 @@
public.cors.allowedOrigins=${org.apache.unomi.public.cors.allowedOrigins:-}
public.cors.matchReferer=${org.apache.unomi.public.cors.matchReferer:-false}
# Let each tenant add its own website origins (publicCorsAllowedOrigins tenant
property). Only false turns it off.
public.cors.tenantOrigins=${org.apache.unomi.public.cors.tenantOrigins:-true}
+# Origins of admin UIs that may use credentialed CORS against /cxs admin REST
and /graphql.
+# Empty (the default) means no cross-origin browser may read admin responses
with the operator's credentials.
+admin.cors.allowedOrigins=${org.apache.unomi.admin.cors.allowedOrigins:-}
#Allowed profile download formats, actually only csv (horizontal and
vertical), json, text and yaml are allowed.
allowed.profile.download.formats=${org.apache.unomi.profile.download.formats:-csv,yaml,json,text}
# This setting allow for request size (Content-length) protection. Checking
that the requests do not exceed the limit.
diff --git
a/web-servlets/src/test/java/org/apache/unomi/web/servlets/WebConfigTest.java
b/web-servlets/src/test/java/org/apache/unomi/web/servlets/WebConfigTest.java
index 899d81ce2..01b84c335 100644
---
a/web-servlets/src/test/java/org/apache/unomi/web/servlets/WebConfigTest.java
+++
b/web-servlets/src/test/java/org/apache/unomi/web/servlets/WebConfigTest.java
@@ -37,6 +37,7 @@ class WebConfigTest {
when(config.public_cors_matchReferer()).thenReturn("yes");
when(config.public_cors_tenantOrigins()).thenReturn("off");
when(config.public_cors_allowedOrigins()).thenReturn("https://shop.example");
+
when(config.admin_cors_allowedOrigins()).thenReturn("https://admin.example");
when(config.contextserver_profileIdCookieSameSite()).thenReturn("None");
ConfigSharingService configSharingService =
mock(ConfigSharingService.class);
@@ -49,10 +50,12 @@ class WebConfigTest {
verify(configSharingService).setProperty("profileIdCookieHttpOnly",
"flase");
verify(configSharingService).setProperty("publicCorsMatchReferer",
"yes");
verify(configSharingService).setProperty("publicCorsTenantOrigins",
"off");
+ verify(configSharingService).setProperty("adminCorsAllowedOrigins",
"https://admin.example");
// Origins before SameSite, so SameSite=None is never resolved against
an empty list on the way.
InOrder order = inOrder(configSharingService);
order.verify(configSharingService).setProperty("publicCorsAllowedOrigins",
"https://shop.example");
order.verify(configSharingService).setProperty("publicCorsTenantOrigins",
"off");
+
order.verify(configSharingService).setProperty("adminCorsAllowedOrigins",
"https://admin.example");
order.verify(configSharingService).setProperty("profileIdCookieSameSite",
"None");
}
}