bb-plane-fork/apps/api/plane/utils/csv_utils.py
sriram veeraghanta dfce8c6278
chore: admin folder structure (#8632)
* chore: admin folder structure

* fix: copy right check and formatting

* fix: types
2026-02-13 16:29:45 +05:30

26 lines
937 B
Python

# Copyright (c) 2023-present Plane Software, Inc. and contributors
# SPDX-License-Identifier: AGPL-3.0-only
# See the LICENSE file for details.
# CSV utility functions for safe export
# Characters that trigger formula evaluation in spreadsheet applications
_CSV_FORMULA_TRIGGERS = frozenset(("=", "+", "-", "@", "\t", "\r", "\n"))
def sanitize_csv_value(value):
"""Sanitize a value for CSV export to prevent formula injection.
Prefixes string values starting with formula-triggering characters
with a single quote so spreadsheet applications treat them as text
instead of evaluating them as formulas.
See: https://owasp.org/www-community/attacks/CSV_Injection
"""
if isinstance(value, str) and value and value[0] in _CSV_FORMULA_TRIGGERS:
return "'" + value
return value
def sanitize_csv_row(row):
"""Sanitize all values in a CSV row."""
return [sanitize_csv_value(v) for v in row]