liveBook · Manning

Access-Control-Allow headers

As explained in Spring Security in Action, Second Edition

Access-Control-Allow-Origin is an HTTP response header that specifies which origins may access a resource through cross-origin requests.

Access-Control-Allow-Origin is an HTTP response header that identifies which foreign origins may access a resource through cross-origin requests. Browsers reject the response when the header is absent or does not allow the requesting origin; Spring Security adds no CORS headers by default. section 10.1

Use the header alongside related CORS controls:

  • Access-Control-Allow-Methods limits permitted HTTP methods, such as allowing only POST or GET. section 10.1
  • Access-Control-Allow-Headers limits which request headers a cross-origin client may send. section 10.1
  • Browsers may send an OPTIONS preflight request before sending the original request. section 10.1

Testing an allowed origin

Send an OPTIONS request with Origin: http://www.example.com and Access-Control-Request-Method: POST, then verify Access-Control-Allow-Origin and Access-Control-Allow-Methods contain the expected values. section 18.7

Figure 10.3 Enabling cross-origin requests. The example.org server adds the Access-Control-Allow-Origin header to specify the origins of the request for which the browser should accept the response. If the domain from which the call was made is enumerated in the origins, the browser accepts the response.

Shows how the server's Access-Control-Allow-Origin value determines whether the browser accepts a cross-origin response. section 10.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains browser rejection, default Spring Security behavior, related headers, and preflight testing without detailing header configuration code.
Examples
Uses an XMLHttpRequest from localhost to test, an iframe scenario, and a MockMvc OPTIONS test with an example origin.
What it assumes
Assumes basic HTTP and browser request knowledge while explaining cross-origin restrictions and CORS behavior from the beginning.
What you can do after
Diagnose/debug browser CORS failures and verify allowed origins and methods with an OPTIONS-based test.
How it connects
Connects CORS with HTTP response headers, browser same-origin restrictions, preflight requests, and Access-Control-Allow-Methods.

Also explained in

Compare how 2 books explain Access-Control-Allow headers →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.