T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:71- Finding
Unescaped Labels Enable Terminal Control-Sequence and Markdown Fence Injection
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script.sh:71, 106-130
Vulnerability Type: Untrusted output injection
Risk Level: MediumVulnerable Code
python # scripts/script.sh:71 label = re.sub(r'^[-*•]\s*', '', stripped)python # scripts/script.sh:106-130 def render_tree(node, prefix="", is_last=True, is_root=True): lines = [] if is_root: lines.append(node["label"]) else: connector = LAST if is_last else TEE lines.append(prefix + connector + node["label"]) children = node.get("children", []) for i, child in enumerate(children): last = (i == len(children) - 1) if is_root: child_prefix = "" else: child_prefix = prefix + (BLANK if is_last else CONT) lines.extend(render_tree(child, child_prefix, last, is_root=False)) return lines nodes = parse_outline(raw) if not nodes: print("Error: empty input. Provide an indented outline.") sys.exit(1) tree = build_tree(nodes) rendered = render_tree(tree) if mode == "markdown": print("```mindmap") for line in rendered: print(line) print("```") else: for line in rendered: print(line)Technical Analysis
Outline labels are accepted from inline arguments, stdin, or files and are copied into rendered output without contextual encoding. The parser only removes an optional list marker; it does not remove terminal control characters or protect Markdown delimiters.
In
viewandcreatemodes, labels containing ANSI escape sequences are written directly to the terminal. Such sequences can clear or rewrite displayed content, alter colors, create misleading terminal output, or trigger terminal-specific behaviors.In
exportmode, the program surrounds output with a fixed three-backtick fence. A label containing three backticks can close that fence early. Subs ...[truncated 1489 chars]- Remediation
View remediation
Remediation Suggestions
- Sanitize terminal-bound labels by removing or visibly encoding C0/C1 control characters, particularly ESC, while preserving necessary newline handling before parsing.
- Consider rejecting labels containing unexpected control characters and return a clear validation error.
- For Markdown export, calculate the longest consecutive backtick run in the rendered content and use a fence longer than that run.
- Alternatively, escape or replace backtick fence sequences before inserting labels into the fenced block.
- If exported files may be rendered by systems that permit raw HTML, disable or encode raw HTML where practical.
- Add regression tests containing ANSI escape bytes, carriage returns, embedded triple backticks, longer backtick runs, and raw HTML.
