T09 · Insecure Skill Coding Practices
- Location
main.py:77- Finding
Stored Markdown Injection Through Unescaped Revenue Fields
- Content
View full analysis
Vulnerability Details
File Location:
main.py:77-80andmain.sh:45-47
Vulnerability Type: Stored Markdown injection
Risk Level: MediumVulnerable Code
python for entry in entries: f.write(f"• {entry['timestamp']} | {entry['amount']} | {entry['source']} | {entry['description']}\n")bash if [ $count -gt 0 ]; then grep "$date" "$LOG_FILE" 2>/dev/null | sed 's/^/• /' >> "$REPORT_FILE" else echo "暂无交易" >> "$REPORT_FILE" fiTechnical Analysis
The revenue source and description are supplied through command-line arguments and persisted without validation or output encoding. Both report implementations subsequently write these values directly into
reports/daily_summary.md.An attacker able to invoke the local logging command can supply Markdown, HTML, embedded links, remote image references, headings, or newline characters. When a report is generated, that content becomes part of the trusted report. The shell implementation is also vulnerable to field corruption because user input can contain pipe delimiters and newlines.
This is a stored content-injection vulnerability: the payload persists in the revenue log and is reproduced whenever the affected daily report is generated.
Attack Path
- The attacker obtains the ability to invoke the revenue logging command or influence its arguments.
- The attacker supplies a malicious source or description containing Markdown, HTML, links, or newline-delimited report content.
- The application stores the payload in
logs/revenue.logwithout validation. - A user invokes the
reportcommand. main.pyormain.shcopies the attacker-controlled content directly intoreports/daily_summary.md.- When the report is viewed in a Markdown renderer, the injected content can display deceptive financial entries, phishing links, or remote resources.
Impact Assessment
Exploitation does not directly grant ope ...[truncated 527 chars]
- Remediation
View remediation
Remediation Suggestions
- Validate source and description fields before persistence.
- Reject newline characters, carriage returns, null bytes, and other control characters.
- Apply reasonable length limits to every user-controlled field.
- Escape Markdown and embedded HTML metacharacters before rendering report content.
- Disable or sanitize raw HTML if reports are processed by a renderer that supports it.
- Store all records in a structured format such as validated JSON rather than an unescaped pipe-delimited format.
- Render reports exclusively from schema-validated records.
- If links are not required, reject link and image syntax or render user data in fenced or escaped plain-text form.
- Add tests covering newlines, pipe characters, headings, links, images, and embedded HTML.
