T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/excel_export.py:47
- Finding
- Spreadsheet Formula Injection in Generated Excel Files## Vulnerability Details **File Location**: `scripts/excel_export.py`, lines 47-67 **Vulnerability Type**: Spreadsheet formula injection **Risk Level**: Medium ```python # 邮编列进行去重 group_df = group_df.drop_duplicates(subset=['邮编']) # 增加开始邮编列. 值等于 邮编列的值 group_df.insert(3, '开始邮编', group_df['邮编']) # 增加技术邮编列. 值等于 邮编列的值 group_df.insert(4, '结束邮编', group_df['邮编']) # 删除 渠道组, 实重区间, 周长区间 列 group_df.drop(['邮编','渠道组', '实重区间', '周长区间'], axis=1, inplace=True) # 导出的文件需要增加 分区名称 列. 默认值 1 group_df.insert(0, '分区名称', 1) # 增加国家二字码列 默认值 US group_df.insert(1, '国家二字码', 'US') # 增加城市列默认值 空 group_df.insert(2, '城市', '') # 导出到新的 Excel 文件 group_df.to_excel(output_path, index=False) ``` ### Technical Analysis The script accepts cell content from an input workbook and writes it into newly generated workbooks without neutralizing spreadsheet formulas. In particular, the untrusted `邮编` value is copied into both the start-postal-code and end-postal-code columns. Other source columns that remain in `group_df` are also exported without validation. Spreadsheet-writing engines can encode strings beginning with `=` as formulas. Depending on the spreadsheet application and export engine, other formula-related prefixes such as `+`, `-`, or `@` may also require handling. Consequently, an attacker who can influence the input workbook can place a formula payload in a postal-code or retained source field. The generated workbook then carries that payload into a file likely to be trusted by its recipient. Formula execution depends on the recipient opening the workbook and on the spreadsheet application's security configuration. Potential payloads may invoke external links, initiate network requests, expose workbook or environment information, or display deceptive content. ### Attack Path 1. An attacker creates or modifies an input XLSX workbook. 2. Th ...[truncated 1356 chars]
- Remediation
- ## Remediation Suggestions - Treat every value originating from the input workbook as untrusted. - Validate postal codes against a strict, business-appropriate allowlist before export. For example, accept only the expected digits, letters, spaces, and hyphens, with a defined maximum length. - Sanitize every textual output cell, not only postal-code fields. Prefix formula-capable strings with an apostrophe or otherwise force them to be stored as literal text. - Account for at least `=`, `+`, `-`, and `@` after trimming leading whitespace and control characters. - Configure the selected Excel writer engine to disable automatic conversion of strings into formulas where supported. - Add automated tests covering formula payloads, leading whitespace, control characters, and ordinary postal codes. - Verify the generated workbook at the cell-type level to ensure untrusted values are stored as text rather than formulas.
