fix(settings): validate git identity emails only on the request path

A stored identity email that failed the stricter rule made every settings
read fall back to defaults, and the next save persisted that reset.

- the stored preferences schema accepts any email string again
- PATCH /api/settings rejects an invalid gitIdentity or gitIdentities email
  with a field path, and saves the trimmed address
- the rule accepts local hosts such as root@localhost
This commit is contained in:
Chris Scott committed 2026-10-23 15:45:36 -04:00
1 parent d089dde466
commit 0c4c024dcc
4 files changed
+157 -17

No files matched your search

+31 -1
View File
@@ -12,6 +12,7 @@ import type { OpenCodeClient } from '../services/opencode/client'
import { getAgentsMdPath } from '@opencode-manager/shared/config/env'
import {
UserPreferencesSchema,
isValidGitIdentityEmail,
type SandboxPreferences,
type UserPreferences,
} from '../types/settings'
@@ -299,9 +300,38 @@ function spawnWithTimeout(args: string[], timeoutMs: number, env?: Record<string
return { output, timedOut: false }
}
const trimGitIdentityEmail = <T extends { email: string }>(identity: T): T => ({
...identity,
email: identity.email.trim(),
})
const UpdateSettingsSchema = z.object({
preferences: UserPreferencesSchema.partial(),
})
}).superRefine(({ preferences }, ctx) => {
if (preferences.gitIdentity && !isValidGitIdentityEmail(preferences.gitIdentity.email)) {
ctx.addIssue({
code: 'custom',
path: ['preferences', 'gitIdentity', 'email'],
message: 'Invalid email address',
})
}
preferences.gitIdentities?.forEach((identity, index) => {
if (!isValidGitIdentityEmail(identity.email)) {
ctx.addIssue({
code: 'custom',
path: ['preferences', 'gitIdentities', index, 'email'],
message: 'Invalid email address',
})
}
})
}).transform(({ preferences }) => ({
preferences: {
...preferences,
...(preferences.gitIdentity ? { gitIdentity: trimGitIdentityEmail(preferences.gitIdentity) } : {}),
...(preferences.gitIdentities ? { gitIdentities: preferences.gitIdentities.map(trimGitIdentityEmail) } : {}),
},
}))
const CreateCustomCommandSchema = z.object({
name: z.string().min(1).max(255),