T09 · Insecure Skill Coding Practices
Warning
- Location
- references/memory-management.md:31
- Finding
- Predictable Repeating-Key XOR Used for Persistent Internal Memory## Vulnerability Details **File Location**: `references/memory-management.md`, lines 31–63 **Vulnerability Type**: Weak encryption and recoverable key derivation **Risk Level**: Medium ### Vulnerable Code ```python def xor_encrypt(text: str, key: str) -> str: import base64 result = bytes([ord(c) ^ ord(key[i % len(key)]) for i, c in enumerate(text)]) return base64.b64encode(result).decode() def xor_decrypt(encoded: str, key: str) -> str: import base64 raw = base64.b64decode(encoded) return ''.join(chr(b ^ ord(key[i % len(key)])) for i, b in enumerate(raw)) # Key derivation: sha256(skill_name + date[:7])[:8] # Example: key for "req-comprehend" on 2026-05 = "a3f1b2c4" ``` ```markdown --- tier: internal key_hint: req-comprehend-2026-05 created: 2026-05-19 expires: 2026-06-19 --- ## Encrypted Preference > a0VmcEdWYQpnUgpmUQp... (base64 encoded, XOR encrypted) ## Decryption Note XOR with key derived from sha256("req-comprehend-2026-05")[:8] Purpose: Stores user's preference for one specific output format choice ``` ### Technical Analysis The documented Tier 2 memory mechanism uses repeating-key XOR followed by Base64 encoding. Repeating-key XOR does not provide modern cryptographic confidentiality or integrity. Base64 is an encoding scheme and adds no security. The key is derived entirely from predictable values—the skill name and calendar month—and is truncated to eight characters. The memory entry stores a `key_hint`, while the same document discloses the complete derivation algorithm. Consequently, any party able to read a Tier 2 memory file can reproduce the key without obtaining an independent secret. The construction also lacks authentication. An attacker with write access could modify ciphertext without reliable detection, potentially corrupting stored preferences. The reviewed Skill does not state that decrypted memory is executed as code, so the pre-scan's ...[truncated 1646 chars]
- Remediation
- ## Remediation Suggestions 1. Replace repeating-key XOR with authenticated encryption, such as AES-256-GCM or ChaCha20-Poly1305. 2. Generate a random encryption key using a cryptographically secure random-number generator. 3. Keep the key in an OS keychain, dedicated secret manager, or similarly protected credential store. Do not derive it solely from public or predictable metadata. 4. Use a unique random nonce for each encrypted entry and store only the nonce, ciphertext, and authentication tag with the memory record. 5. Bind relevant metadata, including the memory tier, creation date, expiry date, and record identifier, as authenticated associated data. 6. Fail closed when authentication fails; do not return partially decrypted or unauthenticated content. 7. Minimize Tier 2 collection and retain only information demonstrably required for the Skill's functionality. 8. Enforce expiry through deletion rather than moving expired confidential entries into an archive. 9. Add automated checks that reject credentials, secrets, and personally identifiable information before persistence. 10. Restrict Tier 2 directory and backup permissions to the minimum required process identity. 11. Clearly distinguish Base64 encoding from encryption in documentation and tests.
