Skip to content

fix: prevent false positive in Secret.get_plaintext() for plaintext values (reopening #3070) - #3078

Open
actuallyrizzn wants to merge 1 commit into
letta-ai:mainfrom
actuallyrizzn:fix/secret-plaintext-false-positive
Open

fix: prevent false positive in Secret.get_plaintext() for plaintext values (reopening #3070)#3078
actuallyrizzn wants to merge 1 commit into
letta-ai:mainfrom
actuallyrizzn:fix/secret-plaintext-false-positive

Conversation

@actuallyrizzn

Copy link
Copy Markdown

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() with was_encrypted=False), the is_encrypted() heuristic can incorrectly identify long API keys (e.g., OpenAI 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.

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_encrypted flag before trusting the is_encrypted() heuristic. If was_encrypted=False, we know the value was explicitly created as plaintext, so we should trust the cached value.

Changes

  • Added early return in get_plaintext() when was_encrypted=False and cache exists
  • This prevents false positives from clearing the cache unnecessarily
  • Preserves existing behavior for actually encrypted values

Testing

This fix resolves the issue where OpenAI API keys stored as plaintext would return None from get_plaintext() when LETTA_ENCRYPTION_KEY was not set.

Fixes #3069
Reopens #3070

…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
@kianjones9

Copy link
Copy Markdown
Member

@jnjpng maybe you can take a look?

@jnjpng

jnjpng commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

this looks good to me!

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix OpenAI API Key Configuration in .env File

3 participants