T09 · Insecure Skill Coding Practices
- Location
scripts/update_ledger.py:48- Finding
Excel Formula Injection Through Unvalidated Ledger Fields
- Content
View full analysis
Vulnerability Details
File Location:
scripts/update_ledger.py, lines 48–58
Vulnerability Type: Spreadsheet formula injection
Risk Level: Mediumpython else: ws.append([date, url]) added += 1 wb.save(ledger_path) return added def main(): parser = argparse.ArgumentParser(description="更新腾讯文档归档台账") parser.add_argument("--date", default=datetime.now().strftime("%Y%m%d"), help="下载日期 YYYYMMDD") parser.add_argument("--url", action="append", required=True, help="腾讯文档链接(可多次指定)")Technical Analysis
The
--dateand--urlarguments are accepted as arbitrary strings and written directly to cells in an XLSX workbook. The script does not enforce the documentedYYYYMMDDdate format, validate that URLs use the expecteddocs.qq.comhost, or neutralize spreadsheet formula prefixes.Spreadsheet applications can interpret cell values beginning with characters such as
=,+,-, or@as formulas rather than plain text. Consequently, an attacker who controls either command-line value can inject a formula into the generated ledger. Depending on the spreadsheet application and its security configuration, formulas may create deceptive hyperlinks, initiate external network requests, expose spreadsheet data, or invoke dangerous legacy functionality.Attack Path
- An attacker supplies a crafted value to a system or operator that ultimately invokes
update_ledger.py. - The script is run with a formula-like value, for example through
--date '=HYPERLINK("https://attacker.example","Open document")'or an equivalently crafted--urlvalue. argparseaccepts the value because no format or hostname validation is configured.ws.append([date, url])stores the attacker-controlled input in the workbook.- A user opens
腾讯文档链接台账.xlsxin spreadsheet software. - The spreadsheet application interprets the cell as a formula. The resulting ...[truncated 621 chars]
- An attacker supplies a crafted value to a system or operator that ultimately invokes
- Remediation
View remediation
Remediation Suggestions
- Validate
--dateusingdatetime.strptime(value, "%Y%m%d")and reject any value that does not exactly match the required format. - Parse every URL with a standard URL parser and require an approved scheme, preferably HTTPS.
- Require the normalized hostname to be exactly
docs.qq.com, or explicitly document and enforce a narrowly defined subdomain policy. - Reject URLs containing unexpected credentials, control characters, or malformed components.
- Before writing user-controlled text to a spreadsheet, treat it explicitly as text. Reject or prefix values beginning with
=,+,-, or@with an apostrophe. - Apply validation within
append_rowsas well as at the CLI boundary so that future programmatic callers cannot bypass it. - Add tests covering formula prefixes, malformed dates, alternate hosts, deceptive hostnames, and encoded control characters.
- Validate
