Google authenticated user getting 500 response with no content

Site name: serene-haibt-7687a8

Hello, I have integrated Identity to my site using the identity plugin and has been working well so far, but I have an issue with a specific user who’s been getting an error with their Google authentication. This is the only user that is currently reporting the issue.

When making any authenticated request to my Netlify functions this user gets a 500 error response with no content at all. I have debugged my endpoints by updating the handlers like this

const handler: Handler = () => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      message: "OK",
    }),
  };
};

and still get a 500 error with no content in the body. It seems like this user triggers an error at an early stage in the API, the request never makes it to my handler.

I have been trying multiple things, and it seems that simply making a request using an Authorization header with a Bearer token from this user causes the error. A token from any other of my users (that I have for debugging) gets the expected response.

NOTE: The user in question is a family member, so I have access to their Gmail account. This is how I’ve been able to debug to this point.

Update: Going through the function logs I can confirm there are no executions of the handlers. The 500 error is coming from an early step. How can I get some more info about the error so I can help this user?

Which function are you having an issue with? Can you provide us a HAR file?

It happens with any of my Netlify functions when this specific user makes an authenticated request. I’ve created a special function just for debugging, that I’ve deployed to a preview environment. The handler looks like this

import type { Handler } from '@netlify/functions';

const handler: Handler = async () => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      message: 'OK',
    }),
  };
};

export { handler };

The result is the same: a 500 error with no content in the body. Also, there are no logs for this function in the Netlify dashboard, so I assume the handler just doesn’t get called.

Here’s the HAR file. I have redacted the user token.

