detect-no-csrf-before-method-override.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Check and see if CSRF middleware is before methodOverride
  3. * @author Adam Baldwin
  4. */
  5. //------------------------------------------------------------------------------
  6. // Rule Definition
  7. //------------------------------------------------------------------------------
  8. module.exports = function(context) {
  9. "use strict";
  10. var csrf = false;
  11. return {
  12. "CallExpression": function(node) {
  13. var token = context.getTokens(node)[0],
  14. nodeType = token.type,
  15. nodeValue = token.value;
  16. if (nodeValue === "express") {
  17. if (!node.callee || !node.callee.property) {
  18. return;
  19. }
  20. if (node.callee.property.name === "methodOverride" && csrf) {
  21. context.report(node, "express.csrf() middleware found before express.methodOverride()");
  22. }
  23. if (node.callee.property.name === "csrf") {
  24. // Keep track of found CSRF
  25. csrf = true;
  26. }
  27. }
  28. }
  29. };
  30. };