T09 · Insecure Skill Coding Practices
- Location
- session_sync.py:73
- Finding
- Incomplete redaction exposes sensitive cross-session chat content in persistent shared storage<![CDATA[ ## Vulnerability Details **File Location**: `session_sync.py:73-78`, `session_sync.py:269-302` **Vulnerability Type**: Incomplete sensitive-data sanitization and plaintext data persistence **Risk Level**: Medium ### Vulnerable Code ```python # Sensitive information sanitization patterns SENSITIVE_PATTERNS = [ (r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', '[EMAIL]'), (r'\b\d{11}\b', '[PHONE]'), (r'\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b', '[CARD]'), (r'\b[A-Za-z0-9]{32,}\b', '[TOKEN]'), ] ``` ```python def parse_messages(self, content: str) -> List[Dict]: """Parse message content""" messages = [] for line in content.strip().split('\n'): line = line.strip() if not line: continue try: msg = json.loads(line) # Sanitize content msg_content = msg.get("content", "") msg_content = sanitize_content(msg_content) messages.append({ "role": msg.get("role", "unknown"), "content": msg_content, "timestamp": msg.get("timestamp", "") }) except json.JSONDecodeError: continue return messages def sync_session(self, session_id: str) -> bool: """Synchronize one session""" content = self.get_session_content(session_id) if not content: return False # Check for changes if not self.detector.has_changed(session_id, content): return False # Parse messages messages = self.parse_messages(content) if not messages: return False # Build session data session_data = { "id": session_id, "timestamp": datetime.now().isoformat(), "hash": self.detector.calculate_hash(content), "message_count": len(messages), "messages": messages[-50:] } # Write files self.file_manager.append_json(session_data) self.file_manager.append_markdown(session_data) ``` ## ...[truncated 2455 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Expand secret detection to cover well-known API-token prefixes, bearer credentials, authorization headers, password assignments, JWTs, private keys, and tokens containing punctuation. 2. Allow administrators to define application-specific deny patterns. 3. Prefer allowlisted message fields and structured secret metadata over relying exclusively on regular expressions. 4. Provide per-session opt-in or exclusion controls before copying data into cross-session storage. 5. Minimize retained content and consider storing summaries rather than complete message bodies. 6. Encrypt sensitive output at rest where cross-session plaintext access is unnecessary. 7. Clearly document that redaction is best-effort and cannot guarantee removal of every secret. 8. Add tests for private keys, JWTs, bearer tokens, prefixed API keys, hyphenated tokens, passwords, and confidential non-credential data. 9. Ensure plugins receive only the minimum sanitized data required for their operation. ]]>
