Headers are not applied

Hello, my headers are not applied but the dashboard is seems correct.

services:
  traefik:
    image: traefik:v2.7
    .........
    labels:
      - traefik.enable=true
     .......
      - traefik.http.middlewares.headers.headers.frameDeny=true
      - traefik.http.middlewares.headers.headers.browserXssFilter=true
      - traefik.http.middlewares.headers.headers.stsIncludeSubdomains=true
      - traefik.http.middlewares.headers.headers.forceSTSHeader=true
      - traefik.http.middlewares.headers.headers.contentSecurityPolicy=true
      - traefik.http.middlewares.headers.headers.accessControlAllowOriginList=https://mydomain.com
      - traefik.http.middlewares.headers.headers.accessControlAllowCredentials=true
    .......
    networks:
      - traefik-network

frontend:
    ...........
    labels:
      - traefik.enable=true
      .......
      - traefik.http.routers.frontend.middlewares=headers
    networks:
      - traefik-network

It seems that there are only a few that work (Access-control-allow-credentials: true)

By using online header checkers or checking by myself, headers seems not to be applied. I should see mydomain as CORS origin...

Screenshot_2

Thanks for helping

@Shidooo does the Origin header in the request matches the AllowOriginList?
https://mydomain.com in this case

@douglasdtm

my backend and frontend are both on the same origin https://mydomain.com
and traefik is on https://traefik.mydomain.com
all on the same server

Does this answer your question? :smile:

I still haven't found a solution, I tried to update traefik to version 3.0, the problem still exists.

Have you tried adding @docker at the end? As the middleware is defined by provider.docker through the labels.

This does not seem to have changed. I still have some of my headers that don't show up as "accessControlAllowOriginList".

I believe that only the headers that are already generated by my services are propagated. But the ones I want to add through traefik are not added at all. Even if the interface indicates otherwise.

Any idea ?

It's still not working.

Hello @Shidooo,

Configuration-wise, everything seems ok.

my backend and frontend are both on the same origin https://mydomain.com
and traefik is on https://traefik.mydomain.com all on the same server
Does this answer your question? :smile:

Well, I fear that this is not really answering the question :wink:
I think @douglasdtm wanted to ask you if you did make sure that the request has the Origin header set to the correct value, can you double-check that?
Thanks!

I have problems as same as you. I try to upgrade the version but all problems still not working too.

Hello @ rtribotte

I think @douglasdtm wanted to ask you if you did make sure that the request has the Origin header set to the correct value, can you double-check that?

I double-checked the request with many different values all problems still not working.

I switch to using customResponseHeaders - (ref.: docs) option like

...
- traefik.http.middlewares.cors.headers.customResponseHeaders.access-control-allow-origin=https://example.com
- traefik.http.middlewares.cors.headers.customResponseHeaders.access-control-allow-credentials=true
...

But this solution only supports one domain I hope will support soon.

Hi,Has this issue been resolved?

I am having the same problem! Any ideas?

customResponseHeaders also doesn't work for me

Works for me.

RequestHeader added to request, ResponseHeader added to response.

You need to declare and assign the headers (doc):

#docker-compose.yml
services:
  traefik:
    image: traefik:v2.11
    ports:
      - 80:80
    networks:
      - proxy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    command:
      - --providers.docker=true
      - --providers.docker.exposedByDefault=false
      - --entryPoints.web.address=:80
      #- --log.level=DEBUG
      - --accesslog=true
      #- --accesslog.format=json

  whoami:
    image: traefik/whoami:v1.10
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=Host(`whoami.example.com`)
      - traefik.http.middlewares.myRequestHeader.headers.customrequestheaders.X-myRequestHeader=FOO
      - traefik.http.middlewares.myResponseHeader.headers.customresponseheaders.X-myResponseHeader=BAR
      - traefik.http.routers.whoami.middlewares=myRequestHeader,myResponseHeader
      - traefik.http.services.whoami.loadbalancer.server.port=80

networks:
  proxy:
    name: proxy