T09 · Insecure Skill Coding Practices
- Location
scripts/mem-plus_cli.py:269- Finding
Credential Filtering Bypass in Direct Filename Retrieval
- Content
View full analysis
Vulnerability Details
File Location:
scripts/mem-plus_cli.py, lines 240–290 and 474–489
Vulnerability Type: Sensitive-data disclosure caused by inconsistent output sanitization
Risk Level: HighVulnerable Code
The direct filename retrieval path reads and inserts raw workspace content:
python def _filename_direct_inject(query: str, results: list) -> list: if not _looks_like_filename(query): return results workspace = os.path.expanduser('~/.openclaw/workspace') matched_result = None try: for fname in os.listdir(workspace): fpath = os.path.join(workspace, fname) if not os.path.isfile(fpath): continue ext = os.path.splitext(fname)[1].lower() if ext not in ('.md', '.txt', '.json', '.py', '.yaml', '.yml'): continue try: with open(fpath, encoding='utf-8', errors='ignore') as f: first_lines = ''.join(f.readlines()[:50]) heading_pattern = rf'^#\s*{re.escape(query)}\b' if re.search( heading_pattern, first_lines, re.MULTILINE | re.IGNORECASE ): with open(fpath, encoding='utf-8', errors='ignore') as f: full_content = f.read(50000) matched_result = { 'content': full_content, 'score': 999.0, 'source': fname, 'meta': {'mtime': os.path.getmtime(fpath)}, '_injected': True, '_filename_boost': 999.0, } break except Exception: continue except Exception: pass if not matched_result: return results res ...[truncated 3690 chars]- Remediation
View remediation
Remediation Suggestions
-
Move
_filename_direct_inject()before the common sanitization stage so all result sources pass through the same controls:python results = _filename_direct_inject(query, results) if strip: for result in results: result['content'] = strip_metadata(result['content']) for result in results: result['content'] = filter_credentials(result['content']) -
Alternatively, sanitize
full_contentbefore constructing the injected result:python full_content = strip_metadata(full_content) full_content = filter_credentials(full_content)Centralized post-retrieval sanitization is preferable because it reduces the likelihood that future retrieval paths will bypass the controls.
-
Apply residual credential detection after redaction. If sensitive content is still detected, reject the result rather than returning it.
-
Use an allowlist of workspace files intended for memory retrieval instead of scanning every supported top-level file. Consider limiting retrieval to documented identity and memory files.
-
Return only the relevant matched section rather than as many as 50,000 raw characters from the file. This reduces unnecessary exposure and follows data-minimization principles.
-
Avoid using an unconditional
999.0boost for directly read files. Rank them using the same relevance and policy checks as other results. -
Add regression tests covering:
- A directly injected file containing a GitHub token.
- Generic password and API-key assignments.
- Sensitive metadata prefixes.
- A secret occurring outside the first 50 lines but inside the returned content.
- Verification that every returned result has passed the final sanitization stage.
-
