elysia icon indicating copy to clipboard operation
elysia copied to clipboard

onError handler isn't getting called during INVALID_COOKIE_SIGNATURE

Open binamralamsal opened this issue 1 year ago • 2 comments
trafficstars

What version of Elysia.JS is running?

1.0.26

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

 .onError(({ code, set, cookie: { accessToken, refreshToken } }) => {
    if (code === "NOT_FOUND")
      return { error: "Route not found :(", status: STATUS.ERROR };

    if (code === "INVALID_COOKIE_SIGNATURE")
      return { error: "Your cookies has been altered", status: STATUS.ERROR };

    set.status = 500;
    return { error: "Internal Server Error", status: STATUS.ERROR };
  })

What is the expected behavior?

When cookies have been altered, it should respond with the format { error: "...", status: "ERROR" }

What do you see instead?

I am just getting raw text when cookies have been altered. onError is not getting called.

Additional information

No response

binamralamsal avatar Jul 07 '24 10:07 binamralamsal

I am not sure if it's related but when I have separate UI and backend, CORS error is occuring if cookies are altered.

binamralamsal avatar Jul 08 '24 12:07 binamralamsal

Same issue here for WSL, on elysia 1.1.13. Also, it seems it works fine on aot: false case

Minimal reproduction example:

import Elysia from 'elysia';

export const app = new Elysia({
  cookie: { secrets: 'secret', sign: ['session'] },
})
  .onError(({ error }) => {
    console.log(error);
    return {};
  })
  .get('', ({ cookie: { session } }) => {
    console.log(session);
  })
  .listen(3000);
console.log('listening on port 3000');

Other errors prints the error and return {} as response But when try sending request with cookie session=1234, error is not caught at all

nxht avatar Sep 20 '24 04:09 nxht

Yeah, same issue but it happens for me with code==="VALIDATION" Also @nxht, doing aot:false worked for me too.

sancho1952007 avatar May 20 '25 16:05 sancho1952007

Closing as https://github.com/elysiajs/elysia/pull/839#issuecomment-2661407310

SaltyAom avatar Aug 01 '25 14:08 SaltyAom