[GH-ISSUE #8585] Cookies are not being chunked #11126

Open
opened 2026-04-13 07:29:52 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @johnf on GitHub (Mar 13, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8585

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  • Better auth config with Entra
  • The user data needs to generate a session cookie that is approx 4069 but less than 4093

Current vs. Expected behavior

Cookie is too big and not being chunked

What version of Better Auth are you using?

1.4.18

System info

"system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#202602262342 SMP PREEMPT_DYNAMIC Fri Feb 27 00:13:55 UTC 2026",
    "release": "6.19.4-061904-generic",
    "cpuCount": 32,
    "cpuModel": "AMD Ryzen 9 7950X 16-Core Processor",
    "totalMemory": "29.99 GB",
    "freeMemory": "6.59 GB"
  },
  "node": {
    "version": "v24.14.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.9.0"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "^19.2.4"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.17.2"
    }
  ],
  "betterAuth": {
    "version": "^1.4.18",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

return betterAuth({
    logger: {
      level: 'debug',
    },
    account: {
      storeAccountCookie: false, // NOTE: Don't store the account data as the cookie is too big
    },
    session: {
      cookieCache: {
        maxAge: 60 * 60 * 24 * 1, // 1 day
        refreshAge: true,
      },
    },
    secret: config.AUTH_SECRET,
    advanced: {
      cookiePrefix: 'abc-admin',
    },
    socialProviders: {
      microsoft: {
        clientId: config.AUTH_MICROSOFT_ENTRA_ID_ID,
        clientSecret: config.AUTH_MICROSOFT_ENTRA_ID_SECRET,
        tenantId: config.AUTH_MICROSOFT_ENTRA_ID_TENANT_ID,
      },
    },
    plugins: [
      tanstackStartCookies(), // NOTE: Must be last
    ],
  });

Additional context

I'm pretty sure the recent cookie chunking work missed something.

In https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/cookies/index.ts#L234

// Check if we need to chunk the cookie (only if it exceeds 4093 bytes)
	if (data.length > 4093) {

This doesn't use the more sophisticated logic that was implemented in https://github.com/better-auth/better-auth/pull/6393

/cc @jslno

Originally created by @johnf on GitHub (Mar 13, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8585 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce * Better auth config with Entra * The user data needs to generate a session cookie that is approx 4069 but less than 4093 * ### Current vs. Expected behavior Cookie is too big and not being chunked ### What version of Better Auth are you using? 1.4.18 ### System info ```bash "system": { "platform": "linux", "arch": "x64", "version": "#202602262342 SMP PREEMPT_DYNAMIC Fri Feb 27 00:13:55 UTC 2026", "release": "6.19.4-061904-generic", "cpuCount": 32, "cpuModel": "AMD Ryzen 9 7950X 16-Core Processor", "totalMemory": "29.99 GB", "freeMemory": "6.59 GB" }, "node": { "version": "v24.14.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.9.0" }, "frameworks": [ { "name": "react", "version": "^19.2.4" } ], "databases": [ { "name": "pg", "version": "^8.17.2" } ], "betterAuth": { "version": "^1.4.18", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript return betterAuth({ logger: { level: 'debug', }, account: { storeAccountCookie: false, // NOTE: Don't store the account data as the cookie is too big }, session: { cookieCache: { maxAge: 60 * 60 * 24 * 1, // 1 day refreshAge: true, }, }, secret: config.AUTH_SECRET, advanced: { cookiePrefix: 'abc-admin', }, socialProviders: { microsoft: { clientId: config.AUTH_MICROSOFT_ENTRA_ID_ID, clientSecret: config.AUTH_MICROSOFT_ENTRA_ID_SECRET, tenantId: config.AUTH_MICROSOFT_ENTRA_ID_TENANT_ID, }, }, plugins: [ tanstackStartCookies(), // NOTE: Must be last ], }); ``` ### Additional context I'm pretty sure the recent cookie chunking work missed something. In https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/cookies/index.ts#L234 ``` // Check if we need to chunk the cookie (only if it exceeds 4093 bytes) if (data.length > 4093) { ``` This doesn't use the more sophisticated logic that was implemented in https://github.com/better-auth/better-auth/pull/6393 /cc @jslno
GiteaMirror added the corebug labels 2026-04-13 07:29:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11126