Skip to content

fix: validate API key prefixes before creation#4629

Open
KirillYarkov wants to merge 2 commits into
Dokploy:canaryfrom
KirillYarkov:fix/api-key-prefix-validation
Open

fix: validate API key prefixes before creation#4629
KirillYarkov wants to merge 2 commits into
Dokploy:canaryfrom
KirillYarkov:fix/api-key-prefix-validation

Conversation

@KirillYarkov

@KirillYarkov KirillYarkov commented Jun 13, 2026

Copy link
Copy Markdown

Summary

  • Validate and trim API key prefixes before calling better-auth.
  • Treat empty trimmed prefixes as undefined.
  • Surface API key creation errors in the UI instead of showing only a generic failure toast.
  • Add client-side form validation with a clear prefix message.
  • Add regression coverage for missing, valid, invalid, trimmed, empty, and server-returned prefix errors.

Root Cause

user.createApiKey accepted any prefix string and passed it through to better-auth. Invalid prefixes were rejected there as a generic error, which surfaced through tRPC as INTERNAL_SERVER_ERROR / HTTP 500 instead of a client validation error. The UI also discarded server error details and always showed Failed to generate API key.

Validation

  • npx --yes pnpm@10.22.0 --dir apps/dokploy exec vitest --config __test__/vitest.config.ts __test__/user/create-api-key-errors.test.ts __test__/user/create-api-key.test.ts --run
  • npx --yes pnpm@10.22.0 exec biome check apps/dokploy/__test__/user/create-api-key-errors.test.ts apps/dokploy/__test__/user/create-api-key.test.ts apps/dokploy/components/dashboard/settings/api/api-key-errors.ts apps/dokploy/components/dashboard/settings/api/add-api-key.tsx apps/dokploy/server/api/routers/user.ts packages/server/src/services/user.ts
  • npx --yes pnpm@10.22.0 --filter=dokploy typecheck
  • npx --yes pnpm@10.22.0 --filter=@dokploy/server typecheck

Note: local checks ran under Node v18.19.1, while .nvmrc specifies Node 24.4.0, so pnpm emitted engine warnings.

@KirillYarkov KirillYarkov changed the title [codex] Fix API key prefix validation fix: validate API key prefixes before creation Jun 13, 2026
@KirillYarkov KirillYarkov marked this pull request as ready for review June 13, 2026 12:30
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant