Skip to content

Commit 5d37621

Browse files
committed
fix(security): neutralize CSV formula injection in logs export
1 parent 20dd654 commit 5d37621

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

apps/sim/app/api/logs/export/route.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ const logger = createLogger('LogsExportAPI')
1414

1515
export const revalidate = 0
1616

17+
/**
18+
* Prefixes a single quote to values starting with a spreadsheet formula trigger
19+
* (`=`, `+`, `-`, `@`, tab, CR), neutralizing CSV injection in Excel/Sheets.
20+
*/
21+
function neutralizeCsvFormula(value: string): string {
22+
return /^[=+\-@\t\r]/.test(value) ? `'${value}` : value
23+
}
24+
1725
function escapeCsv(value: any): string {
1826
if (value === null || value === undefined) return ''
19-
const str = String(value)
27+
const str = neutralizeCsvFormula(String(value))
2028
if (/[",\n]/.test(str)) {
2129
return `"${str.replace(/"/g, '""')}"`
2230
}

0 commit comments

Comments
 (0)