Skip to content

Commit

Permalink
fix #67 (vulnerable to ReDoS)
Browse files Browse the repository at this point in the history
  • Loading branch information
hgoebl committed Dec 9, 2017
1 parent ab8c7e8 commit 7222f6e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion generate/mobile-detect.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ define(function () {
}
}

function prepareUserAgent(userAgent) {
return (userAgent || '').substr(0, 500); // mitigate vulnerable to ReDoS
}

(function init() {
var key, values, value, i, len, verPos, mobileDetectRules = impl.mobileDetectRules;
for (key in mobileDetectRules.props) {
Expand Down Expand Up @@ -398,7 +402,7 @@ define(function () {
* @global
*/
function MobileDetect(userAgent, maxPhoneWidth) {
this.ua = userAgent || '';
this.ua = prepareUserAgent(userAgent);
this._cache = {};
//600dp is typical 7" tablet minimum width
this.maxPhoneWidth = maxPhoneWidth || 600;
Expand Down

0 comments on commit 7222f6e

Please sign in to comment.