Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies not set if secureCookieAttribute and httpOnlyCookieAttribute is true #938

Closed
donn1123 opened this issue Oct 29, 2024 · 3 comments
Closed
Labels
bug A bug that needs to be resolved pending An issue waiting for triage

Comments

@donn1123
Copy link

Environment

Reproduction

Here's my auth setup in nuxt.config

auth: {
baseURL: '<API_URL>',
globalAppMiddleware: true,

provider: {
  type: 'local',
  endpoints: {
    signIn: { path: '<api>', method: 'post' },
    getSession: { path: '<api>', method: 'get' },
  },
  token: {
    signInResponseTokenPointer: '/access',
    maxAgeInSeconds: 300,
    sameSiteAttribute: 'none',
    secureCookieAttribute: process.env.NODE_ENV === 'production',
    httpOnlyCookieAttribute: process.env.NODE_ENV === 'production',
  },
  refresh: {
    isEnabled: true,
    endpoint: { path: '<api>', method: 'post' },
    refreshOnlyToken: true,
    token: {
      signInResponseRefreshTokenPointer: '/refresh',
      refreshRequestTokenPointer: '/refresh',
      maxAgeInSeconds: 60 * 60 * 24 * 1,
      sameSiteAttribute: 'none',
      secureCookieAttribute: process.env.NODE_ENV === 'production',
      httpOnlyCookieAttribute: process.env.NODE_ENV === 'production',
    },
  },
},

},

Describe the bug

When I refresh the page it goes back to login page again. I notice that the auth.token and refresh token are not set in browser cookies. In my local or even in prod, when I set secureCookieAttribute and httpOnlyCookieAttribute to false, the tokens are added and everything works just fine. The problem only happens when I set TRUE secureCookieAttribute and httpOnlyCookieAttribute.

My backend where I call the api is using JWT and I also tried adding
Set-Cookie: auth.token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...; HttpOnly; Secure; SameSite=Lax; Path=/; Expires=<some expiration date> in the login api response.

Additional context

No response

Logs

No response

@donn1123 donn1123 added bug A bug that needs to be resolved pending An issue waiting for triage labels Oct 29, 2024
@julienguillot77
Copy link

I’m facing same issue. Please someone can fix it ?

@Aniket-Harmoney
Copy link

Aniket-Harmoney commented Dec 17, 2024

Hi, is this issue being solved for. Because I'm in dire need of setting httpOnly cookies and setting httpOnlyAtrribute to true in nuxt.config.ts is just not working. If not then is there any workaround I can do for this, need to solve this as security risk asap? @zoey-kaiser

@zoey-kaiser
Copy link
Member

zoey-kaiser commented Dec 17, 2024

Hey everyone 👋

I am responably sure that this issue is a duplicate of #851. Therefore I would continue the discussion there around httpOnly not being correctly set!

@donn1123, one thing I noticed that in your nuxt.config.ts you are setting some values dynamically using process.env.NODE_ENV === 'production'.

The nuxt.config.ts gets compiled at build time (when you run nuxi build) and not at runtime (when you start the built application). Therefore if you do not set the NODE_ENV to production when building this could cause issues.

I cannot know if this could affect you, however I did just want to point out that pitfall, as it could create potenial issue 😊

@zoey-kaiser zoey-kaiser closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that needs to be resolved pending An issue waiting for triage
Projects
None yet
Development

No branches or pull requests

4 participants