calcom / docker

The Docker configuration for Cal.com is an effort powered by people within the community. Cal.com, Inc. does not provide official support for Docker, but we will accept fixes and documentation. Use at your own risk.
MIT License
676 stars 346 forks source link

JSON Error on Login #321

Closed jdalrymple closed 8 months ago

jdalrymple commented 8 months ago

Summary

After a fresh install, I go to login and after about 20 seconds, i see this error pop up in the login screen:

image

Environment

Hosting service: GCP e2-small OS: Debian Bullseye

Config

I kept the defaults from here, however ive updated the NEXT_PUBLIC_WEBAPP_URL to be my own domain.

Additional Notes

After the first login, I am also greeted with the message: "You are admin but you do not have a password length of at least 15 characters or no 2FA yet Change Password to gain admin access", but this has been reported already https://github.com/calcom/cal.com/issues/9527, https://github.com/calcom/cal.com/issues/9690

I've also tried to set up 2FA but entering my password isnt accepted and occasionally It just closes the modal:

Screenshot from 2024-01-17 14-40-07

Updates!!

I do see this error in the browser console:

Error setting up two-factor authentication SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data two-factor-auth-5a03d5ad2d4dbd78.js:1:5962 handleSetup NextJS

update 2

It looks like the fetch call to '...api/auth/two-factor/totp/setup' is returning an internal server error, which then sends back the JSON error when the response.json() function is called.

update 3

Default config is outdated. The newer config file makes sure to specify the length of the encryption key:

# Application Key for symmetric encryption and decryption
# must be 32 bytes for AES256 encryption algorithm
# You can use: `openssl rand -base64 32` to generate one
CALENDSO_ENCRYPTION_KEY=

update 4

So even changing the key to a 32 byte key using the algo mentioned above, the error still persists:

: RangeError: Invalid key length
@calcom/web:start:     at Cipheriv.createCipherBase (node:internal/crypto/cipher:122:19)
@calcom/web:start:     at Cipheriv.createCipherWithIV (node:internal/crypto/cipher:141:3)
@calcom/web:start:     at new Cipheriv (node:internal/crypto/cipher:249:3)
@calcom/web:start:     at Object.createCipheriv (node:crypto:141:10)
@calcom/web:start:     at symmetricEncrypt (/calcom/apps/web/.next/server/chunks/69559.js:1:278)
@calcom/web:start:     at handler (/calcom/apps/web/.next/server/pages/api/auth/two-factor/totp/setup.js:1:2125) {
@calcom/web:start:   code: 'ERR_CRYPTO_INVALID_KEYLEN'

update 5

Doing some local testing with the touched code, it looks like the base64 encoding of the string generated through openssl rand -base64 32 command, is failing when converting into a buffer which sets the encoding to latin1, resulting in a 44 length string, not 32. This is what causes the error.

update 6

Temporary solution would be to just create a 32 character long alphanumeric string.

jdalrymple commented 8 months ago

Oh! lmk if i should post this in cal.com instead of the docker repo! I figured since im using the docker image id post it here, but I wasnt sure!