Recall & Review
beginner
What does CORS stand for and why is it important in web security?
CORS stands for Cross-Origin Resource Sharing. It is important because it controls how resources on a web server can be requested from another domain, helping to prevent unauthorized access and security risks.
Click to reveal answer
intermediate
How do you enable CORS in a Spring Boot Security configuration?
You enable CORS by configuring a CorsConfigurationSource bean and applying it in the HttpSecurity object using .cors(). This allows you to specify allowed origins, methods, headers, and credentials.
Click to reveal answer
intermediate
What is the role of the CorsConfigurationSource bean in Spring Security?
CorsConfigurationSource defines the CORS settings like allowed origins, methods, headers, and credentials. Spring Security uses it to apply these rules to incoming requests.
Click to reveal answer
advanced
Why should CORS be configured carefully in a security context?
Because incorrect CORS settings can allow malicious websites to access sensitive data or perform unwanted actions on behalf of a user, leading to security vulnerabilities.
Click to reveal answer
intermediate
Show a simple example of enabling CORS for all origins in Spring Security.
In your SecurityFilterChain bean, add .cors().configurationSource(request -> {
var cors = new CorsConfiguration();
cors.setAllowedOriginPatterns(List.of("*"));
cors.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE"));
return cors;
});
Click to reveal answer
What does the .cors() method do in Spring Security configuration?
✗ Incorrect
The .cors() method enables CORS support in Spring Security, allowing you to define cross-origin rules.
Which bean is commonly used to define CORS settings in Spring Boot Security?
✗ Incorrect
CorsConfigurationSource bean defines the CORS rules like allowed origins and methods.
What could happen if you set allowed origins to '*' in production without restrictions?
✗ Incorrect
Allowing all origins can let any website access your API, which can be a security risk.
Which HTTP methods should you specify in CORS configuration to allow data modification?
✗ Incorrect
POST, PUT, and DELETE methods are used to create, update, or delete data and should be allowed if needed.
Where do you typically apply the CORS configuration in Spring Security?
✗ Incorrect
CORS is configured in the HttpSecurity object by calling .cors() and providing a CorsConfigurationSource.
Explain how to configure CORS in Spring Security and why it is important.
Think about how browsers restrict cross-domain requests and how Spring Security helps manage that.
You got /4 concepts.
Describe potential security risks if CORS is misconfigured in a Spring Boot application.
Consider what happens if any website can call your API without limits.
You got /4 concepts.