T09 · Insecure Skill Coding Practices
Warning
- Location
- generators/hook_generator.py:111
- Finding
- Generated hooks expose complete pipeline contexts through logging<![CDATA[ ## Vulnerability Details **File Location**: `generators/hook_generator.py`, lines 111-118; generated instances appear at line 8 of every file under `generated_hooks/` **Vulnerability Type**: Sensitive information exposure through logging **Risk Level**: Medium ### Vulnerable Code ```python for stage_name, stage_info in self.architecture['pipeline'].items(): # Generate one sample pre-hook for each stage hook = self.generate_hook_package( hook_name=f"pre_{stage_name}_custom", hook_type='pre', stage=stage_name, logic='// Custom pre-processing logic\nconsole.log("Pre-processing:", context);' ) hooks.append(hook) ``` This produces hooks containing: ```javascript async function pre_llm_submit_custom(context, next) { // Your pre-processing logic here // Custom pre-processing logic console.log("Pre-processing:", context); // Call next stage await next(context); } ``` The same logging behavior is present in these generated files: - `generated_hooks/pre_input_receive_custom.js:8` - `generated_hooks/pre_context_gather_custom.js:8` - `generated_hooks/pre_memory_retrieve_custom.js:8` - `generated_hooks/pre_prompt_assemble_custom.js:8` - `generated_hooks/pre_token_check_custom.js:8` - `generated_hooks/pre_context_compress_custom.js:8` - `generated_hooks/pre_llm_submit_custom.js:8` - `generated_hooks/pre_response_process_custom.js:8` - `generated_hooks/pre_memory_store_custom.js:8` ### Technical Analysis The generator creates pre-hooks for security-sensitive stages and configures each hook to log the complete `context` object. Depending on the OpenClaw runtime's context structure, this object may contain user input, conversation history, retrieved memory, assembled prompts, model requests, model responses, tool arguments, or authentication-related metadata. Logging the entire object violates data-minimization principles. Console output may be captured by process supervisors, containers, ...[truncated 1710 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove full-context logging from the default generated hook: ```python logic='// Add custom pre-processing logic here.' ``` 2. If diagnostic logging is necessary, log only fixed event names and explicitly allowlisted metadata: ```javascript console.log("Pre-processing stage entered", { stage: "llm_submit", requestId: context.requestId }); ``` 3. Never log message content, prompts, memory records, tool arguments, authorization headers, API keys, cookies, or tokens. 4. Add a centralized redaction function that recursively removes sensitive fields before structured objects reach any logger. 5. Make debugging logs opt-in and disabled by default in production. 6. Document log sensitivity, access controls, and retention requirements. 7. Remove or regenerate the existing files under `generated_hooks/` so already generated unsafe hooks are not accidentally deployed. ]]>
