-
Notifications
You must be signed in to change notification settings - Fork 2
SL-378 Fix API password corruption and plaintext exposure on settings save #331
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -56,6 +56,9 @@ public function initContent() | |
|
|
||
| public function postProcess() | ||
| { | ||
| $this->keepExistingPasswordWhenSubmittedEmpty(SaferPayConfig::PASSWORD); | ||
| $this->keepExistingPasswordWhenSubmittedEmpty(SaferPayConfig::PASSWORD . SaferPayConfig::TEST_SUFFIX); | ||
|
|
||
| parent::postProcess(); | ||
|
|
||
| /** @var Configuration $configuration */ | ||
|
|
@@ -82,6 +85,15 @@ public function postProcess() | |
| return true; | ||
| } | ||
|
|
||
| private function keepExistingPasswordWhenSubmittedEmpty($key) | ||
| { | ||
| if (!isset($_POST[$key]) || $_POST[$key] !== '') { | ||
| return; | ||
| } | ||
|
|
||
| $_POST[$key] = \Configuration::get($key); | ||
| } | ||
|
Comment on lines
+88
to
+95
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. Refactor this helper method to dynamically remove the empty password fields from private function ignoreEmptyPasswordFieldsFromOptions()
{
$keys = [
SaferPayConfig::PASSWORD,
SaferPayConfig::PASSWORD . SaferPayConfig::TEST_SUFFIX,
];
foreach ($keys as $key) {
if (Tools::getValue($key) === '') {
foreach ($this->fields_options as &$category) {
if (isset($category['fields'][$key])) {
unset($category['fields'][$key]);
}
}
}
}
} |
||
|
|
||
| private function validateTerminalId() | ||
| { | ||
| try { | ||
|
|
@@ -489,7 +501,10 @@ private function displayTestEnvironmentConfiguration() | |
| 'title' => $this->module->l('JSON API Password'), | ||
| 'type' => 'password_input', | ||
| 'class' => 'fixed-width-xl', | ||
| 'value' => \Configuration::get(SaferPayConfig::PASSWORD . SaferPayConfig::TEST_SUFFIX), | ||
| 'autocomplete' => false, | ||
| 'placeholder' => \Configuration::get(SaferPayConfig::PASSWORD . SaferPayConfig::TEST_SUFFIX) | ||
| ? $this->module->l('Leave empty to keep the saved password') | ||
| : '', | ||
| ], | ||
| SaferPayConfig::CUSTOMER_ID . SaferPayConfig::TEST_SUFFIX => [ | ||
| 'title' => $this->module->l('Customer ID'), | ||
|
|
@@ -557,7 +572,10 @@ private function displayLiveEnvironmentConfiguration() | |
| 'title' => $this->module->l('JSON API Password'), | ||
| 'type' => 'password_input', | ||
| 'class' => 'fixed-width-xl', | ||
| 'value' => \Configuration::get(SaferPayConfig::PASSWORD), | ||
| 'autocomplete' => false, | ||
| 'placeholder' => \Configuration::get(SaferPayConfig::PASSWORD) | ||
| ? $this->module->l('Leave empty to keep the saved password') | ||
| : '', | ||
| ], | ||
| SaferPayConfig::CUSTOMER_ID => [ | ||
| 'title' => $this->module->l('Customer ID'), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,8 @@ | |
| class="{if isset($field['class'])}{$field['class']|escape:'htmlall':'UTF-8'}{/if}" | ||
| size="{if isset($field['size'])}{$field['size']|intval}{else}5{/if}" | ||
| name="{$key|escape:'htmlall':'UTF-8'}" | ||
| value="{$field['value']|escape:'htmlall':'UTF-8'}" | ||
| value="" | ||
| {if isset($field['placeholder']) && $field['placeholder']} placeholder="{$field['placeholder']|escape:'htmlall':'UTF-8'}"{/if} | ||
| {if isset($field['autocomplete']) && !$field['autocomplete']} autocomplete="off"{/if} /> | ||
|
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. Modern browsers (such as Chrome, Firefox, and Safari) often ignore |
||
| </div> | ||
| {/if} | ||
|
|
||
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.
Instead of directly modifying the global
$_POSTsuperglobal (which is a code smell and can lead to unexpected side effects or issues with other modules/hooks), we can dynamically remove the password fields from$this->fields_optionswhen they are submitted empty. This prevents PrestaShop'sHelperOptionsfrom updating them in the database, preserving the existing configuration values cleanly and safely.