T09 · Insecure Skill Coding Practices
- Location
parse_blf_signal.py:76- Finding
Spreadsheet Formula Injection in CSV Exports
- Content
View full analysis
Vulnerability Details
File Location:
parse_blf_signal.py:76-79;visualize_signal.py:85-89
Vulnerability Type: CSV formula injection
Risk Level: MediumVulnerable Code
parse_blf_signal.py:76-79:python elif output_format == 'csv': csv_lines = ['timestamp,value'] for point in timeseries: csv_lines.append(f"{point['timestamp']},{point['value']}") return '\n'.join(csv_lines)visualize_signal.py:85-89:python elif format_type == 'csv': if 'time_series' not in data: return "No time series data available" csv_lines = ['timestamp,value'] for point in data['time_series']: if 'timestamp' in point and 'value' in point: csv_lines.append(f"{point['timestamp']},{point['value']}") return '\n'.join(csv_lines)Technical Analysis
Both CSV export implementations construct rows through direct string interpolation. They do not use a standards-compliant CSV writer, quote fields, validate value types, or neutralize spreadsheet formula prefixes.
Values decoded from attacker-controlled DBC definitions may be represented as strings, while
visualize_signal.pydirectly accepts values from an input JSON document. If a cell begins with a spreadsheet formula marker such as=,+,-, or@, spreadsheet applications may interpret the value as a formula rather than inert data.Quoting a field is not, by itself, sufficient protection against every spreadsheet application. Formula-leading string cells should be explicitly neutralized or rejected.
Attack Path
- An attacker creates a DBC or JSON input containing a signal value represented by a formula-like string, such as
=HYPERLINK("https://attacker.example","Open report"). - The victim processes that input and requests CSV output.
- The application interpolates the attacker-controlled value directly into a CSV cell.
- The victim opens the r ...[truncated 823 chars]
- An attacker creates a DBC or JSON input containing a signal value represented by a formula-like string, such as
- Remediation
View remediation
Remediation Suggestions
- Use Python's
csvmodule instead of manually concatenating fields. - Enforce numeric types for signal values when the expected signal domain is numeric.
- For string fields, neutralize values whose first non-whitespace character is
=,+,-, or@, for example by prefixing an apostrophe. - Apply neutralization only to string fields so legitimate negative numeric values remain numeric.
- Quote fields consistently and handle embedded commas, quotes, and line breaks.
- Add tests covering formula prefixes, leading whitespace, embedded delimiters, quotes, and newline characters.
Example hardening approach:
python import csv import io def safe_spreadsheet_cell(value): if isinstance(value, str) and value.lstrip().startswith(('=', '+', '-', '@')): return "'" + value return value output = io.StringIO() writer = csv.writer(output) writer.writerow(['timestamp', 'value']) for point in timeseries: writer.writerow([ safe_spreadsheet_cell(point['timestamp']), safe_spreadsheet_cell(point['value']) ]) csv_data = output.getvalue()- Use Python's
