From 5ff62f0a8c98245f5632d69dfcb147efb87cd623 Mon Sep 17 00:00:00 2001 From: kakwa Date: Fri, 29 Jul 2016 23:00:16 +0200 Subject: [PATCH] fix ppolicy client side javascript checker Due to a missing encodeURIComponent, the post arguments of the http query on /checkppolicy could be interpreted as several argument if caracters like & or = were present. This commit also adds error handling on http return codes in the checker. --- resources/static/js/ppolicy.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/resources/static/js/ppolicy.js b/resources/static/js/ppolicy.js index 655ec67..8e9ef25 100644 --- a/resources/static/js/ppolicy.js +++ b/resources/static/js/ppolicy.js @@ -10,9 +10,24 @@ $('#form').validator({ type: 'POST', dataType: 'json', async: false, - data: 'pwd=' + $el.val(), + data: 'pwd=' + encodeURIComponent($el.val()), success: function(data) { $ret = data; + }, + error: function(jqXHR, exception) { + switch (jqXHR.status) { + case 400: + $ret = {"reason":"Javascript ppolicy.js error","match":false}; + break; + case 403: + $ret = {"reason":"Session expired, you must reconnect","match":false}; + break; + case 500: + $ret = {"reason":"Server error","match":false}; + break; + default: + $ret = {"reason":"Unknown error [" + jqXHR.status + "], check logs","match":false}; + } } }); this.options.errors['ppolicy'] = $ret['reason'];