T09 · Insecure Skill Coding Practices
- Location
protocol.py:19- Finding
AICP Wire-Format Injection Through Unescaped Input
- Content
View full analysis
Vulnerability Details
File Location:
protocol.py, lines 19–28 and 41–49; exposed to CLI-controlled input throughopenclaw_aicp.py, lines 127–148
Vulnerability Type: AICP protocol structural injection
Risk Level: MediumVulnerable Code
python def to_wire(self, glossary: Dict[str, str]) -> str: """Convert to compact wire format.""" parts = [f"op:{self.op}", f"ref:{self.ref}"] for key, val in self.fields.items(): # Use glossary abbreviation if exists for abbr, full in glossary.items(): if val == full: val = abbr break parts.append(f"{key}={val}") return " ".join(parts)python def to_wire(self) -> str: """Serialize to wire format.""" lines = [f"VER:{self.version}", f"SID:{self.session_id}"] if self.glossary: gloss_str = " ".join(f"{k}={v}" for k, v in self.glossary.items()) lines.append(f"GLOSS: {gloss_str}") for msg in self.messages: lines.append("MSG:") lines.append(f"{msg.to_wire(self.glossary)}") return "\n".join(lines)The CLI passes user-controlled values into this serializer:
python p_spawn.add_argument("--task", required=True, help="Task description") p_spawn.add_argument("--type", default="general", help="Task type (image/code/data/llm/aicp)") p_spawn.add_argument("--priority", default="normal", help="Priority (CRIT/WARN/INFO)") # ... result = aicp.spawn_subagent( task_type=args.type, params={"task": args.task, "pri": args.priority.upper()[:4]} )Technical Analysis
The serializer directly interpolates operation names, references, field keys and values, glossary entries, versions, and session identifiers into a whitespace- and newline-delimited protocol. It performs no escaping, encoding, or grammar validation.
An attacker-controlled value can consequently include delimiters such as line breaks, spaces,
:, and=. In particular, a newline followed by struc ...[truncated 2043 chars]- Remediation
View remediation
Remediation Suggestions
- Define a strict, documented grammar for every protocol component, including operation names, references, field names, field values, session identifiers, versions, and glossary aliases.
- Validate operation names against an explicit allowlist such as
upd,create,del,qry,ack, andnotify. - Reject carriage returns and line feeds in all scalar values unless the protocol introduces an unambiguous encoding for them.
- Restrict identifiers and field names to a conservative character set and maximum length, for example an anchored ASCII alphanumeric pattern with explicitly permitted punctuation.
- Encode arbitrary field values using a robust representation such as JSON string escaping, percent encoding, Base64 with explicit markers, or length-prefixed fields. Apply matching decoding in
parse_wire(). - Do not rely on whitespace splitting for arbitrary values. Use a real tokenizer or a serialization format capable of preserving spaces and delimiters.
- Make parsing fail closed: reject malformed records, unknown operations, invalid keys, unexpected structural lines, duplicate headers, and incomplete messages rather than accepting partial data.
- Apply resource limits to input size, number of lines, glossary entries, messages, and field lengths.
- Add adversarial round-trip tests covering spaces, tabs, carriage returns, newlines, colons, equals signs, duplicate headers, forged
MSG:blocks, and malformed message bodies. - Validate input both at CLI boundaries and inside the serializer so direct library callers receive the same protection.
