@@ -237,8 +237,12 @@ public void addAllowedOriginPattern(@Nullable String originPattern) {
237
237
238
238
/**
239
239
* Set the HTTP methods to allow, e.g. {@code "GET"}, {@code "POST"},
240
- * {@code "PUT"}, etc.
241
- * <p>The special value {@code "*"} allows all methods.
240
+ * {@code "PUT"}, etc. The special value {@code "*"} allows all methods.
241
+ * <p>{@code Access-Control-Allow-Methods} response header is set either
242
+ * to the configured method or to {@code "*"}. Keep in mind however that the
243
+ * CORS spec does not allow {@code "*"} when {@link #setAllowCredentials
244
+ * allowCredentials} is set to {@code true}, that combination is handled
245
+ * by copying the method specified in the CORS preflight request.
242
246
* <p>If not set, only {@code "GET"} and {@code "HEAD"} are allowed.
243
247
* <p>By default this is not set.
244
248
* <p><strong>Note:</strong> CORS checks use values from "Forwarded"
@@ -269,24 +273,24 @@ public void setAllowedMethods(@Nullable List<String> allowedMethods) {
269
273
/**
270
274
* Return the allowed HTTP methods, or {@code null} in which case
271
275
* only {@code "GET"} and {@code "HEAD"} allowed.
276
+ * @see #setAllowedMethods(List)
272
277
* @see #addAllowedMethod(HttpMethod)
273
278
* @see #addAllowedMethod(String)
274
- * @see #setAllowedMethods(List)
275
279
*/
276
280
@ Nullable
277
281
public List <String > getAllowedMethods () {
278
282
return this .allowedMethods ;
279
283
}
280
284
281
285
/**
282
- * Add an HTTP method to allow .
286
+ * Variant of {@link #setAllowedMethods} for adding one allowed method at a time .
283
287
*/
284
288
public void addAllowedMethod (HttpMethod method ) {
285
289
addAllowedMethod (method .name ());
286
290
}
287
291
288
292
/**
289
- * Add an HTTP method to allow .
293
+ * Variant of {@link #setAllowedMethods} for adding one allowed method at a time .
290
294
*/
291
295
public void addAllowedMethod (String method ) {
292
296
if (StringUtils .hasText (method )) {
@@ -309,9 +313,13 @@ else if (this.resolvedMethods != null) {
309
313
310
314
/**
311
315
* Set the list of headers that a pre-flight request can list as allowed
312
- * for use during an actual request.
313
- * <p>The special value {@code "*"} allows actual requests to send any
314
- * header.
316
+ * for use during an actual request. The special value {@code "*"} allows
317
+ * actual requests to send any header.
318
+ * <p>{@code Access-Control-Allow-Headers} response header is set either
319
+ * to the configured list of headers or to {@code "*"}. Keep in mind however
320
+ * that the CORS spec does not allow {@code "*"} when {@link #setAllowCredentials
321
+ * allowCredentials} is set to {@code true}, that combination is handled by
322
+ * copying the headers specified in the CORS preflight request.
315
323
* <p>A header name is not required to be listed if it is one of:
316
324
* {@code Cache-Control}, {@code Content-Language}, {@code Expires},
317
325
* {@code Last-Modified}, or {@code Pragma}.
@@ -332,7 +340,7 @@ public List<String> getAllowedHeaders() {
332
340
}
333
341
334
342
/**
335
- * Add an actual request header to allow .
343
+ * Variant of {@link #setAllowedHeaders(List)} for adding one allowed header at a time .
336
344
*/
337
345
public void addAllowedHeader (String allowedHeader ) {
338
346
if (this .allowedHeaders == null ) {
@@ -345,12 +353,19 @@ else if (this.allowedHeaders == DEFAULT_PERMIT_ALL) {
345
353
}
346
354
347
355
/**
348
- * Set the list of response headers other than simple headers (i.e.
349
- * {@code Cache-Control}, {@code Content-Language}, {@code Content-Type},
350
- * {@code Expires}, {@code Last-Modified}, or {@code Pragma}) that an
351
- * actual response might have and can be exposed.
352
- * <p>The special value {@code "*"} allows all headers to be exposed for
353
- * non-credentialed requests.
356
+ * Set the list of response headers that an actual response might have
357
+ * and can be exposed to the client. The special value {@code "*"}
358
+ * allows all headers to be exposed.
359
+ * <p>{@code Access-Control-Expose-Headers} response header is set either
360
+ * to the configured list of headers or to {@code "*"}. While the CORS
361
+ * spec does not allow {@code "*"} when {@code Access-Control-Allow-Credentials}
362
+ * is set to {@code true}, most browsers support it and
363
+ * the response headers are not all available during the CORS processing,
364
+ * so as a consequence {@code "*"} is the header value used when specified
365
+ * regardless of the value of the `allowCredentials` property.
366
+ * <p>A header name is not required to be listed if it is one of:
367
+ * {@code Cache-Control}, {@code Content-Language}, {@code Expires},
368
+ * {@code Last-Modified}, or {@code Pragma}.
354
369
* <p>By default this is not set.
355
370
*/
356
371
public void setExposedHeaders (@ Nullable List <String > exposedHeaders ) {
@@ -368,9 +383,7 @@ public List<String> getExposedHeaders() {
368
383
}
369
384
370
385
/**
371
- * Add a response header to expose.
372
- * <p>The special value {@code "*"} allows all headers to be exposed for
373
- * non-credentialed requests.
386
+ * Variant of {@link #setExposedHeaders} for adding one exposed header at a time.
374
387
*/
375
388
public void addExposedHeader (String exposedHeader ) {
376
389
if (this .exposedHeaders == null ) {
@@ -381,6 +394,15 @@ public void addExposedHeader(String exposedHeader) {
381
394
382
395
/**
383
396
* Whether user credentials are supported.
397
+ * <p>Setting this property has an impact on how {@link #setAllowedOrigins(List)
398
+ * origins}, {@link #setAllowedOriginPatterns(List) originPatterns},
399
+ * {@link #setAllowedMethods(List) allowedMethods} and
400
+ * {@link #setAllowedHeaders(List) allowedHeaders} are processed, see related
401
+ * API documentation for more details.
402
+ * <p><strong>NOTE:</strong> Be aware that this option establishes a high
403
+ * level of trust with the configured domains and also increases the surface
404
+ * attack of the web application by exposing sensitive user-specific
405
+ * information such as cookies and CSRF tokens.
384
406
* <p>By default this is not set (i.e. user credentials are not supported).
385
407
*/
386
408
public void setAllowCredentials (@ Nullable Boolean allowCredentials ) {
0 commit comments