Skip to content

fix: prevent CSV formula injection - #405

Closed
kul-91 wants to merge 2 commits into
AOSSIE-Org:mainfrom
kul-91:fix/370-csv-formula-injection
Closed

kul-91 wants to merge 2 commits into
AOSSIE-Org:mainfrom
kul-91:fix/370-csv-formula-injection

Conversation

@kul-91

@kul-91 kul-91 commented Oct 23, 2026 •

Copy link
Copy Markdown

Addressed Issues:

Fixes #370

Screenshots/Recordings:

Screencast_20261023_181520.webm

Summary:

  • Add a shared CSV serializer for all three CSV export functions.
  • Neutralize formula-like text beginning with =, +, -, and @, including prefixes preceded by whitespace or control characters.
  • Escape commas, double quotes, and newlines to ensure CSV fields are serialized correctly.
  • Add regression tests covering formula injection, CSV escaping, and preservation of ordinary text and numeric values.

Testing:

  • CSV export tests pass (11/11).
  • Full test suite passes (92/92 across 9 test files).
  • Production build succeeds (npm run build).
  • git diff --check passes.

Checklist

  • My code follows the project's code style and conventions
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contributing Guidelines

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • Bug Fixes
    • CSV exports now correctly handle commas, quotation marks, and line breaks, preserving values when opened in spreadsheet tools.
    • Text beginning with formula-like characters is prefixed to prevent unintended spreadsheet interpretation.
    • Empty values are exported as blank cells, and rows use consistent line endings.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between f8db13f and 65470b1.

📒 Files selected for processing: 2
  • src/services/analytics.csvExport.test.js
  • src/services/analytics.js

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Repository, contributor, and trend CSV exports now use shared serialization for formula-like values, CSV delimiters, quotes, and line breaks. Added tests check formula neutralization, escaping, and preservation of ordinary text and numeric values.

Changes

CSV export sanitization

Layer / File(s) Summary
Serialize and validate CSV exports
src/services/analytics.js, src/services/analytics.csvExport.test.js
Shared serializers neutralize formula-like strings, escape delimiters, quotes, and line breaks, and join rows with CRLF. Repository, contributor, and trend exports use the serializers. Tests cover formula-like values, escaping, and ordinary text and numeric values.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested labels: Typescript Lang

Suggested reviewers: ri1tik

Merge Risk: ⚪ Minimal · up to 65470

CSV exports now neutralize formula-like values and escape delimiters, quotes and newlines. The one narrow edge case, which needs a semicolon- or tab-delimited import of a value containing such a separator, does not block merging.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: prevent CSV formula injection" matches the main change. The PR adds a shared serializer to the three CSV export functions (repositories, contributors, trends). The serializer prefixes …
Linked Issues check Passed Issue #370 requires formula neutralization in exportReposCSV, exportContributorsCSV, and exportTrendsCSV, CSV escaping, and unit tests. serializeCSVCell applies apostrophe neutralization to st…
Out of Scope Changes check Passed The changed implementation is limited to CSV serialization and its use by the three exports named in issue #370. The added tests directly verify the required security and CSV behavior. No unrelated pr…
Full details: Title check

Explanation

The title "fix: prevent CSV formula injection" matches the main change. The PR adds a shared serializer to the three CSV export functions (repositories, contributors, trends). The serializer prefixes formula-like string cells with an apostrophe and escapes commas, quotes, and newlines. The PR also adds regression tests. The title is short, specific, and uses the conventional fix: prefix. It does not mention the escaping or the tests, but it does not need to cover every detail.

Full details: Linked Issues check

Explanation

Issue #370 requires formula neutralization in exportReposCSV, exportContributorsCSV, and exportTrendsCSV, CSV escaping, and unit tests. serializeCSVCell applies apostrophe neutralization to string values with the required formula prefixes, including leading whitespace or control characters. It escapes commas, quotes, and line breaks. All three exports use the shared serializer. analytics.csvExport.test.js covers formula prefixes, organization and contributor values, CSV escaping, and ordinary text and numeric values.

Full details: Out of Scope Changes check

Explanation

The changed implementation is limited to CSV serialization and its use by the three exports named in issue #370. The added tests directly verify the required security and CSV behavior. No unrelated production behavior or unrelated files are changed.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each cell with care,
A quote, a comma, safely there.
CRLF rows hop into place,
No formula leads the race.
The exports rest, neat as a hare.

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added bug Something isn't working javascript JavaScript/TypeScript changes tests Test changes size/M 51-200 lines changed first-time-contributor First time contributor and removed size/M 51-200 lines changed labels Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working first-time-contributor First time contributor javascript JavaScript/TypeScript changes size/M 51-200 lines changed tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Security: CSV Formula Injection (CWE-1236) in repository and contributor export files

1 participant