Skip to content

Commit b2e9f57

Browse files
committed
fix(security): hash wealthbox fallback token identity, guard undefined userId
- Replace base64 encoding with SHA-256 hash for fallback token-derived identity so raw token bytes are never stored in the DB - Return null early when Wealthbox API response lacks an id field to prevent all such users colliding on the wealthbox-undefined account
1 parent d3bd321 commit b2e9f57

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

apps/sim/lib/auth/auth.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createHash } from 'crypto'
12
import { cache } from 'react'
23
import { sso } from '@better-auth/sso'
34
import { stripe } from '@better-auth/stripe'
@@ -1630,6 +1631,9 @@ export const auth = betterAuth({
16301631
if (response.ok) {
16311632
const data = await response.json()
16321633
const userId = data.id?.toString()
1634+
if (!userId) {
1635+
return null
1636+
}
16331637
const email =
16341638
data.email && typeof data.email === 'string'
16351639
? data.email
@@ -1660,7 +1664,7 @@ export const auth = betterAuth({
16601664
logger.error('Wealthbox fallback identity: no refresh or access token available')
16611665
return null
16621666
}
1663-
const tokenHash = Buffer.from(stableToken).toString('base64').slice(0, 24)
1667+
const tokenHash = createHash('sha256').update(stableToken).digest('hex').slice(0, 24)
16641668
return {
16651669
id: `wealthbox-${tokenHash}`,
16661670
name: 'Wealthbox User',

0 commit comments

Comments
 (0)