Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ₯… Catches and warns on truncated numeric clientId (#1941)

Alicia Sykesd2940e246295
diff --git a/docs/authentication.md b/docs/authentication.md
index 25982129..9ed81333 100644
--- a/docs/authentication.md
+++ b/docs/authentication.md
@@ -360,7 +360,7 @@ appConfig:
auth:
enableOidc: true
oidc:
- clientId: [registered client id]
+ clientId: ['registered client id']
endpoint: [OIDC endpoint]
scope: [The scope(s) to request from the OIDC provider]
adminGroup: admin
@@ -368,6 +368,8 @@ appConfig:
Because Dashy is a SPA, a [public client](https://datatracker.ietf.org/doc/html/rfc6749#section-2.1) registration with PKCE is needed.
+Note, that if your `clientId` is numeric, you must place it in quotes. Otherwise it will be interpreted as a number and truncated to 64 chars!
+
An example for Authelia is shared below, but other OIDC systems can be used:
```yaml
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 170dcb39..c360b397 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -18,6 +18,7 @@
- [Auth Validation Error: "should be object"](#auth-validation-error-should-be-object)
- [App Not Starting After Update to 2.0.4](#app-not-starting-after-update-to-204)
- [Keycloak Redirect Error](#keycloak-redirect-error)
+- [OIDC or Keycloak failure on numeric client IDs](#oidc-or-keycloak-failure-on-numeric-client-ids)
- [Docker Directory Error](#docker-directory)
- [Config not Saving on Vercel / Netlify / CDN](#user-content-config-not-saving-on-vercel--netlify--cdn)
- [Config Not Updating](#config-not-updating)
@@ -267,6 +268,29 @@ See also: #479, #409, #507, #491, #341, #520
---
+## OIDC or Keycloak failure on numeric client IDs
+
+If your IdP rejects the login with an *"invalid client"* / *"client not found"* error, and your `clientId` is a long numeric value, the cause is almost certainly YAML number parsing.
+
+YAML parses unquoted numeric tokens as Numbers, and JavaScript can't represent integers larger than 2^53 (~16 digits) without losing precision. So an unquoted numeric `clientId` will be silently truncated (e.g. `918756876419824312` β†’ `918756876419824300`), or β€” for very large values β€” converted to scientific notation (e.g. `9.187568764198242e+37`), and the IdP will reject it.
+
+The fix is to wrap the `clientId` in quotes in your `conf.yml` so it gets parsed as a string:
+
+```yaml
+appConfig:
+ auth:
+ enableOidc: true
+ oidc:
+ clientId: "918756876419824312"
+ endpoint: https://idp.example.com/
+```
+
+The same applies to `auth.keycloak.clientId`. Dashy will print a warning in the [browser console](#how-to-open-browser-console) when it detects a numeric `clientId`, to help diagnose this.
+
+See also: #1941
+
+---
+
## Docker Directory
```text
diff --git a/src/utils/KeycloakAuth.js b/src/utils/KeycloakAuth.js
index 58af0031..bcd333f6 100644
--- a/src/utils/KeycloakAuth.js
+++ b/src/utils/KeycloakAuth.js
@@ -20,6 +20,13 @@ class KeycloakAuth {
const {
serverUrl, realm, clientId, idpHint, legacySupport,
} = auth.keycloak;
+ if (typeof clientId === 'number' && !Number.isSafeInteger(clientId)) {
+ ErrorHandler(
+ 'Keycloak clientId appears invalid. ',
+ 'You passed it as a number, and it is too long to be parsed without loosing precision. ',
+ 'Wrap it in quotes in your conf.yml (e.g. clientId: "12345") to force it to be a string. ',
+ );
+ }
const url = legacySupport ? `${serverUrl}/auth` : serverUrl;
const initOptions = { url, realm, clientId };
const loginOptions = idpHint ? { idpHint } : {};
diff --git a/src/utils/OidcAuth.js b/src/utils/OidcAuth.js
index f001ba5f..957c3144 100644
--- a/src/utils/OidcAuth.js
+++ b/src/utils/OidcAuth.js
@@ -25,10 +25,17 @@ class OidcAuth {
adminGroup,
adminRole,
} = auth.oidc;
+ if (typeof clientId === 'number' && !Number.isSafeInteger(clientId)) {
+ ErrorHandler(
+ 'Your OIDC appears invalid. ',
+ 'You passed it as a number, and it is too long to be parsed without loosing precision. ',
+ 'Wrap it in quotes in your conf.yml (e.g. clientId: "12345") to force it to be a string. ',
+ );
+ }
const settings = {
userStore: new WebStorageStateStore({ store: window.localStorage }),
authority: endpoint,
- client_id: clientId,
+ client_id: String(clientId),
redirect_uri: `${window.location.origin}`,
response_type: 'code',
scope: scope || 'openid profile email roles groups',