|
1 | | -# 11744: CORS header handling fixes (echo single Origin, add Vary: Origin, multi-origin allow, sanitization) |
| 1 | +# 11744: CORS handling improvements |
2 | 2 |
|
3 | | -This branch adjusts the CORS filter so browser clients work correctly when multiple origins are allowed. |
| 3 | +Modernizes CORS so browser integrations (previewers, external tools, JS clients) work correctly with multiple origins and proper caching. |
4 | 4 |
|
5 | | -## What changed |
6 | | -- Access-Control-Allow-Origin (ACAO) now echoes the single request `Origin` when it matches an allowlist from `dataverse.cors.origin`. |
7 | | -- `Vary: Origin` is added when echoing a specific origin to keep caches correct across different origins. |
8 | | -- Comma-separated origin lists are supported; surrounding quotes in CSV configs are stripped. |
9 | | -- Sanitization is applied to CORS header lists (methods/allow/expose) to avoid quoted values that can break preflight checks. |
10 | | -- Deprecated DB fallback for enabling CORS is removed; CORS is considered enabled only when `dataverse.cors.origin` is set as a JVM options/Microprofile setting. |
| 5 | +## Highlights |
| 6 | +* Echoes the request origin (`Access-Control-Allow-Origin`) when it matches `dataverse.cors.origin`. |
| 7 | +* Adds `Vary: Origin` for per-origin responses (not for wildcard). |
| 8 | +* Supports comma‑separated origin list; any `*` in the list = wildcard mode. |
| 9 | +* CORS now only enabled when `dataverse.cors.origin` is set (deprecated `:AllowCors` no longer enables it). |
| 10 | +* Sanitizes CORS CSV settings (`dataverse.cors.methods`, `dataverse.cors.headers.allow`, `dataverse.cors.headers.expose`). |
| 11 | +* Docs updated (Installation, Big Data Support, External Tools, File Previews); new tests cover edge cases. |
11 | 12 |
|
12 | | -## Upgrade / run notes (non-SQL) |
13 | | -To keep CORS working after pulling this branch: |
| 13 | +## Admin Action |
| 14 | +Set `dataverse.cors.origin` explicitly (required). Use explicit origins (not `*`) for credentialed requests. Ensure proxies keep `Vary: Origin`. |
14 | 15 |
|
15 | | -1) Configure origins as JVM options/Microprofile settings (no quotes): |
16 | | -- Single origin: |
17 | | - - `dataverse.cors.origin=https://example.org` |
18 | | -- Multiple origins (comma-separated): |
19 | | - - `dataverse.cors.origin=https://libis.github.io,https://gdcc.github.io` |
20 | | -- Wildcard: |
21 | | - - `dataverse.cors.origin=*` |
22 | | - - Note: Browsers reject `*` when credentialed requests are used (cookies/Authorization headers). Prefer explicit origins for those cases. |
23 | | - |
24 | | -2) Optional headers/methods lists (unquoted, comma-separated CSV): |
25 | | -- `dataverse.cors.methods` |
26 | | -- `dataverse.cors.headers.allow` |
27 | | -- `dataverse.cors.headers.expose` |
28 | | - |
29 | | -Avoid surrounding values with quotes (e.g., do not use `"Accept, Content-Type"`). Quotes will be stripped but may cause confusion. |
30 | | - |
31 | | -3) If you previously relied on the database setting to enable CORS (deprecated `AllowCors`), set `dataverse.cors.origin` instead. The DB fallback is no longer used. |
32 | | - |
33 | | -4) Reverse proxies/caches: `Vary: Origin` is now emitted. Ensure your proxy does not drop this header. |
34 | | - |
35 | | -## Verify |
36 | | -Preflight (replace DV_URL with your base URL): |
37 | | - |
38 | | -```bash |
39 | | -curl -i -X OPTIONS \ |
40 | | - -H "Origin: https://libis.github.io" \ |
41 | | - -H "Access-Control-Request-Method: GET" \ |
42 | | - "${DV_URL}/api/info/version" |
| 16 | +Examples: |
43 | 17 | ``` |
44 | | - |
45 | | -Expected: |
46 | | -- `Access-Control-Allow-Origin: https://libis.github.io` |
47 | | -- `Vary: Origin` present |
48 | | - |
49 | | -Actual request: |
50 | | - |
51 | | -```bash |
52 | | -curl -i \ |
53 | | - -H "Origin: https://libis.github.io" \ |
54 | | - "${DV_URL}/api/info/version" |
| 18 | +dataverse.cors.origin=https://example.org |
| 19 | +dataverse.cors.origin=https://libis.github.io,https://gdcc.github.io |
| 20 | +dataverse.cors.origin=* |
55 | 21 | ``` |
| 22 | +Optional (unquoted): |
| 23 | +``` |
| 24 | +dataverse.cors.methods=GET, POST, OPTIONS, PUT, DELETE |
| 25 | +``` |
| 26 | + |
| 27 | +## Compatibility |
| 28 | +* Must configure `dataverse.cors.origin`; `:AllowCors` no longer sufficient. |
| 29 | +* Any `*` triggers wildcard (no per-origin echo / no Vary header). |
56 | 30 |
|
57 | | -Expected: |
58 | | -- Same ACAO echo as above |
| 31 | +## Docs |
| 32 | +See updated `dataverse.cors.origin` section and related notes in Big Data Support (S3), External Tools, and File Previews. |
59 | 33 |
|
60 | | -## Backward compatibility |
61 | | -- Instances relying on the deprecated DB-based CORS enablement must set `dataverse.cors.origin` to keep CORS enabled. |
62 | | -- Quoted CORS configuration values may behave differently; remove quotes going forward. |
0 commit comments