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 request blocked in Firefox but not other browsers

See original GitHub issue

I’m using aws-amplify to query API Gateway (configured through serverless) to trigger a lambda.

I have no trouble accessing some resources except for one, which I get using query string parameters. This is the only difference with the other queries. Yet, I get CORS error and cannot see any log for the lambda that should have been triggered nor can I see the query in the browser network console.

What confuses me is that I get this error only in firefox and not in chrome.

In my serverless configuration file for the endpoint, I do have cors to true:

  myEndpoint:
    handler: myEndpoint.main
    events:
      - http:
          path: myEndpoint
          method: get
          cors: true
          authorizer: aws_iam
          request:
            parameters:
              querystrings:
                x: true
                y: true
                z: true

I configured the custom authorizer

Resources:
  GatewayResponseDefault4XX:
    Type: 'AWS::ApiGateway::GatewayResponse'
    Properties:
      ResponseParameters:
         gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
         gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
      ResponseType: DEFAULT_4XX
      RestApiId:
        Ref: 'ApiGatewayRestApi'
  GatewayResponseDefault5XX:
    Type: 'AWS::ApiGateway::GatewayResponse'
    Properties:
      ResponseParameters:
         gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
         gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
      ResponseType: DEFAULT_5XX
      RestApiId:
        Ref: 'ApiGatewayRestApi'

In my lambda, I’m adding CORS headers before response

    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Credentials": true
    }

All of this is working well except for that one request with query string parameters, for which there’s a CORS error logged in the console, but not log in network and no log in CloudWatch.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://...?x=1&y=2&z=3. (Reason: CORS request did not succeed).[Learn More]

What makes it even harder for me to understand is that when I remove my parameters, I get a 502 error from the lambda (as should be) and can read what’s wrong in CloudWatch logs

    let params = {
      queryStringParameters: {
        x: 1,
        y: 2,
        z: 3
      }
    };
    API.get("api", '/myEndpoint', params); // this causes CORS error
    API.get("api", '/myEndpoint', {}); // this causes 502 (as it should)

Another thing that puzzles me is that this worked for a while and then stopped without me changing anything (except uploading a front-end to S3 and CloudFront but I fail to see where that could do something). I thought this might be caching issue but when I go to API Gateway > Stages > myStage, “Enable API cache” is not checked.

I’m really confused and would appreciate any help. Thank you.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
7hibaultcommented, Mar 6, 2019

This drove me crazy but I think I figured it out…

Turns out my browser was caching an incorrect preflight response. I didn’t figure this out right away because the behavior was the same in private mode. I deactivated my addons one by one and after deactivating Ghostery, the request went through.

@powerful23 Thanks for investigating 😃

6reactions
NWRichmondcommented, Sep 6, 2019

In my case, the Privacy Badger extension was blocking subdomains, which triggered a CORS error. There’s no need to remove this extension, though - just click on the Privacy Badger icon and slide any relevant “potential tracker” settings from blocked to allowed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is this CORS request failing only in Firefox?
ANSWER: While unrelated to the OP's specific case, it may help you to know that Firefox does not trust CA's (certificate authorities) in...
Read more >
Reason: CORS request did not succeed - HTTP | MDN
In many cases, it is caused by a browser plugin (e.g. an ad blocker or privacy protector) blocking the request. Other possible causes ......
Read more >
Firefox local development "CORS request not http"
As of update to v68 I get errors like these: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at...
Read more >
CORS error in Firefox incognito mode only - Mozilla Support
Whats happening is, I get the following error: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource ...
Read more >
CORS errors - HTTP - MDN Web Docs - Mozilla
Firefox's console displays messages in its console when requests fail due to CORS. Part of the error text is a "reason" message that...
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