fix: mask API keys in debug output and clear from memory in destructor (closes #76)#159
Merged
Merged
Conversation
closes #76) SEC-008: API keys stored in plaintext memory Changes: - Add __debugInfo() to ApiEmbeddingFunction — masks API key in var_dump - Add __destruct() with sodium_memzero() — clears key from memory - Constructor apiKey param now nullable with env var fallback - Add private __clone() to prevent shared buffer corruption - Update SECURITY.md to mark as fixed - Add 4 test files (source analysis + runtime validation)
4 tasks
…n (refs #76) - Add default value '' to property to prevent fatal error when subclass does not call parent constructor (MockDenseEmbedding case) - Fix getenv() false return: getenv() returns false for unset vars, not null — use (getenv(...) ?: null) to make null coalescing work - Fix runtime test: clone error msg differs per PHP version, and substr('', -4) returns '' not '****'
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.
Description
Closes #76
SEC-008: API Keys Stored in Plaintext Memory
Changes
__debugInfo()— Added toApiEmbeddingFunction. Masks API key as***xxxxin var_dump() output, preventing accidental exposure in logs, crash dumps, and debug output__destruct()— Callssodium_memzero($this->apiKey)when ext-sodium is available, clearing the key from process memory$apiKeychanged fromstringto?string = null. Falls back toOPENAI_API_KEYorDASHSCOPE_API_KEYenvironment variables__clone()— Private to prevent cloned-instance string buffer corruption (sodium_memzero on shared buffer during destruct)Testing
Code Review