Repository navigation
fix(security): reject encrypted-envelope credentials at provider create/update validation - #15932
Merged
diegosouzapw merged 1 commit intoOct 9, 2026
Conversation
…te/update validation A credential arriving with the enc:v1: prefix is an encrypted envelope from a credential store, not a plaintext key. encrypt() deliberately skips re-encrypting prefixed values, so such a payload was stored verbatim, failed to decrypt at runtime, and surfaced only as a misleading 5ms "Missing API key" on the connection test (auth_missing) despite the row showing api_key SET. Plaintext keys from every provider (sk-…, tvly-…, JWTs, cookie headers, JSON storage state) start with something else, so the schema-level rejection is near-zero-false-positive. Checked inline rather than via looksEncrypted() because these schemas are imported by client-side dashboard code (node:crypto-free). Also drops 10 unused imports in schemas/provider.ts (with their now-stale eslint suppression entries) that trip the pre-commit hook for any change to this file. Closes diegosouzapw#15930
Owner
|
Thanks @hongkongkiwi — creating or updating a provider now rejects an apiKey that is still an |
6 tasks done
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.
Closes #15930
What
Rejects provider credentials that arrive already carrying the
enc:v1:envelope prefix at both validation seams:createProviderSchema(POST/api/providers)updateProviderConnectionSchema(PATCH/api/providers/{id})with a clear message: "apiKey looks like an encrypted envelope from a credential store, not a plaintext key — store the plaintext API key" — instead of today's flow, where the envelope is stored verbatim and surfaces only as a misleading 5ms
Missing API key/auth_missingon the connection test.Why schema-level
encrypt()deliberately skips re-encrypting values that already carry the prefix (src/lib/db/encryption.ts), so the envelope gets stored as-is, thendecryptConnectionFieldsreturns null at runtime. Plaintext keys from every provider (sk-…, tvly-…, JWTs, cookie headers, JSON storage state) start with something else, so the rejection is near-zero-false-positive — per the analysis in #15930.The check is inline in the schemas rather than reusing
looksEncrypted(): both schemas are imported by client-side dashboard code (providerOnboardingApi.ts), and the crypto-backed module must not enter that bundle.Also in this diff
schemas/provider.ts(pre-existing onrelease/v3.8.52) that trip the pre-commitno-unused-varsgate for any change to this file, plus their now-stale entries inconfig/quality/eslint-suppressions.json.Tests
New
tests/unit/15930-encrypted-envelope-credential-rejected.test.ts(follows the issue-number naming convention):enc:v1:-prefixed credential with anapiKey-path issueenc:v1:mid-string (startsWith semantics)Verified locally: 4/4 new + 74/74 existing provider-schema tests pass;
eslint-suppressions-prunedconsistency test 5/5.