T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/cache_manager.py:129- Finding
Redis Namespace Restriction Bypass Allows Enumeration of Unrelated Keys
- Content
View full analysis
Vulnerability Details
File Location:
scripts/cache_manager.py:129-135andscripts/cache_manager.py:176-177
Vulnerability Type: Insufficient namespace access control
Risk Level: MediumVulnerable Code:
python def scan_keys(pattern: str, count: int = 100) -> list[str]: if not pattern.startswith(KEY_PREFIX) and "*" not in pattern: pattern = f"{KEY_PREFIX}*" if pattern == "*" else f"{KEY_PREFIX}*{pattern}*" r = _client() try: return list(r.scan_iter(match=pattern, count=count)) except redis.RedisError as e: raise CacheError(str(e))python p_scan = subparsers.add_parser("scan", help="List keys by pattern (SCAN, safe for production)") p_scan.add_argument("pattern", default="*", nargs="?", help="Glob pattern (default: mema:*)")Technical Analysis
The skill claims to enforce the
mema:Redis namespace, butscan_keys()does not validate scan patterns using the same namespace restrictions applied to individual key operations.The default pattern is
"*". Because this pattern contains an asterisk, the following condition evaluates to false:python if not pattern.startswith(KEY_PREFIX) and "*" not in pattern:Therefore, the default pattern is passed directly to Redis as
SCAN MATCH *, rather than being rewritten tomema:*. Any user able to invoke the command can also provide another wildcard pattern that does not begin withmema:and bypass the intended namespace restriction.Although this does not directly retrieve the values of non-
mema:keys through the providedgetcommand, it discloses their names. Redis key names commonly reveal application identifiers, tenant IDs, session structures, queue names, account references, and internal architecture.Attack Path
- An attacker or untrusted agent obtains permission to invoke the cache skill against a Redis database shared with other applications.
- The a ...[truncated 1205 chars]
- Remediation
View remediation
Remediation Suggestions
-
Change the CLI default pattern from
"*"to"mema:*":python p_scan.add_argument( "pattern", default="mema:*", nargs="?", help="Glob pattern restricted to mema:*", ) -
Reject every pattern that does not begin with the required namespace:
python def scan_keys(pattern: str, count: int = 100) -> list[str]: if not isinstance(pattern, str) or not pattern.startswith(KEY_PREFIX): raise KeyValidationError("Scan pattern must start with mema:") if count <= 0 or count > 1000: raise KeyValidationError("SCAN count must be between 1 and 1000") r = _client() try: return list(r.scan_iter(match=pattern, count=count)) except redis.RedisError as e: raise CacheError(str(e)) -
If users need shorthand search terms, construct the complete namespaced pattern internally rather than accepting an unrestricted Redis glob.
-
Configure a dedicated Redis account with ACL rules limited to
~mema:*, so server-side authorization still prevents cross-namespace access if application validation fails. -
Prefer a dedicated Redis database or instance when the cache may contain data from mutually untrusted applications.
-
Add regression tests covering
"*","other:*","?:*", and other wildcard patterns to verify that none can escape themema:namespace.
-
