Skip to content

Conversation

@sequba
Copy link
Contributor

@sequba sequba commented Apr 22, 2025

Changes:

  • Add a configuration option sanitizeValues to exportPlugin.downloadFile API that controls the value sanitization during the CSV export
    • when sanitizeValues is true, HOT sanitizes values according to OWASP recommendations
    • when sanitizeValues is a regexp, HOT escapes all values that match the regexp
    • when sanitizeValues is a function, HOT replaces all values with the return value of the function
    • when sanitizeValues is not set, HOT doesn't sanitize values
  • Add e2e tests for this feature
  • Update typing for ExportOptions interface
  • Update relevant jsdocs
  • Describe it in export-to-csv guide

How has this been tested?

  • unit tests
  • new unit tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Additional language file or change to the existing one (translations)

Related issue(s):

Fixes https://github.com/handsontable/dev-handsontable/issues/1275

Affected project(s):

  • handsontable
  • @handsontable/angular
  • @handsontable/react
  • @handsontable/react-wrapper
  • @handsontable/vue
  • @handsontable/vue3

Checklist:

@sequba sequba self-assigned this Apr 22, 2025
@sequba sequba marked this pull request as ready for review April 22, 2025 11:43
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 22, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 27fc366:

Sandbox Source
handsontable-pr-javascript-demo Configuration
handsontable-ts-demo Configuration
handsontable-pr-react-demo Configuration

@sequba sequba requested review from jansiegel and qunabu April 22, 2025 14:48
@github-actions
Copy link

github-actions bot commented Apr 22, 2025

Launch the local version of documentation by running:

npm run docs:review f7bf68f2ca3930f5bd3542f776eb1b5b65352e9c

* @returns {string}
* @private
*/
_sanitizeValueWithOWASP(value) {
Copy link
Member

Choose a reason for hiding this comment

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

Not crucial, but you could utilize the private method notation with #, so #sanitizeValueWithOWASP. I think this plugin doesn't use it yet because it was created before we supported it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

@sequba I can see this change broke the test. These "private" functions don't seem to be that private 🙄 . I think you can either revert this change or try to refactor the plugin to make them actually private, whatever you think it's best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed escapeCell to be public again

@qunabu
Copy link
Contributor

qunabu commented Apr 23, 2025

Add example with 4 buttons that represent each sanitaze option

Screenshot 2025-04-23 at 10 13 48

with content

## Example with `sanitize` option enabled. 

The sanitize option for the Export to CSV plugin helps prevent [CSV injection](https://owasp.org/www-community/attacks/CSV_Injection) vulnerabilities by sanitizing cell data before exporting. CSV injection can occur when malicious formulas or commands are injected into CSV files that are later opened in spreadsheet applications.

button1 button2 button3 button4

table with unsafe data 

toolbar with sourcecode preview 

@sequba sequba requested review from jansiegel and qunabu April 23, 2025 13:34
@sequba sequba merged commit 1e4543f into develop Apr 23, 2025
33 of 34 checks passed
@sequba sequba deleted the feature/dev-issue-1275 branch April 23, 2025 13:45
@sequba
Copy link
Contributor Author

sequba commented Apr 23, 2025

Add example with 4 buttons that represent each sanitaze option

This will be done in separate task: https://github.com/handsontable/dev-handsontable/issues/2444

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.

5 participants