Recipe Name:
Security Misconfiguration: CORS: Avoid broad settings: @CrossOrigin - 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 configure @CrossOrigin. Allowing CORS, in particular with overly permissive settings, can make the application vulnerable to attacks.

Before
@CrossOrigin(allowedHeaders = "*")
After
@CrossOrigin(allowedHeaders = "header1")
References
Recipe
id: scw:spring:security:cors:CrossOrigin-allowedHeaders
version: 10
metadata:
  name: 'Security Misconfiguration: CORS: Avoid broad settings: @CrossOrigin - allowedHeaders'
  shortDescription: Allowing all headers makes the application vulnerable
  level: warning
  language: java
  enabled: true
  descriptionFile: descriptions/AvoidbroadsettingsCrossOrigin-allowedHeaders.html
  tags: Spring;security;framework specific;web;Spring Security
search:
  annotationParameter:
    owner:
      type: org.springframework.web.bind.annotation.CrossOrigin
    name: allowedHeaders
    value:
      anyOf:
      - value:
          stringified: '*'
      - value:
          stringified: '{"*"}'
availableFixes:
- name: Specify the allowedHeaders
  actions: []