-
Notifications
You must be signed in to change notification settings - Fork 284
N°6977 - Sanitize Excel formulas in exports #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f0e6224
4be4c9f
ec00c05
e0dfab0
43fc6f8
8f39d07
e47556e
86133b5
80a5d9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||||||
| * @license http://opensource.org/licenses/AGPL-3.0 | ||||||||||
| */ | ||||||||||
|
|
||||||||||
| use Combodo\iTop\Application\Helper\ExportHelper; | ||||||||||
| use Combodo\iTop\Application\UI\Base\Component\FieldSet\FieldSetUIBlockFactory; | ||||||||||
| use Combodo\iTop\Application\UI\Base\Component\Html\Html; | ||||||||||
| use Combodo\iTop\Application\UI\Base\Component\Input\InputUIBlockFactory; | ||||||||||
|
|
@@ -13,7 +14,6 @@ | |||||||||
| use Combodo\iTop\Application\UI\Base\Component\Panel\PanelUIBlockFactory; | ||||||||||
| use Combodo\iTop\Application\UI\Base\Layout\MultiColumn\Column\ColumnUIBlockFactory; | ||||||||||
| use Combodo\iTop\Application\UI\Base\Layout\MultiColumn\MultiColumnUIBlockFactory; | ||||||||||
| use Combodo\iTop\Application\Helper\ExportHelper; | ||||||||||
| use Combodo\iTop\Application\WebPage\Page; | ||||||||||
| use Combodo\iTop\Application\WebPage\WebPage; | ||||||||||
|
|
||||||||||
|
|
@@ -55,6 +55,8 @@ public function ReadParameters() | |||||||||
| $this->aStatusInfo['charset'] = strtoupper(utils::ReadParam('charset', 'UTF-8', true, 'raw_data')); | ||||||||||
| $this->aStatusInfo['formatted_text'] = (bool)utils::ReadParam('formatted_text', 0, true); | ||||||||||
|
|
||||||||||
| $this->aStatusInfo['ignore_excel_sanitization'] = (bool)utils::ReadParam('ignore_excel_sanitization', 0, true, utils::ENUM_SANITIZATION_FILTER_INTEGER); | ||||||||||
|
|
||||||||||
| $sDateFormatRadio = utils::ReadParam('csv_date_format_radio', ''); | ||||||||||
| switch ($sDateFormatRadio) { | ||||||||||
| case 'default': | ||||||||||
|
|
@@ -223,6 +225,10 @@ public function GetFormPart(WebPage $oP, $sPartId) | |||||||||
| $oRadioCustom->GetInput()->AddCSSClass('ibo-input-checkbox'); | ||||||||||
| $oFieldSetDate->AddSubBlock($oRadioCustom); | ||||||||||
|
|
||||||||||
| $oFieldSetSecurity = FieldSetUIBlockFactory::MakeStandard(Dict::S('Core:BulkExport:Security')); | ||||||||||
| $oMulticolumn->AddColumn(ColumnUIBlockFactory::MakeForBlock($oFieldSetSecurity)); | ||||||||||
| $oFieldSetSecurity->AddSubBlock(ExportHelper::GetInputForSanitizeExcelExport()); | ||||||||||
|
|
||||||||||
| $oP->add_ready_script( | ||||||||||
| <<<EOF | ||||||||||
| $('#form_part_csv_options').on('preview_updated', function() { FormatDatesInPreview('csv', 'csv'); }); | ||||||||||
|
|
@@ -264,6 +270,13 @@ protected function GetValue($oObj, $sAttCode) | |||||||||
| default: | ||||||||||
| $sRet = trim($oObj->GetAsCSV($sAttCode), '"'); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // If the option to ignore Excel sanitization is not set or explicitly set to false, apply sanitization | ||||||||||
| if (!(array_key_exists('ignore_excel_sanitization', $this->aStatusInfo)) || $this->aStatusInfo['ignore_excel_sanitization'] === false) { | ||||||||||
| return ExportHelper::SanitizeField($sRet, $this->aStatusInfo['text_qualifier'] ?? ''); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // The option to ignore Excel sanitization is explicitly set to true: return the raw value without sanitization | ||||||||||
| return $sRet; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -337,6 +350,12 @@ public function GetNextChunk(&$aStatus) | |||||||||
| $sField = $oObj->GetAsCSV($sAttCode, $this->aStatusInfo['separator'], $this->aStatusInfo['text_qualifier'], $this->bLocalizeOutput, !$this->aStatusInfo['formatted_text']); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // If the option to ignore Excel sanitization is not set or absent, sanitize the field | ||||||||||
| if (!(array_key_exists('ignore_excel_sanitization', $this->aStatusInfo)) || $this->aStatusInfo['ignore_excel_sanitization'] === false) { | ||||||||||
| $sField = ExportHelper::SanitizeField($sField, $this->aStatusInfo['text_qualifier']); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
Comment on lines
+354
to
+358
|
||||||||||
| // If the option to ignore Excel sanitization is not set or absent, sanitize the field | |
| if (!(array_key_exists('ignore_excel_sanitization', $this->aStatusInfo)) || $this->aStatusInfo['ignore_excel_sanitization'] === false) { | |
| $sField = ExportHelper::SanitizeField($sField, $this->aStatusInfo['text_qualifier']); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetValue is not called in the GetNextChunk context in CSV export (it is though in the Excel export, that's why the code differs).
The sanitization does not add the text_qualifier, it strips them from the start of the value to compare its first character and then add it back.
I see no risk of double sanitization
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ | |
| */ | ||
|
|
||
| @import "bulk-modify"; | ||
| @import "bulk-export"; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /* | ||
| * @copyright Copyright (C) 2010-2026 Combodo SAS | ||
| * @license http://opensource.org/licenses/AGPL-3.0 | ||
| */ | ||
|
|
||
| #form_part_csv_options:has(#ibo-sanitize-excel-export--input:checked), #form_part_xlsx_options:has(#ibo-sanitize-excel-export--input:checked){ | ||
| #ibo-sanitize-excel-export--alert { | ||
| display: none; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.