Skip to content

Commit dd7039f

Browse files
Copilothotlong
andcommitted
fix: use crypto.randomUUID for transaction IDs, use single-quote for Excel formula injection protection
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 9274ad3 commit dd7039f

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/core/src/actions/TransactionManager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,14 @@ export class TransactionManager {
503503
// Helpers
504504
// ==========================================================================
505505

506-
let idCounter = 0;
507-
508506
/**
509-
* Generate a simple unique ID
507+
* Generate a unique transaction ID using crypto when available
510508
*/
511509
function generateId(): string {
512-
idCounter++;
513-
return `txn_${Date.now()}_${idCounter}`;
510+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
511+
return `txn_${crypto.randomUUID()}`;
512+
}
513+
return `txn_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
514514
}
515515

516516
/**

packages/plugin-report/src/LiveReportExporter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,14 @@ function getExcelColumnLetter(index: number): string {
326326

327327
/**
328328
* Sanitize cell values to prevent formula injection in Excel.
329-
* Prefixes values starting with formula characters (=, +, -, @, |) with a tab.
329+
* Prefixes values starting with formula characters (=, +, -, @, |) with a
330+
* single-quote, which is the standard Excel protection against formula injection.
330331
*/
331332
function sanitizeExcelValue(val: string): string {
332333
if (val.length > 0) {
333334
const firstChar = val.charAt(0);
334335
if (firstChar === '=' || firstChar === '+' || firstChar === '-' || firstChar === '@' || firstChar === '|') {
335-
return `\t${val}`;
336+
return `'${val}`;
336337
}
337338
}
338339
return val;

0 commit comments

Comments
 (0)