restlet-framework-java
restlet-framework-java copied to clipboard
CORS: Vary: Origin missing, '*' accepted with credentials, no way to allow origin patterns
Description
Review of the CORS support (CorsService, CorsFilter, CorsResponseHelper) against the Fetch standard (CORS protocol, "CORS protocol and HTTP caches") and RFC 9110 section 12.5.5. Identical code in 2.6, 2.7 and 3.0.
Vary: Originis never sent. When the CORS answer depends on the request origin (allow-list, or credentials), a shared cache can serve the response built for one origin to another, or serve a response without CORS headers to a later CORS request. Fetch: useVaryunless the answer is a static*or a static origin.*allowed together with credentials. The filter then echoes any request origin withAccess-Control-Allow-Credentials: true, so any web site can send credentialed requests. Fetch does not accept a literal*with credentials, and calls sharing credentialed responses "rather unsafe".- Configuration changes after the first request are ignored by
CorsFilter(the internal helper is built once). 3.0 only. - Only exact origins or
*can be allowed, no way to accept for example any sub-domain. - Javadoc still references the 2014 W3C draft.
Proposed fix
- 2.6, 2.7: add
Vary: Originwhen the answer depends on the origin; log a warning for*with credentials; opt-insetAllowedOriginMatcher(Predicate<String>); Javadoc. - 3.0: same, plus reject
*with credentials (IllegalStateException, breaking) and rebuild the helper when the configuration changes.
Not planned: Private Network Access (separate WICG draft).
Related
#216 (CORS support) and #1088 (custom CORS headers dropped, duplicate of #1198) are not addressed here.