restlet-framework-java icon indicating copy to clipboard operation
restlet-framework-java copied to clipboard

CORS: Vary: Origin missing, '*' accepted with credentials, no way to allow origin patterns

Open thboileau-git opened this issue 1 month ago • 0 comments

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.

  1. Vary: Origin is 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: use Vary unless the answer is a static * or a static origin.
  2. * allowed together with credentials. The filter then echoes any request origin with Access-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".
  3. Configuration changes after the first request are ignored by CorsFilter (the internal helper is built once). 3.0 only.
  4. Only exact origins or * can be allowed, no way to accept for example any sub-domain.
  5. Javadoc still references the 2014 W3C draft.

Proposed fix

  • 2.6, 2.7: add Vary: Origin when the answer depends on the origin; log a warning for * with credentials; opt-in setAllowedOriginMatcher(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.

thboileau-git avatar Oct 31 '26 17:10 thboileau-git