spring-cloud / spring-cloud/spring-cloud-gateway

The OPTIONS request cannot be forwarded to the service

Open
#2,472 24 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug status: pending-design-work
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Describe the bug
Because I have a service proxied by the gateway, this service needs to customize the response header of the OPTIONS request, but I found that the gateway does not send the request to my service

I found that when the preflight request passes through the gateway, the request header contains both Origin and Access-Control-Request-Method, it will enter NO_OP_HANDLER and will not access the route defined by the RouteDefinition.
Does the cors of the gateway refer to intercepting the request and returning it directly?
If so, is there a way to remove the cors filter of the gateway? Or can you briefly talk about why it is designed like this?

image
image

Version
spring-cloud-gateway-server@3.0.4

Config

spring:
  cloud:
    gateway:
      globalcors:
        corsConfigurations:
          '[/**]':
            allowedOriginPatterns: '*'
            allowedMethods: '*'
            allowedHeaders: '*'
            allowCredentials: true
      default-filters:
          - DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing global CORS handling for preflight requests in the gateway version listed, focusing on the NO_OP_HANDLER path and how it relates to the RouteDefinition. Reproduce the behavior with the supplied YAML and verify whether the OPTIONS request reaches the service. Done means the forwarding behavior or its intended design is confirmed, with a supported configuration or documented explanation identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.