fix(ai-providers): cap AI_PROVIDER_KEY_CREATE/UPDATE apiKey length - #7129
Closed
pedrofrxncx wants to merge 1 commit into
Closed
pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
Collaborator
Author
|
Closing as stale: this PR sat past the bot's 48h merge window, main has moved on, and its CI results no longer reflect the current base. This is a housekeeping close, not a rejection of the change — if the underlying problem still exists, the bot will find it again and open a fresh, rebased PR. [studio-bot:stale-close] |
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.
Reduction/hardening: none of AI_PROVIDER_KEY_CREATE or AI_PROVIDER_KEY_UPDATE bounded the length of the
apiKeyfield before it's hashed (SHA-256) and encrypted (AES-256-GCM) into the vault and stored in Postgres — every other string field on these tools (label,presetId) has a.max(), butapiKeyhad none.Why it matters: an authenticated org member could submit an arbitrarily large string as an "API key" (megabytes), and it would be hashed, encrypted, and persisted as a DB row with no bound — a resource/DoS gap of the same shape as the other attacker-controlled-string-length caps already fixed in this codebase (see the
apiKeys/registrytool schemas, which do cap their key/secret fields).Fix: added
.max(4096)toapiKeyin bothAI_PROVIDER_KEY_CREATEandAI_PROVIDER_KEY_UPDATEinput schemas — generous enough for any real provider API key/token (these are typically well under 200 characters) while closing the unbounded-write gap. Pure input-validation tightening; no behavior change for any legitimate caller.Regression test:
apps/api/src/tools/ai-providers/key-length-bound.test.tsasserts a 4097-char key is rejected on both tools and a 4096-char key is accepted.To verify:
bun test apps/api/src/tools/ai-providers/key-length-bound.test.ts apps/api/src/tools/ai-providers/key-create.test.tsLocally ran:
bun run fmt,cd apps/api && bunx tsc --noEmit(clean), the targeted test file above (16 pass), andbunx oxlinton the three changed files (0 warnings/errors). Full CI validates the rest.Summary by cubic
Caps the
apiKeylength on the AI provider key create and update tools to prevent unbounded string writes. Previously any length was accepted; now keys over 4096 characters are rejected.Written for commit 1cd9f5a. Summary will update on new commits.