T09 · Insecure Skill Coding Practices
- Location
datev-export.py:81- Finding
Spreadsheet Formula Injection in DATEV CSV Exports
- Content
View full analysis
Vulnerability Details
File Location:
datev-export.py:81-82, 112, 142-143
Vulnerability Type: CSV/spreadsheet formula injection
Risk Level: MediumVulnerable Code
python beschreibung = buchung.get('beschreibung') or buchung.get('anbieter', '')python row = [ f"{betrag:.2f}", # Umsatz soll_haben, # Soll/Haben 'EUR', # WKZ '', # Kurs '', # Basis-Umsatz '', # WKZ Basis konto, # Konto gegenkonto, # Gegenkonto beleg, # Belegfeld1 beleg_datum, # Belegfeld2 '', # Skonto beschreibung, # Buchungstext '', # Postensperre '', # Adressfelder '', # Geschäftspartnerbank '', # Sachverhalt '', # Zahlweise '', # Forderungsart '', # Veranlagungsnummer '', # Ausstellungsdatum buch_datum, # Datum steuercode, # Steuercode ] rows.append(row)python writer = csv.writer(output, delimiter=';') writer.writerow(header) writer.writerows(rows)Technical Analysis
Booking descriptions and vendor names can originate from externally supplied accounting records. These values are placed into spreadsheet-compatible CSV cells without neutralizing characters that spreadsheet applications interpret as formulas, including
=,+,-,@, tab, and carriage return.CSV quoting only preserves field boundaries; it does not prevent spreadsheet software from interpreting a quoted value as a formula. Consequently, a value such as
=HYPERLINK("https://attacker.example","Open")may be evaluated when the resulting DATEV CSV is opened.Attack Path
- An attacke ...[truncated 949 chars]
- Remediation
View remediation
Remediation Suggestions
- Apply a shared sanitization function to every untrusted text cell before CSV serialization.
- Prefix values beginning with
=,+,-,@, tab, or carriage return with an apostrophe or otherwise encode them according to the target DATEV workflow. - Validate dates, account numbers, categories, invoice identifiers, and monetary values against strict allowlists.
- Treat descriptions and vendor names as untrusted even when imported from internal accounting files.
- Add regression tests using values such as
=1+1,+SUM(1,1),@SUM(1,1), and tab-prefixed formulas.
