T09 · Insecure Skill Coding Practices
Error
- Location
- poetry_hub_entrypoint.py:8
- Finding
- All CLI Commands Unexpectedly Launch an Infinite Mutating Agent<![CDATA[ ## Vulnerability Details **File Location**: `poetry_hub_entrypoint.py:8-20`; `poetry_hub_agent.py:58-87` **Vulnerability Type**: Command dispatch failure and unintended remote state mutation **Risk Level**: High ### Vulnerable Code `poetry_hub_entrypoint.py:8-20`: ```python def main(): if len(sys.argv) < 2: print("Usage: poetry_hub_entrypoint.py [register|run|state|feed|reset]") sys.exit(2) cmd = sys.argv[1] if cmd == "register": # Run the existing agent's register path subprocess.run([sys.executable, "poetry_hub_agent.py", "register"], check=True) elif cmd == "run": subprocess.run([sys.executable, "poetry_hub_agent.py"], check=True) else: # Fallback to delegating to the Python script for other commands if implemented subprocess.run([sys.executable, "poetry_hub_agent.py", cmd], check=True) if __name__ == "__main__": main() ``` `poetry_hub_agent.py:58-87`: ```python def main(): print(f"Initializing poetry-hub agent as {NAME} — {PROFILE}") register_agent() while True: state = get_state() if not state.get("is_running", True): print("Hub not running yet, waiting...") time.sleep(5) continue feed = get_feed() # Simple loop: if fewer than 4 lines, post a line; otherwise post feedback or reset via hub if first line poem_lines = [p for p in feed.get("posts", []) if p.get("agent_name")==NAME] # simplistic if len(poem_lines) < 4: line = f"A line from {NAME} in the voice of {NAME.split('-')[0]}" # placeholder, replace with real generation post_line(line) time.sleep(2) else: # Post a generic FEEDBACK line (start with FEEDBACK:) post_line("FEEDBACK: continue exploring imagery and rhythm.") time.sleep(5) # After some feedback, post FINAL before reset (simplified) post_line("FINAL:\nL ...[truncated 2311 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Implement explicit command dispatch and reject unsupported commands: ```python if cmd not in {"register", "run", "state", "feed", "reset"}: print(f"Unknown command: {cmd}", file=sys.stderr) sys.exit(2) ``` 2. Import and invoke single-purpose functions instead of spawning the same script for every operation: ```python from poetry_hub_agent import register_agent, get_state, get_feed, reset_hub, main if cmd == "register": print(json.dumps(register_agent())) elif cmd == "state": print(json.dumps(get_state())) elif cmd == "feed": print(json.dumps(get_feed())) elif cmd == "reset": print(json.dumps(reset_hub())) elif cmd == "run": main() ``` 3. Make `state` and `feed` strictly read-only and ensure they terminate after one request. 4. Make `register` perform exactly one registration and then exit. 5. Reserve the infinite loop exclusively for an explicit `run` command. 6. Add tests that assert each command's network methods and endpoints. In particular, verify that `state` and `feed` never issue POST requests. 7. Add bounded execution, graceful shutdown handling, retry limits, and backoff to the autonomous run mode. ]]>
