Recipe Name:
Security Misconfiguration: CORS: Avoid broad settings: CorsRegistry#allowedHeaders
Description:
Allowing all headers makes the application vulnerable
Level:
warning
Language:
  • java
Tags:
  • Spring
  • security
  • framework specific
  • web
  • Spring Security
Documentation

Be cautious when using a wildcard ("*") to set allowedHeaders. Allowing CORS, in particular with overly permissive settings, can make the application vulnerable to attacks.

Before
registry.allowedHeaders("*");
After
registry.allowedHeaders();
References
Recipe
id: scw:spring:security:cors:CorsRegistry#allowedHeaders
version: 10
metadata:
  name: 'Security Misconfiguration: CORS: Avoid broad settings: CorsRegistry#allowedHeaders'
  shortDescription: Allowing all headers makes the application vulnerable
  level: warning
  language: java
  enabled: true
  descriptionFile: descriptions/AvoidbroadsettingsCorsRegistryallowedHeaders.html
  tags: Spring;security;framework specific;web;Spring Security
search:
  methodcall:
    args:
      1:
        value:
          stringified: '*'
    name: allowedHeaders
    type: org.springframework.web.servlet.config.annotation.CorsRegistration
availableFixes:
- name: Specify the allowedHeaders
  actions: []