session icon indicating copy to clipboard operation
session copied to clipboard

enhance checkOptions to reject invalid signer objects

Open autopulated opened this issue 1 year ago • 3 comments

I passed a Buffer instead of a string as a secret, and this resulted in an error message that "cookieSigner.sign is not a function" an at request time, rather than at plugin registration.

Someone else had a similar issue in the past https://github.com/fastify/help/issues/852

This PR makes checkOptions more comprehensive (explicitly checking for .sign and .unsign methods on signer objects passed as options.secret), and adds associated tests, so that this error is caught sooner and with a helpful message :)

Checklist

autopulated avatar Apr 10 '24 15:04 autopulated

CI failed, can you take a look?

gurgunday avatar Apr 10 '24 15:04 gurgunday

@gurgunday It seems that the cookie "maxAge set by maxAge" test has a race condition, since the clock can run forwards 1ms between line 582 and line 583, changing the max age of the cookie from 1000 to 999.

autopulated avatar Apr 10 '24 15:04 autopulated

Yeah I remember now

gurgunday avatar Apr 10 '24 15:04 gurgunday