T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/mema.py:69
- Finding
- Redis mental-state data lacks authentication and transport security<![CDATA[ ## Vulnerability Details **File Location**: `scripts/mema.py:13-15, 69-100` **Vulnerability Type**: Unauthenticated and unencrypted remote state storage **Risk Level**: High ### Vulnerable Code ```python REDIS_HOST = os.getenv("REDIS_HOST", "localhost") REDIS_PORT = int(os.getenv("REDIS_PORT", 6379)) REDIS_PREFIX = "mema:mental" ``` ```python def mental_op(action, key=None, value=None, ttl=21600): r = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, decode_responses=True) if action == "set": if not key: print("Error: key is required for 'set' action", file=sys.stderr) return False if value is None: print("Error: value is required for 'set' action", file=sys.stderr) return False full_key = f"{REDIS_PREFIX}:{key}" r.set(full_key, value, ex=ttl) print(f"✓ Set {key} (TTL: {ttl}s)") return True elif action == "get": if not key: print("Error: key is required for 'get' action", file=sys.stderr) return False full_key = f"{REDIS_PREFIX}:{key}" val = r.get(full_key) print(val if val else "(nil)") return True elif action == "list": for k in r.scan_iter(match=f"{REDIS_PREFIX}:*"): print(k.replace(f"{REDIS_PREFIX}:", "")) return True elif action == "clear": if key: full_key = f"{REDIS_PREFIX}:{key}" r.delete(full_key) print(f"✓ Cleared {key}") else: keys_to_delete = list(r.scan_iter(match=f"{REDIS_PREFIX}:*")) if keys_to_delete: r.delete(*keys_to_delete) print("✓ Cleared all mental state") return True return False ``` ### Technical Analysis The Redis endpoint is configurable through `REDIS_HOST`, but the client is instantiated without a username, password, TLS, or server-certificate verification. The default loopback configuration limits ...[truncated 1987 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Keep Redis bound to loopback by default and reject non-loopback hosts unless remote operation is explicitly enabled. 2. Add support for Redis ACL credentials through protected environment variables or a secret manager: - `REDIS_USERNAME` - `REDIS_PASSWORD` 3. Require TLS for remote endpoints by using `rediss://` or `redis.Redis(..., ssl=True)`. 4. Enable server-certificate validation and provide a trusted CA bundle; do not disable hostname verification. 5. Configure Redis network controls so that only authorized clients can reach the service. 6. Use a dedicated Redis account restricted to the required key prefix and commands. 7. Treat all retrieved state as untrusted data. Do not insert it into system or developer instruction contexts without validation and clear data boundaries. 8. Consider authenticating stored values, such as with an application-level MAC, when integrity against Redis-side modification is required. 9. Update `SKILL.md` to disclose that configuring a remote Redis host transmits and stores data outside the local machine. ]]>
