-
Notifications
You must be signed in to change notification settings - Fork 62
Fix: correct minor bugs in the import/export workflow #656
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 1 commit
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -320,6 +320,14 @@ public static function showResultsForm(PluginDatainjectionModel $model) | |||||
| TemplateRenderer::getInstance()->display('@datainjection/clientinjection_result.html.twig', $data); | ||||||
| } | ||||||
|
|
||||||
| private static function escapeCsvFormula($value) | ||||||
| { | ||||||
| if (is_string($value) && isset($value[0]) && str_contains('=+-@', $value[0])) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arguments are in an unconventional order:
Suggested change
|
||||||
| return "'" . $value; | ||||||
| } | ||||||
| return $value; | ||||||
| } | ||||||
|
|
||||||
| public static function exportErrorsInCSV() | ||||||
| { | ||||||
|
|
||||||
|
|
@@ -328,7 +336,7 @@ public static function exportErrorsInCSV() | |||||
|
|
||||||
| if (!empty($error_lines)) { | ||||||
| $model = PluginDatainjectionSession::unserialize(PluginDatainjectionSession::getParam('currentmodel')); | ||||||
| $file = PLUGIN_DATAINJECTION_UPLOAD_DIR . PluginDatainjectionSession::getParam('file_name'); | ||||||
| $file = PLUGIN_DATAINJECTION_UPLOAD_DIR . basename(PluginDatainjectionSession::getParam('file_name')); | ||||||
|
|
||||||
| $mappings = $model->getMappings(); | ||||||
| $tmpfile = fopen($file, 'w'); | ||||||
|
|
@@ -341,11 +349,11 @@ public static function exportErrorsInCSV() | |||||
|
|
||||||
| //Write lines | ||||||
| foreach ($error_lines as $line) { | ||||||
| fputcsv($tmpfile, $line, $model->getBackend()->getDelimiter()); | ||||||
| fputcsv($tmpfile, array_map([self::class, 'escapeCsvFormula'], $line), $model->getBackend()->getDelimiter()); | ||||||
| } | ||||||
| fclose($tmpfile); | ||||||
|
|
||||||
| $name = "Error-" . PluginDatainjectionSession::getParam('file_name'); | ||||||
| $name = "Error-" . basename(PluginDatainjectionSession::getParam('file_name')); | ||||||
| $name = str_replace(' ', '', $name); | ||||||
| header('Content-disposition: attachment; filename=' . $name); | ||||||
| header('Content-Type: application/octet-stream'); | ||||||
|
|
||||||
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.
New security function with no unit test. It is a pure function with several edge cases worth pinning (empty string, non-string passthrough, each of the four trigger characters, a value starting with a safe character). Without a test, a future refactor or PHP upgrade could silently break the protection and let formula-injection payloads through.
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.
Missing PHP 8.2 type declarations. The function accepts any type (non-strings are passed through unchanged) and returns the same type. Project rules require strict typing everywhere.