Skip to content

Commit 74a55f5

Browse files
committed
Merge pull request #539 from Martii/plugPotentialDDoS
Fix enforcing of `limit` QS fix for non-numerics in `limitRange` Auto-merge
2 parents 7606f0a + c6251d4 commit 74a55f5

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

libs/helpers.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ exports.cleanFilename = function (aFilename, aDefaultName) {
9696
return cleanName || aDefaultName;
9797
};
9898

99-
exports.limitRange = function (aMin, aX, aMax) {
100-
return Math.max(Math.min(aX, aMax), aMin);
99+
exports.limitRange = function (aMin, aX, aMax, aDefault) {
100+
var x = Math.max(Math.min(aX, aMax), aMin);
101+
102+
// ES5 strict similar check to ES6 Number.isNaN()
103+
return (x !== x ? aDefault : x);
101104
};
102105

103106
exports.limitMin = function (aMin, aX) {

libs/templateHelpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ var newPagination = function (aCurrentPage, aItemsPerPage) {
8080

8181
//
8282
pagination.currentPage = aCurrentPage ? helpers.limitMin(1, aCurrentPage) : 1;
83-
pagination.itemsPerPage = aItemsPerPage ? helpers.limitRange(1, aItemsPerPage, maxItemsPerPage) : defaultItemsPerPage;
83+
pagination.itemsPerPage = aItemsPerPage ?
84+
helpers.limitRange(1, aItemsPerPage, maxItemsPerPage, defaultItemsPerPage) :
85+
defaultItemsPerPage;
8486

8587
return pagination;
8688
};

0 commit comments

Comments
 (0)