# CORS header with regex list on kuberenetes

**URL:** <https://community.traefik.io/t/cors-header-with-regex-list-on-kuberenetes/11900>\
**Category:** Traefik v2\
**Tags:** middleware\
**Created:** [September 28, 2021, 7:22pm UTC](https://community.traefik.io/t/cors-header-with-regex-list-on-kuberenetes/11900 "2021-09-28T19:22:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yassine.laz](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/yassine.laz/32/1987_2.png) [@yassine.laz](https://community.traefik.io/u/yassine.laz)\
**Post date:** [September 28, 2021, 7:22pm UTC](https://community.traefik.io/t/cors-header-with-regex-list-on-kuberenetes/11900/1 "2021-09-28T19:22:46Z")

</div>

Hello everyone,

I have this middle ware configured to handle cors header for multiple origins (mostly microservices hosted under subdomains).

```auto
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: admin-fe-cors
  namespace: staging
spec:
  headers:
    accessControlAllowMethods:
      - "GET"
      - "POST"
      - "OPTIONS"
      - "DELETE"
      - "PATCH"
      - "PUT"
    accessControlAllowOriginListRegex:
      - "https://(.*?)XXXXX.net"
      - "https://(.*?)XXXXX.com"
    accessControlMaxAge: 100
    addVaryHeader: true

```

Im running Traefik v2.5.3 and I have not Idea if that config works or not or what headers Im supposed to look for or how to test it?  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/c/c78737f696e5b23e062d739140a1b50f75f8cb37.png)

Thanks

---

<div class="post-metadata">

**Author:** ![jakubhajek](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/jakubhajek/32/3389_2.png) [@jakubhajek](https://community.traefik.io/u/jakubhajek)\
**Post date:** [September 30, 2021, 12:32pm UTC](https://community.traefik.io/t/cors-header-with-regex-list-on-kuberenetes/11900/2 "2021-09-30T12:32:56Z")

</div>

> [@yassine.laz](#):
>
> ```auto
> apiVersion: traefik.containo.us/v1alpha1
> kind: Middleware
> metadata:
> name: admin-fe-cors
> namespace: staging
> spec:
> headers:
> accessControlAllowMethods:
> - "GET"
> - "POST"
> - "OPTIONS"
> - "DELETE"
> - "PATCH"
> - "PUT"
> accessControlAllowOriginListRegex:
> - "https://(.*?)XXXXX.net"
> - "https://(.*?)XXXXX.com"
> accessControlMaxAge: 100
> addVaryHeader: true
> 
> ```

You need to test your configuration by sending the request with the Origin header set. The easiest way is to use curl with the following extra arguments added:

`curl -i -H 'Origin: https://your-origin-address.org' https://example.org`

in the response, you should see the header `Access-Control-Allow-Origin` and the origin domain you set in your request.

If you find the better approach to validate CORS feel free to let us know 😉

Thank you,  
Jakub

---

<div class="post-metadata">

**Author:** ![bhakiagjunfikorty011](https://avatars.discourse-cdn.com/v4/letter/b/e480ec/32.png) [@bhakiagjunfikorty011](https://community.traefik.io/u/bhakiagjunfikorty011)\
**Post date:** [March 24, 2022, 9:27am UTC](https://community.traefik.io/t/cors-header-with-regex-list-on-kuberenetes/11900/3 "2022-03-24T09:27:46Z")

</div>

The CORS filter allows you to control which cross-origin requests Firefox allows.  
It is enabled by default.  
It may cause problems with your site, because there are some cases where sites need to be able to issue cross-origin requests that won't be allowed by default.  
If you have a CORS issue, please add a CORS policy.

Please note that CORS is not the same as Same-origin policy (SOP). SOP is also enabled by default.  
You may also need to disable SOP temporarily while debugging your site.  
For more information about CORS and SOP, please see the documentation on the Mozilla website .
