fix(auth): update auth stack and remove token logging

Upgrade better-auth and @better-auth/passkey to 1.7.12 and hono to
4.13.13, which clears every auth-related advisory in pnpm audit. The
lockfile also picks up patched kysely, @simplewebauthn/server and defu.

Drop the Set-Cookie and cookie-name logging that exposed session tokens,
match ADMIN_EMAIL case-insensitively, revoke admin sessions when
ADMIN_PASSWORD_RESET rotates the password, and require user verification
for passkeys.
This commit is contained in:
Chris Scott committed 2026-10-21 11:00:15 -04:00
1 parent 959ed8ca2e
commit eb3937ef7e
11 files changed
+426 -258

No files matched your search

+1 -1
View File
@@ -69,7 +69,7 @@ export function createAuth(db: Database) {
origin: ENV.AUTH.PASSKEY_ORIGIN,
authenticatorSelection: {
residentKey: 'required',
userVerification: 'preferred',
userVerification: 'required',
},
}),
],
+1 -6
View File
@@ -16,7 +16,6 @@ export function createAuthMiddleware(
user: Session['user']
}
}>(async (c, next) => {
const cookies = c.req.header('cookie')
const origin = c.req.header('origin')
const fetchSite = c.req.header('sec-fetch-site')
@@ -30,11 +29,7 @@ export function createAuthMiddleware(
return c.json({ error: 'Cross-site request rejected' }, 403)
}
logger.debug(`Auth check - Path: ${c.req.path}, Origin: ${origin}, Has cookies: ${!!cookies}`)
if (cookies) {
const cookieNames = cookies.split(';').map(c => c.trim().split('=')[0]).join(', ')
logger.debug(`Cookie names: ${cookieNames}`)
}
logger.debug(`Auth check - Path: ${c.req.path}, Origin: ${origin}`)
let session
try {
+11 -19
View File
@@ -8,19 +8,7 @@ import { hashPassword } from 'better-auth/crypto'
export function createAuthRoutes(auth: AuthInstance): Hono {
const app = new Hono()
app.all('/*', async (c) => {
const response = await auth.handler(c.req.raw)
const setCookie = response.headers.get('set-cookie')
if (c.req.path.includes('sign-in')) {
logger.info(`Sign-in response - Status: ${response.status}, Set-Cookie: ${setCookie ? 'present' : 'missing'}`)
if (setCookie) {
logger.debug(`Set-Cookie header: ${setCookie.substring(0, 100)}...`)
}
}
return response
})
app.all('/*', (c) => auth.handler(c.req.raw))
return app
}
@@ -31,16 +19,20 @@ export async function syncAdminFromEnv(auth: AuthInstance, db: Database): Promis
const adminEmail = ENV.AUTH.ADMIN_EMAIL!
const adminPassword = ENV.AUTH.ADMIN_PASSWORD!
const existingUser = db.prepare('SELECT id, email FROM "user" WHERE email = ?').get(adminEmail) as { id: string; email: string } | undefined
const existingUser = db.prepare('SELECT id, email FROM "user" WHERE lower(email) = lower(?)').get(adminEmail) as { id: string; email: string } | undefined
if (existingUser) {
if (ENV.AUTH.ADMIN_PASSWORD_RESET) {
const hashedPassword = await hashPassword(adminPassword)
db.prepare('UPDATE "account" SET password = ? WHERE "userId" = ? AND "providerId" = ?').run(
hashedPassword,
existingUser.id,
'credential'
)
const resetAdminCredentials = db.transaction(() => {
db.prepare('UPDATE "account" SET password = ? WHERE "userId" = ? AND "providerId" = ?').run(
hashedPassword,
existingUser.id,
'credential'
)
db.prepare('DELETE FROM "session" WHERE "userId" = ?').run(existingUser.id)
})
resetAdminCredentials()
logger.info(`Admin password reset from environment for ${adminEmail}`)
logger.warn('Remove ADMIN_PASSWORD_RESET=true from environment after password reset')
}
+1 -1
View File
@@ -41,7 +41,7 @@ export function createRepoGitRoutes(
logMessage: string,
handler: (repo: Repo, id: number) => Promise<Response>,
): Promise<Response> {
const id = parseInt(c.req.param('id'))
const id = Number.parseInt(c.req.param('id') ?? '', 10)
const repo = getRepoById(database, id)
if (!repo) {
+1 -1
View File
@@ -52,7 +52,7 @@ export function createRepoTerminalSocketRoutes(
upgradeWebSocket((c) => {
const directory = c.get('terminalDirectory')
const cursor = c.get('terminalCursor')
const ptyID = c.req.param('ptyID')
const ptyID = c.req.param('ptyID') ?? ''
return createBridgedSocketEvents((peer) => terminalService.connect(directory, ptyID, cursor, peer))
}),