liveBook · Manning

Chapter 10: Configuring CORS

What you will learn in chapter 10 of Spring Security in Action, Second Edition

Introduces why browsers restrict cross-origin requests and why web applications may need CORS to permit them.

After this chapter you will be able to

Section by section

Introduction

Introduces why browsers restrict cross-origin requests and why web applications may need CORS to permit them.

Key terms: cross-origin resource sharing (CORS), origins, frontend, backend

10.1 How does CORS work?

This section explains how browsers handle cross-origin requests, how CORS response headers affect access to responses, and why CORS does not secure an endpoint.

Key terms: CORS, origin, Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, localhost, 127.0.0.1, browser, endpoint, preflight request

10.2 Applying CORS policies with the @CrossOrigin annotation

This section shows how to apply CORS rules to individual endpoints with @CrossOrigin and explains the benefits and risks of that approach.

Key terms: @CrossOrigin, value, allowedHeaders, methods, allowed origin, asterisk (*), origins, headers, cross-site scripting (XSS), DDoS attacks

10.3 Applying CORS using a CorsConfigurer

This section shows how to centralize CORS configuration through HttpSecurity and explains why both allowed origins and methods must be specified.

Key terms: @CrossOrigin, HttpSecurity, cors(), Customizer<CorsConfigurer>, CorsConfigurationSource, CorsConfiguration, allowed origins, methods, headers

10.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 9: Configuring CSRF protection Chapter 11: Implementing authorization at the method level →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.