fix: validate API key prefixes before creation#64
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports Dokploy#4629 by @KirillYarkov (2 commits, cherry-picked with
-x, original authorship preserved).What / why
Hardening of the API-key creation path. The user-supplied key
prefixpreviously flowed unvalidated intoauth.createApiKey; malformed prefixes could produce broken/confusing API keys and opaque creation failures.apps/dokploy/server/api/routers/user.ts): zod schema trims the prefix, converts empty string toundefined, and enforces^[A-Za-z0-9_-]+$(ASCII letters, numbers, underscore, hyphen).packages/server/src/services/user.ts):normalizeApiKeyPrefix()re-validates defensively and throwsTRPCError(BAD_REQUEST)— protection holds even for callers that bypass the router schema.add-api-key.tsx+ newapi-key-errors.ts): API-key creation errors (including the prefix validation message) are now surfaced to the user instead of a generic failure.Adaptations
None — both commits applied cleanly onto fork canary.
Test evidence
vitest run __test__/user/create-api-key.test.ts __test__/user/create-api-key-errors.test.ts: 14/14 passed (Windows local).pnpm --filter=dokploy run typecheck: clean.Overlap notes
No file overlap with open fork PRs #36/#58 or with the other salvo-2 M2 ports.