question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cors mapping doesnt work with filters

See original GitHub issue

Describe the bug When filter is specified then CORS specified for mapping doesn’t work. As I understand maybe filters are applied before mapping, but I didn’t found any way for filter to be aplied after mapping or to pass OPTIONS request.

To Reproduce I have mapping and OIDC filter specified together for a service

apiVersion: getambassador.io/v2
kind: FilterPolicy
metadata:
  name: api-filter-policy
spec:
  rules:
    - host: api.example.com
      path: "*"
      filters:
        - name: api-filter
apiVersion: getambassador.io/v2
kind: Filter
metadata:
  name: api-filter
spec:
  OAuth2:
    authorizationURL: "https://keycloak.example.com/auth/realms/api"
    grantType: "AuthorizationCode"
    protectedOrigins:
      - origin: "https://api.example.com"
        internalOrigin: "*://*"
    audience: api-client
    clientID: api-client
    secret: "secretString"
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
  name: api-mapping
spec:
  host: api.example.com
  prefix: /
  service: api-service:8080
  cors:
    origins: '*'
    methods: '*'
    headers: '*'

Expected behavior A way for CORS to work with filters

Versions (please complete the following information):

  • Ambassador: 1.7.0
  • Kubernetes environment bare metal
  • Version v1.18.8

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:9

github_iconTop GitHub Comments

4reactions
paulwittcommented, Mar 2, 2021

We’re having the same issue. When the Filter and FilterPolicy aren’t in place the CORS mapping works just as expected. @havenotfear 's comment is an issue for us as our JWT Filter is the only token validation we have in place. If there was a way to link mappings to filterpolicies then we might be able to work around this using the method definition of the mapping. But as far as I can tell, the only thing linking filters/filterpolicies to mappings is the host definition.

(EDIT) We’re still testing it but I think this will work around the issue:

kind: FilterPolicy
metadata:
  name: my-service
  namespace: my-service
spec:
  rules:
  - host: my-service.my-domain.com
    path: "*"
    filters:
    - name: my-service
      namespace: my-service
      ifRequestHeader:
        name: ":method"
        value: "OPTIONS"
        negate: true
      arguments:
        ...```
4reactions
michael4screencommented, Feb 16, 2021

Hi @havenotfear ,

I came accross because i have the same issue right now. Your solution might work but you will allow any request to bypass your auth filter only by setting the Access-Control-Request-Method header. If i understand it correctly, your solution is not restricted to allow OPTIONS requests only. This is a security issue then.

Maybe you have found another solution already ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

cors mapping doesnt work with filters · Issue #2962 - GitHub
When filter is specified then CORS specified for mapping doesn't work. As I understand maybe filters are applied before mapping, ...
Read more >
CORS Filter not working as intended - Stack Overflow
CORS Filter not working as intended ; Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Read more >
Configuring CORS Filters
Enable CORS Filter. Open the WEB-INF/web.xml file of the web application where you want to enable CORS. For example, the default location of...
Read more >
How do I troubleshoot issues with CORS in AM (All versions)?
AM 7 and later: Check the CORS filter is enabled: Configuring CORS Support. AM 6.x: Add oauth2 to the CORSFilter filter-mapping in the...
Read more >
Enabling Cross Origin Requests for a RESTful Web Service
The browser is not required to send a CORS preflight request, but we could use @PostMapping and accept some JSON in the body...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found