fix: prevent false positive in Secret.get_plaintext() for plaintext values (reopening #3070) - #3078
Open
actuallyrizzn wants to merge 1 commit into
Open
Conversation
…alues When a Secret is created from plaintext (was_encrypted=False), the is_encrypted() heuristic can incorrectly identify long API keys as encrypted. This causes get_plaintext() to return None when no encryption key is available, even though the value was explicitly stored as plaintext. Fix: Check was_encrypted flag before trusting is_encrypted() heuristic. If was_encrypted=False, trust the cached plaintext value. Fixes: letta-ai#3069
Member
|
@jnjpng maybe you can take a look? |
Contributor
|
this looks good to me! |
jnjpng
approved these changes
Dec 8, 2025
carenthomas
pushed a commit
that referenced
this pull request
Dec 15, 2025
…alues (#6566) When a Secret is created from plaintext (was_encrypted=False), the is_encrypted() heuristic can incorrectly identify long API keys as encrypted. This causes get_plaintext() to return None when no encryption key is available, even though the value was explicitly stored as plaintext. Fix: Check was_encrypted flag before trusting is_encrypted() heuristic. If was_encrypted=False, trust the cached plaintext value. This is a port of #3078 to letta-cloud. 👾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta Bot <noreply@letta.com>
carenthomas
pushed a commit
that referenced
this pull request
Dec 15, 2025
…alues (#6566) When a Secret is created from plaintext (was_encrypted=False), the is_encrypted() heuristic can incorrectly identify long API keys as encrypted. This causes get_plaintext() to return None when no encryption key is available, even though the value was explicitly stored as plaintext. Fix: Check was_encrypted flag before trusting is_encrypted() heuristic. If was_encrypted=False, trust the cached plaintext value. This is a port of #3078 to letta-cloud. 👾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta Bot <noreply@letta.com>
carenthomas
pushed a commit
that referenced
this pull request
Dec 15, 2025
…alues (#6566) When a Secret is created from plaintext (was_encrypted=False), the is_encrypted() heuristic can incorrectly identify long API keys as encrypted. This causes get_plaintext() to return None when no encryption key is available, even though the value was explicitly stored as plaintext. Fix: Check was_encrypted flag before trusting is_encrypted() heuristic. If was_encrypted=False, trust the cached plaintext value. This is a port of #3078 to letta-cloud. 👾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta Bot <noreply@letta.com>
huangyingting
pushed a commit
to repomesh/letta
that referenced
this pull request
May 17, 2026
huangyingting
pushed a commit
to repomesh/letta
that referenced
this pull request
May 17, 2026
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.
Update: Repository Recovery
Note: A rogue agent erroneously deleted the previous repository, which caused PR #3070 to be closed. This PR restores the fix and addresses the original issue (#3069).
Problem
When a Secret is created from plaintext (via
from_plaintext()withwas_encrypted=False), theis_encrypted()heuristic can incorrectly identify long API keys (e.g., OpenAI API keys) as encrypted. This causesget_plaintext()to returnNonewhen no encryption key is available, even though the value was explicitly stored as plaintext.Root Cause
The
CryptoUtils.is_encrypted()method uses a heuristic that checks if a value is base64-decodable and meets minimum encrypted size requirements. Long API keys (164+ characters) can trigger false positives, causing the code to attempt decryption and fail.Solution
Check the
was_encryptedflag before trusting theis_encrypted()heuristic. Ifwas_encrypted=False, we know the value was explicitly created as plaintext, so we should trust the cached value.Changes
get_plaintext()whenwas_encrypted=Falseand cache existsTesting
This fix resolves the issue where OpenAI API keys stored as plaintext would return
Nonefromget_plaintext()whenLETTA_ENCRYPTION_KEYwas not set.Fixes #3069
Reopens #3070