T09 · Insecure Skill Coding Practices
- Location
scripts/generate_pdf.py:129- Finding
Unescaped User Input Is Parsed as ReportLab Paragraph Markup
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_pdf.py, lines 129-204
Vulnerability Type: ReportLab markup injection
Risk Level: MediumVulnerable Code
python info_data = [ [Paragraph("Team ID(团队 ID)", info_key_style), Paragraph(f":{team_id}", info_val_style)], [Paragraph("账户持有人法定姓名", info_key_style), Paragraph(f":{name}", info_val_style)], ]python app_data = [ [Paragraph("App ID(应用 ID)", info_key_style), Paragraph(f":{app_id}", info_val_style)], ]python declarations = [ f"本人 {name},Team ID 为 {team_id},现就 App ID 为 {app_id} 的独立应用,向 Apple 申请中国大陆地区 ICP 备案豁免例外批准。本人声明如下:", ]python sign_data = [ [Paragraph("手写签名:", sign_label_style), Paragraph(sig_line, sign_val_style), Paragraph("", sign_val_style)], [Paragraph("正楷姓名:", sign_label_style), Paragraph(name, sign_val_style), Paragraph("", sign_val_style)], [Paragraph("日 期:", sign_label_style), Paragraph(date, sign_val_style), Paragraph("", sign_val_style)], ]Technical Analysis
The command-line values
team_id,name,app_id, anddateare passed directly to ReportLabParagraphobjects. AParagraphdoes not treat its input exclusively as plain text; it parses a ReportLab-supported XML-like markup language.Because the values are not escaped, an attacker who can control one of these arguments can inject markup elements. This can alter formatting, insert misleading content, hide or restructure parts of the legal declaration, or cause PDF generation to fail. Depending on the installed ReportLab version and enabled resource handlers, resource-bearing markup such as image elements may also cause the process to resolve an attacker-selected URL or local resource.
The same input can be rendered in several sections of the document, increasing the scope of document manipulation. Input is also accepted ...[truncated 1390 chars]
- Remediation
View remediation
Remediation Suggestions
Treat all command-line values as untrusted plain text before passing them to
Paragraph.-
Escape XML-sensitive characters with
xml.sax.saxutils.escape:python from xml.sax.saxutils import escape safe_team_id = escape(team_id) safe_name = escape(name) safe_app_id = escape(app_id) safe_date = escape(date) -
Use only the escaped variables in all
Paragraphcontent. -
Validate inputs before PDF generation:
- Restrict Team ID to its documented character set and length.
- Restrict App ID to the expected numeric or identifier format.
- Parse and normalize the date using an explicit date format.
- Apply reasonable maximum lengths to every field.
- Reject control characters and line breaks where they are not required.
-
Do not attempt to sanitize markup with a tag blacklist. Encoding the complete value as plain text is safer.
-
Add tests using values containing
&,<,>, quotes, malformed tags, resource tags, and oversized input to confirm they are rendered literally or rejected.
-
