@@ -198,6 +198,16 @@ public function saveProperties()
198198 ];
199199 }
200200
201+ if (!$ this ->validateCryptoParams ()) {
202+ return [
203+ "status " => "error " , "data " => [
204+ "message " => $ this ->localization ->t (
205+ "Hash algorithm parameter is out of range. "
206+ )
207+ ]
208+ ];
209+ }
210+
201211 foreach ($ properties as $ key => $ value ) {
202212 $ reqValue = $ this ->request ->getParam (str_replace (". " , "- " , $ key ));
203213 $ appValue = $ this ->properties [$ key ];
@@ -213,6 +223,9 @@ public function saveProperties()
213223 "Property ' $ key' has been set to: " . $ value ,
214224 ["app " => $ this ->appName ]
215225 );
226+ } elseif (!is_bool ($ appValue ) && !isset ($ reqValue )) {
227+ unset($ this ->properties [$ key ]);
228+
216229 }
217230 }
218231
@@ -230,6 +243,48 @@ public function saveProperties()
230243 ];
231244 }
232245
246+ /**
247+ * Validate request crypto params.
248+ *
249+ * @return bool TRUE if crypto params are correct FALSE otherwise.
250+ */
251+ private function validateCryptoParams ()
252+ {
253+ $ cryptoClass = $ this ->request ->getParam ("opt-crypto_class " );
254+ $ configuration = $ this ->cryptoClassConfiguration ($ cryptoClass );
255+
256+ for ($ i = 0 ; $ i < count ($ configuration ); ++$ i ) {
257+ $ reqParam = $ this ->request ->getParam (
258+ "opt-crypto_param_ " . $ i , null
259+ );
260+ $ cryptoParam = $ configuration [$ i ];
261+
262+ if (is_null ($ reqParam ) || $ reqParam < $ cryptoParam ->min
263+ || $ reqParam > $ cryptoParam ->max
264+ ) {
265+ return false ;
266+ }
267+ }
268+
269+ return true ;
270+ }
271+
272+ /**
273+ * Get a crypto class configuration from request.
274+ *
275+ * @param $cryptoClass string Crypto class name.
276+ *
277+ * @return array A crypto class configuration.
278+ */
279+ private function cryptoClassConfiguration ($ cryptoClass )
280+ {
281+ /**
282+ * @var $passwordAlgorithm IPasswordAlgorithm
283+ */
284+ $ passwordAlgorithm = new $ cryptoClass ($ this ->localization );
285+ return $ passwordAlgorithm ->configuration ();
286+ }
287+
233288 /**
234289 * Clear the application cache memory.
235290 *
@@ -385,12 +440,8 @@ public function cryptoParams()
385440 "Entering cryptoParams() " , ["app " => $ this ->appName ]
386441 );
387442
388- /**
389- * @var $passwordAlgorithm IPasswordAlgorithm
390- */
391443 $ cryptoClass = $ this ->request ->getParam ("cryptoClass " );
392- $ passwordAlgorithm = new $ cryptoClass ($ this ->localization );
393- $ configuration = $ passwordAlgorithm ->configuration ();
444+ $ configuration = $ this ->cryptoClassConfiguration ($ cryptoClass );
394445
395446 if ($ cryptoClass === $ this ->properties [Opt::CRYPTO_CLASS ]) {
396447 foreach ($ configuration as $ key => $ value ) {
0 commit comments