{
  "log": {
    "version": "1.2",
    "creator": {
      "name": "WebInspector",
      "version": "537.36"
    },
    "pages": [
      {
        "startedDateTime": "2023-10-22T15:25:31.049Z",
        "id": "page_10",
        "title": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/",
        "pageTimings": {
          "onContentLoad": 760.8159999945201,
          "onLoad": 1295.8750000107102
        }
      }
    ],
    "entries": [
      {
        "_initiator": {
          "type": "script",
          "stack": {
            "callFrames": [
              {
                "functionName": "",
                "scriptId": "70",
                "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                "lineNumber": 1,
                "columnNumber": 1287932
              },
              {
                "functionName": "A",
                "scriptId": "70",
                "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                "lineNumber": 1,
                "columnNumber": 1253641
              },
              {
                "functionName": "",
                "scriptId": "70",
                "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                "lineNumber": 1,
                "columnNumber": 1254987
              },
              {
                "functionName": "",
                "scriptId": "70",
                "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                "lineNumber": 1,
                "columnNumber": 1254070
              },
              {
                "functionName": "eM",
                "scriptId": "70",
                "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                "lineNumber": 1,
                "columnNumber": 1259557
              },
              {
                "functionName": "n",
                "scriptId": "70",
                "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                "lineNumber": 1,
                "columnNumber": 1259761
              }
            ],
            "parent": {
              "description": "Promise.then",
              "callFrames": [
                {
                  "functionName": "eM",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259628
                },
                {
                  "functionName": "n",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259761
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259822
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259701
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1288066
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1290396
                },
                {
                  "functionName": "A",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1253641
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1254987
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1254070
                },
                {
                  "functionName": "eM",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259557
                },
                {
                  "functionName": "n",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259761
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259822
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1259701
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1290776
                },
                {
                  "functionName": "onClick",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 1291325
                },
                {
                  "functionName": "xM",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 345200
                },
                {
                  "functionName": "_M",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 345354
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 365254
                },
                {
                  "functionName": "ke",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 365348
                },
                {
                  "functionName": "Ie",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 365763
                },
                {
                  "functionName": "",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 371205
                },
                {
                  "functionName": "rO",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 434917
                },
                {
                  "functionName": "wM",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 344332
                },
                {
                  "functionName": "Pe",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 367057
                },
                {
                  "functionName": "Gz",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 351453
                },
                {
                  "functionName": "Qz",
                  "scriptId": "70",
                  "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/static/js/main.4f05ad08.js",
                  "lineNumber": 1,
                  "columnNumber": 351237
                }
              ]
            }
          }
        },
        "_priority": "High",
        "_resourceType": "fetch",
        "cache": {},
        "connection": "1518781",
        "pageref": "page_10",
        "request": {
          "method": "GET",
          "url": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/.netlify/functions/debugging",
          "httpVersion": "http/2.0",
          "headers": [
            {
              "name": ":authority",
              "value": "deploy-preview-10--serene-haibt-7687a8.netlify.app"
            },
            {
              "name": ":method",
              "value": "GET"
            },
            {
              "name": ":path",
              "value": "/.netlify/functions/debugging"
            },
            {
              "name": ":scheme",
              "value": "https"
            },
            {
              "name": "accept",
              "value": "*/*"
            },
            {
              "name": "accept-encoding",
              "value": "gzip, deflate, br"
            },
            {
              "name": "accept-language",
              "value": "en-GB,en-US;q=0.9,en;q=0.8,es;q=0.7"
            },
            {
              "name": "authorization",
              "value": "Bearer ******"
            },
            {
              "name": "cookie",
              "value": "_ga=GA1.1.1734536200.1697985400; nf_jwt=******; _ga_JZ9563TH49=GS1.1.1697988331.2.1.1697988331.0.0.0"
            },
            {
              "name": "referer",
              "value": "https://deploy-preview-10--serene-haibt-7687a8.netlify.app/"
            },
            {
              "name": "sec-ch-ua",
              "value": "\"Chromium\";v=\"118\", \"Google Chrome\";v=\"118\", \"Not=A?Brand\";v=\"99\""
            },
            {
              "name": "sec-ch-ua-mobile",
              "value": "?0"
            },
            {
              "name": "sec-ch-ua-platform",
              "value": "\"macOS\""
            },
            {
              "name": "sec-fetch-dest",
              "value": "empty"
            },
            {
              "name": "sec-fetch-mode",
              "value": "cors"
            },
            {
              "name": "sec-fetch-site",
              "value": "same-origin"
            },
            {
              "name": "user-agent",
              "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
            }
          ],
          "queryString": [],
          "cookies": [
            {
              "name": "_ga",
              "value": "GA1.1.1734536200.1697985400",
              "path": "/",
              "domain": ".deploy-preview-10--serene-haibt-7687a8.netlify.app",
              "expires": "2024-11-25T14:36:40.038Z",
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "nf_jwt",
              "value": "******",
              "path": "/",
              "domain": "deploy-preview-10--serene-haibt-7687a8.netlify.app",
              "expires": "1969-12-31T23:59:59.000Z",
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "_ga_JZ9563TH49",
              "value": "GS1.1.1697988331.2.1.1697988331.0.0.0",
              "path": "/",
              "domain": ".deploy-preview-10--serene-haibt-7687a8.netlify.app",
              "expires": "2024-11-25T15:25:31.640Z",
              "httpOnly": false,
              "secure": false
            }
          ],
          "headersSize": -1,
          "bodySize": 0
        },
        "response": {
          "status": 500,
          "statusText": "Internal Server Error",
          "httpVersion": "http/2.0",
          "headers": [
            {
              "name": "age",
              "value": "0"
            },
            {
              "name": "content-length",
              "value": "0"
            },
            {
              "name": "date",
              "value": "Sun, 22 Oct 2023 15:25:42 GMT"
            },
            {
              "name": "server",
              "value": "Netlify"
            },
            {
              "name": "strict-transport-security",
              "value": "max-age=31536000; includeSubDomains; preload"
            },
            {
              "name": "x-nf-request-id",
              "value": "01HDBZVWQKCKM65KBHT9RP3MB5"
            }
          ],
          "cookies": [],
          "content": {
            "size": 0,
            "mimeType": "x-unknown",
            "text": ""
          },
          "redirectURL": "",
          "headersSize": -1,
          "bodySize": -1,
          "_transferSize": 63,
          "_error": null
        },
        "serverIPAddress": "35.156.224.161",
        "startedDateTime": "2023-10-22T15:25:42.461Z",
        "time": 147.4519999756012,
        "timings": {
          "blocked": 1.5329999835602939,
          "dns": -1,
          "ssl": -1,
          "connect": -1,
          "send": 0.35100000000000003,
          "wait": 145.12300000873952,
          "receive": 0.44499998330138624,
          "_blocked_queueing": 1.197999983560294
        }
      }
    ]
  }
}

Note: If I take the user token and use Postman to replicate the request against my local machine there is no error. So the error actually happens on live deployments.

We’re seeing this error in the logs:

