Skip to content

fix(output): prevent CSV formula injection - #31

Open
zoya-brd wants to merge 2 commits into
mainfrom
fix/csv-formula-injection
Open

fix(output): prevent CSV formula injection#31
zoya-brd wants to merge 2 commits into
mainfrom
fix/csv-formula-injection

Conversation

@zoya-brd

Copy link
Copy Markdown
Collaborator

No description provided.

@zoya-brd
zoya-brd requested a review from artemo-brd August 31, 2026 09:10
Comment thread src/utils/output.ts Outdated
};

const sanitize_csv_cell = (s: string): string=>{
if (/^[=+\-@\t\r]/.test(s))

@artemo-brd artemo-brd Aug 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a workaround for formula injection if there is a space before a formula like " =cmd|'/c calc'!A0" . Please detect dangerous prefixes after leading whitespace without removing that whitespace from the exported value. For example:

if (/^[\s\u00a0]*[=+\-@]/.test(s))
    return "'" + s;

Please add tests for regular spaces, tabs, and NBSP.

This also changes numeric-looking string values such as "-100" and "+15". Is that intentional? If we want to preserve them, please define a strict numeric-string exemption and add tests. Otherwise, we should document that sanitization intentionally modifies all string cells starting with + or -.

Comment thread src/utils/output.ts
return JSON.stringify(data, null, 2);
};

const print = (data: unknown, opts: Print_opts = {})=>{

@artemo-brd artemo-brd Aug 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/commands/dataset.ts -> handle_pipelines:

handle_pipelines() requests CSV from the API, so the result is already a string. Without -o, print() treats it as raw because format is not passed. With -o file.csv, serialize_csv() still returns the string unchanged before csv_escape.

Passing format to print() alone therefore won't fix the issue. We should choose:

  • request structured JSON and serialize it locally when CSV output is requested, or
  • parse the returned CSV and sanitize/re-serialize every cell.

Please add regression tests for both stdout redirection and -o file.csv

Comment thread src/utils/output.ts
return JSON.stringify(val);
};

const sanitize_csv_cell = (s: string): string=>{

@artemo-brd artemo-brd Aug 31, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a global sanitize_csv configuration option that users can set with:

brightdata config set sanitize_csv false
brightdata config set sanitize_csv true

It should default to true. Since config values currently enter through the CLI as strings, please validate and convert "true"/"false" to actual booleans when setting or reading this option; "false" must not be treated as a truthy string. Other values should be rejected.

We can add per-command overrides later if needed (scrape, search, pipelines, discover, scraper, browser),

@artemo-brd artemo-brd changed the title fix(output): prevent CVS formula injection fix(output): prevent CSV formula injection Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants