Back to skill

Security audit

LLM Result Cache

Security checks for vulnerabilities and agentic risk

Overview

This is a small disclosed Python disk-cache helper with ordinary local file persistence and no hidden network, credential, or execution behavior.

Install only if you are comfortable with results being written to a local JSON cache file you choose. Avoid caching secrets or regulated data unless you protect the file appropriately, and use a custom key_fn whenever the result depends on more than the first argument, user identity, tenant, model, prompt, or options.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Warning
Location
llm_result_cache.py:91
Finding

Incomplete Default Cache Key Causes Cross-Context Result Confusion

Content
View full analysis
Callable: @wraps(fn) def wrapper(*args, **kwargs): key = key_fn(*args, **kwargs) if key_fn else str(args[0]) if args else "" hit = cache.get(key) if hit is not None: return hit result = fn(*args, **kwargs) if isinstance(result, dict): cache.set(key, result) return result ``` ### Technical Analysis When no custom `key_fn` is supplied, the decorator derives the cache key exclusively from the first positional argument. It ignores: - Additional positional arguments - All keyword arguments - Tenant or user identity - Authorization context - Model and prompt versions - Configuration options that can affect the result Consequently, semantically different function calls can resolve to the same cache entry. For example, calls such as `analyze(document, tenant="A")` and `analyze(document, tenant="B")` use an identical default key if `document` is the same. The cached value is returned immediately, so the wrapped function and any authorization-sensitive or context-sensitive processing it performs are skipped. ### Attack Path 1. An application decorates a multi-argument or keyword-sensitive function with `@cached(cache)` without providing `key_fn`. 2. An attacker or ordinary user invokes the function with a chosen first argument and attacker-controlled secondary arguments. 3. The resulting dictionary is stored under a key derived only from the first argument. 4. Another caller invokes the function with the same first argument but different tenant, permission, model, prompt, or processing options. 5. The decorator finds the previously stored value and returns it without executing the wrapped function. 6. The second caller receives a result generated for a differe ...[truncated 667 chars]
Remediation
View remediation

T09 · Insecure Skill Coding Practices

Note
Location
llm_result_cache.py:43
Finding

Structurally Invalid Cache Data Can Cause Persistent Denial of Service

Content
View full analysis
dict[str, Any]: if self.cache_file.exists(): try: return json.loads(self.cache_file.read_text()) except Exception: # Corrupted cache file — treat as empty rather than crashing. # (This is a CACHE, not a source of truth, so losing it is # safe; a spend/audit ledger would need fail-closed handling # instead — see the ad-budget-governor skill for that case.) return {} return {} def _save(self, cache: dict[str, Any]) -> None: try: self.cache_file.write_text(json.dumps(cache, indent=2)) except Exception: pass # best-effort — a failed cache write should never break the caller def get(self, key: str) -> Optional[dict]: cache = self._load() entry = cache.get(key) if not entry: return None if time.time() - entry.get("cached_at", 0) > self.ttl_seconds: return None return entry.get("value") def set(self, key: str, value: dict) -> None: cache = self._load() cache[key] = {"cached_at": time.time(), "value": value} if len(cache) > self.max_entries: oldest_first = sorted(cache.items(), key=lambda kv: kv[1].get("cached_at", 0)) cache = dict(oldest_first[-self.max_entries:]) self._save(cache) ``` ### Technical Analysis The `_load()` method catches decoding and file-reading exceptions, but it does not validate the type or schema of successfully decoded JSON. Valid JSON is not necessarily a valid cache structure. For example: - A root value of `[]`, `null`, a string, or a number does not support `cache.get()` or item assignment. - An entry value that is a string, list, or number does not support `entry.get()`. - During eviction, any non-dictionary entry causes `k ...[truncated 1839 chars]
Remediation
View remediation
dict[str, Any]: try: decoded = json.loads(self.cache_file.read_text()) except (OSError, UnicodeError, json.JSONDecodeError): return {} if not isinstance(decoded, dict): return {} valid = {} for key, entry in decoded.items(): if not isinstance(key, str) or not isinstance(entry, dict): continue cached_at = entry.get("cached_at") value = entry.get("value") if not isinstance(cached_at, (int, float)): continue if not isinstance(value, dict): continue valid[key] = entry return valid ``` Atomic replacement should be used to prevent readers from observing partially written files. ]]>
Vulnerability Patterns
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (1)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
70% confidence
Finding

Without declared permissions the skill's intent is opaque and cannot be validated.

Content

No source excerpt is available for this finding.