InvalidRequestContentException: Size of client context (4094) exceeds maximum client context size of 3584

This error comes from AWS Lambda. Have you by any chance included a lot of information in the Identity data for the user? I’m assuming the metadata for that is going over the limits.

I have not included any additional data other than the default. Everything in the user context comes from the Google authentication. I have no idea what is Google sending as part of the user context.

I have to say this user is a chile with a “supervised” Google account, belonging to a Google family, and is the only user that has reported such an issue. I suspect this can be related to the amount of information in the user context.

I’ve asked the devs to check what could be causing this for us.

Any updates on this?

None so far. We’ll post here once we have more info.

Hi @mapolonio,

Can you please check if this is resolved for you now?

And if it’s not, could you please share the email address of the user who’s experiencing this?

No, still not working. The issue remains. How can I send you the email without exposing it publicly?

Feel free to DM me the email address.

Hey there!

I hope all is well, and thank you again for your patience while our team worked to get to the bottom of this issue.

We’ve shipped a few fixes we can apply to your site that will allow us to reduce the amount of data sent to the lambda context.

We’d first like to confirm, however, that you’re accessing the identity context per our updated documentation. Once confirmed, we’ll be able to roll out this fix for your site. Looking forward to hearing from you!

Hello. I’m trying to follow the updated documentation but I’m getting the following error:

TypeError: Cannot read properties of undefined (reading 'netlify')

It happens at in this block

const { clientContext } = context;
const rawNetlifyContext = clientContext.custom.netlify;
const netlifyContext = Buffer.from(rawNetlifyContext, 'base64').toString(
  'utf-8',
);
const { user } = JSON.parse(netlifyContext);

Thanks for following up!

Can you expand the snippet to include the function in its entirety (or DM us a snippet/gist of the function code)? This will help us take a closer look at the error you’re seeing and provide additional context to our engineering team if needed. Thanks again!

I updated one of my functions specifically following the example to see how it works, so I don’t think it will add anything. Anyway, here it is

import type { Handler, HandlerContext, HandlerEvent } from '@netlify/functions';

const handler: Handler = async function (
  event: HandlerEvent,
  context: HandlerContext,
) {
  const rawNetlifyContext = context.clientContext?.custom.netlify;
  const netlifyContext = Buffer.from(rawNetlifyContext, 'base64').toString(
    'utf-8',
  );
  const { user } = JSON.parse(netlifyContext);

  console.log(user);

  return {
    statusCode: 200,
    body: 'ok',
  };
};

export { handler };

The error:

Function get-game-status has returned an error: Cannot read properties of undefined (reading 'netlify')
    at Object.handler (/Users/xxxxxxxxx/projects/wordl/src/functions/get-game-status.ts:7:52)
    at executeLambdaFunc (/Users/xxxxxxxxx/.nvm/versions/node/v18.18.2/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js:352:51)
    at Object._executeSync (/Users/xxxxxxxxx/.nvm/versions/node/v18.18.2/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js:377:13)
    at /Users/xxxxxxxxx/.nvm/versions/node/v18.18.2/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js:96:26
    at new Promise (<anonymous>)
    at Object.execute (/Users/xxxxxxxxx/.nvm/versions/node/v18.18.2/lib/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js:88:16)
    at invokeFunctionDirectly (file:///Users/xxxxxxxxx/.nvm/versions/node/v18.18.2/lib/node_modules/netlify-cli/src/lib/functions/runtimes/js/index.js:84:38)
    at Module.invokeFunction (file:///Users/xxxxxxxxx/.nvm/versions/node/v18.18.2/lib/node_modules/netlify-cli/src/lib/functions/runtimes/js/index.js:47:22)
    at NetlifyFunction.invoke (file:///Users/xxxxxxxxx/.nvm/versions/node/v18.18.2/lib/node_modules/netlify-cli/src/lib/functions/netlify-function.js:182:47)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

I’m using netlify-cli v17.10.1 and @netlify/functions v2.4.1

Does this work when deployed? This is probably an issue with the CLI which is being worked upon.

The CLI fix has been released in v17.10.2.

Thanks. The new CLI version works locally. However I deployed a new branch to test the new context API and encountered the same issu from the original post. Here’s the HAR file in case you wish to check it:

deploy-preview-15–serene-haibt-7687a8.netlify.app.har (12.8 KB)