NShiftKey-Rule-Guide logo NShiftKey-Rule-Guide

1. Vulnerability Description

2. Vulnerability Countermeasure

3. Sample code

validateEmailFormat: function( string ) {
  var emailExpression = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  return emailExpression.test( string );
}
start = process.hrtime();
console.log(validateEmailFormat(""jjjjjjjjjjjjjjjjjjjjjjjjjjjj@ccccccccccccccccccccccccccccc.555555555555555555555555555555555555555555555555555555{""));
console.log(process.hrtime(start));

output>
false
[ 8, 487126563 ]
var safe = require('safe-regex');
module.exports = function(context) {
  ""use strict"";

  return {
    ""Literal"": function(node) {
      var token = context.getTokens(node)[0],
          nodeType = token.type,
          nodeValue = token.value;

      if (nodeType === ""RegularExpression"") {
        if (!safe(nodeValue)) {
          context.report(node, ""Possible Unsafe Regular Expression"");
        }
      }
    }
  };
};