A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat: Add support for configurable ID token signing algorithm in OAuth (#2850)
CertStoneb2b2579baa3a
diff --git a/apps/web/server/auth.ts b/apps/web/server/auth.tsindex 63a8ae06..68023f26 100644--- a/apps/web/server/auth.ts+++ b/apps/web/server/auth.ts@@ -174,6 +174,13 @@ if (oauth.wellKnownUrl) {authorization: { params: { scope: oauth.scope } },clientId: oauth.clientId,clientSecret: oauth.clientSecret,+ ...(oauth.idTokenSignedResponseAlg+ ? {+ client: {+ id_token_signed_response_alg: oauth.idTokenSignedResponseAlg,+ },+ }+ : {}),allowDangerousEmailAccountLinking: oauth.allowDangerousEmailAccountLinking,checks: ["pkce", "state"],httpOptions: {diff --git a/docs/docs/03-configuration/01-environment-variables.md b/docs/docs/03-configuration/01-environment-variables.mdindex 6a9a977c..3eda1af8 100644--- a/docs/docs/03-configuration/01-environment-variables.md+++ b/docs/docs/03-configuration/01-environment-variables.md@@ -65,19 +65,20 @@ Only OIDC compliant OAuth providers are supported! For information on how to setWhen setting up OAuth, the allowed redirect URLs configured at the provider should be set to `<KARAKEEP_ADDRESS>/api/auth/callback/custom` where `<KARAKEEP_ADDRESS>` is the address you configured in `NEXTAUTH_URL` (for example: `https://try.karakeep.app/api/auth/callback/custom`).:::-| Name | Required | Default | Description |-| ------------------------------------------- | -------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| DISABLE_SIGNUPS | No | false | If enabled, no new signups will be allowed and the signup button will be disabled in the UI |-| DISABLE_PASSWORD_AUTH | No | false | If enabled, only signups and logins using OAuth are allowed and the signup button and login form for local accounts will be disabled in the UI |+| Name | Required | Default | Description |+| ------------------------------------------- | -------- | ---------------------- | ------------------------------------------------------------ |+| DISABLE_SIGNUPS | No | false | If enabled, no new signups will be allowed and the signup button will be disabled in the UI |+| DISABLE_PASSWORD_AUTH | No | false | If enabled, only signups and logins using OAuth are allowed and the signup button and login form for local accounts will be disabled in the UI || EMAIL_VERIFICATION_REQUIRED | No | false | Whether email verification is required during user signup. If enabled, users must verify their email address before they can use their account. If you enable this, you must configure SMTP settings. |-| OAUTH_AUTO_REDIRECT | No | false | If enabled and password authentication is disabled, automatically redirect to the OAuth provider instead of showing the login page. Useful when OAuth is the only authentication method available. |-| OAUTH_WELLKNOWN_URL | No | Not set | The "wellknown Url" for openid-configuration as provided by the OAuth provider |-| OAUTH_CLIENT_SECRET | No | Not set | The "Client Secret" as provided by the OAuth provider |-| OAUTH_CLIENT_ID | No | Not set | The "Client ID" as provided by the OAuth provider |-| OAUTH_SCOPE | No | "openid email profile" | "Full list of scopes to request (space delimited)" |-| OAUTH_PROVIDER_NAME | No | "Custom Provider" | The name of your provider. Will be shown on the signup page as "Sign in with `<name>`" |-| OAUTH_ALLOW_DANGEROUS_EMAIL_ACCOUNT_LINKING | No | false | Whether existing accounts in karakeep stored in the database should automatically be linked with your OAuth account. Only enable it if you trust the OAuth provider! |-| OAUTH_TIMEOUT | No | 3500 | The wait time in milliseconds for the OAuth provider response. Increase this if you are having `outgoing request timed out` errors |+| OAUTH_AUTO_REDIRECT | No | false | If enabled and password authentication is disabled, automatically redirect to the OAuth provider instead of showing the login page. Useful when OAuth is the only authentication method available. |+| OAUTH_WELLKNOWN_URL | No | Not set | The "wellknown Url" for openid-configuration as provided by the OAuth provider |+| OAUTH_CLIENT_SECRET | No | Not set | The "Client Secret" as provided by the OAuth provider |+| OAUTH_CLIENT_ID | No | Not set | The "Client ID" as provided by the OAuth provider |+| OAUTH_ID_TOKEN_SIGNED_RESPONSE_ALG | No | Not set | The expected JWS signing algorithm for OIDC ID tokens. Set this when your provider signs ID tokens with an algorithm other than the default. If unset, Karakeep leaves the algorithm unspecified and the underlying OIDC client uses its default behavior, which is typically RS256. If this does not match the provider's ID token algorithm, OAuth login can fail during callback with an unexpected JWT algorithm error. Supported values: `RS256`, `RS384`, `RS512`, `PS256`, `PS384`, `PS512`, `ES256`, `ES384`, `ES512`, `EdDSA`. |+| OAUTH_SCOPE | No | "openid email profile" | "Full list of scopes to request (space delimited)" |+| OAUTH_PROVIDER_NAME | No | "Custom Provider" | The name of your provider. Will be shown on the signup page as "Sign in with `<name>`" |+| OAUTH_ALLOW_DANGEROUS_EMAIL_ACCOUNT_LINKING | No | false | Whether existing accounts in karakeep stored in the database should automatically be linked with your OAuth account. Only enable it if you trust the OAuth provider! |+| OAUTH_TIMEOUT | No | 3500 | The wait time in milliseconds for the OAuth provider response. Increase this if you are having `outgoing request timed out` errors |For more information on `OAUTH_ALLOW_DANGEROUS_EMAIL_ACCOUNT_LINKING`, check the [next-auth.js documentation](https://next-auth.js.org/configuration/providers/oauth#allowdangerousemailaccountlinking-option).diff --git a/packages/shared/config.ts b/packages/shared/config.tsindex 95f830af..2846ae46 100644--- a/packages/shared/config.ts+++ b/packages/shared/config.ts@@ -16,6 +16,21 @@ const optionalStringBool = () =>.transform((s) => s === "true").optional();+// Only asymmetric algorithms are supported here because ID tokens are verified+// against the provider's JWKS. Do not add "none" or symmetric HS* algorithms.+const oauthIdTokenSignedResponseAlg = z.enum([+ "RS256",+ "RS384",+ "RS512",+ "PS256",+ "PS384",+ "PS512",+ "ES256",+ "ES384",+ "ES512",+ "EdDSA",+]);+const allEnv = z.object({PORT: z.coerce.number().default(3000),WORKERS_HOST: z.string().default("127.0.0.1"),@@ -52,6 +67,7 @@ const allEnv = z.object({OAUTH_WELLKNOWN_URL: z.string().url().optional(),OAUTH_CLIENT_SECRET: z.string().optional(),OAUTH_CLIENT_ID: z.string().optional(),+ OAUTH_ID_TOKEN_SIGNED_RESPONSE_ALG: oauthIdTokenSignedResponseAlg.optional(),OAUTH_TIMEOUT: z.coerce.number().optional().default(3500),OAUTH_SCOPE: z.string().default("openid email profile"),OAUTH_PROVIDER_NAME: z.string().default("Custom Provider"),@@ -285,6 +301,7 @@ const serverConfigSchema = allEnv.transform((val, ctx) => {wellKnownUrl: val.OAUTH_WELLKNOWN_URL,clientSecret: val.OAUTH_CLIENT_SECRET,clientId: val.OAUTH_CLIENT_ID,+ idTokenSignedResponseAlg: val.OAUTH_ID_TOKEN_SIGNED_RESPONSE_ALG,scope: val.OAUTH_SCOPE,name: val.OAUTH_PROVIDER_NAME,timeout: val.OAUTH_TIMEOUT,