msimerson/Haraka

View on GitHub
plugins/bounce.js

Summary

Maintainability
D
3 days
Test Coverage

Function bounce_spf has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.bounce_spf = function (next, connection) {
    if (!this.cfg.check.bounce_spf) return next();
    if (!this.has_null_sender(connection)) return next();

    const txn = connection?.transaction;
Severity: Major
Found in plugins/bounce.js - About 2 hrs to fix

    Function non_local_msgid has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.non_local_msgid = function (next, connection) {
        if (!this.cfg.check.non_local_msgid) return next();
        if (!this.has_null_sender(connection)) return next();
    
        const transaction = connection?.transaction;
    Severity: Minor
    Found in plugins/bounce.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File bounce.js has 261 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // bounce tests
    const tlds = require('haraka-tld');
    const { SPF }  = require('haraka-plugin-spf');
    
    const net_utils = require('haraka-net-utils');
    Severity: Minor
    Found in plugins/bounce.js - About 2 hrs to fix

      Function bounce_spf has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.bounce_spf = function (next, connection) {
          if (!this.cfg.check.bounce_spf) return next();
          if (!this.has_null_sender(connection)) return next();
      
          const txn = connection?.transaction;
      Severity: Minor
      Found in plugins/bounce.js - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function non_local_msgid has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.non_local_msgid = function (next, connection) {
          if (!this.cfg.check.non_local_msgid) return next();
          if (!this.has_null_sender(connection)) return next();
      
          const transaction = connection?.transaction;
      Severity: Minor
      Found in plugins/bounce.js - About 1 hr to fix

        Avoid too many return statements within this function.
        Open

                if (!this.cfg.reject.non_local_msgid) return next();
        Severity: Major
        Found in plugins/bounce.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                              return run_cb(false, DENY, 'Invalid bounce (spoofed sender)');
          Severity: Major
          Found in plugins/bounce.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return next(DENY, `bounce with invalid Message-ID, I didn't send it.`);
            Severity: Major
            Found in plugins/bounce.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return next(DENY, `bounce without Message-ID in headers, unable to verify that I sent it`);
              Severity: Major
              Found in plugins/bounce.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return next();
                Severity: Major
                Found in plugins/bounce.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return next(DENY, `bounce Message-ID without valid domain, I didn't send it.`);
                  Severity: Major
                  Found in plugins/bounce.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        return next(DENY, 'this bounce message does not have 1 recipient');
                    Severity: Major
                    Found in plugins/bounce.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              if (!this.cfg.reject.non_local_msgid) return next();
                      Severity: Major
                      Found in plugins/bounce.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            if (!this.cfg.reject.single_recipient) return next();
                        Severity: Major
                        Found in plugins/bounce.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                              if (!this.cfg.reject.bounce_spf) return run_cb();
                          Severity: Major
                          Found in plugins/bounce.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                return next(DENY, 'bounce with non-empty Return-Path (RFC 3834)');
                            Severity: Major
                            Found in plugins/bounce.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                      return next();
                              Severity: Major
                              Found in plugins/bounce.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                    return next();
                                Severity: Major
                                Found in plugins/bounce.js - About 30 mins to fix

                                  Function single_recipient has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  exports.single_recipient = function (next, connection) {
                                      if (!this?.cfg?.check?.single_recipient) return next();
                                      if (!this?.has_null_sender(connection)) return next();
                                      const { transaction, relaying, remote } = connection;
                                  
                                  
                                  Severity: Minor
                                  Found in plugins/bounce.js - About 25 mins to fix

                                  Cognitive Complexity

                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                  A method's cognitive complexity is based on a few simple rules:

                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                  • Code is considered more complex for each "break in the linear flow of the code"
                                  • Code is considered more complex when "flow breaking structures are nested"

                                  Further reading

                                  Function bad_rcpt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  exports.bad_rcpt = function (next, connection) {
                                      if (!this.cfg.check.bad_rcpt) return next();
                                      if (!this.has_null_sender(connection)) return next();
                                      if (!this.cfg.invalid_addrs) return next();
                                  
                                  
                                  Severity: Minor
                                  Found in plugins/bounce.js - About 25 mins to fix

                                  Cognitive Complexity

                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                  A method's cognitive complexity is based on a few simple rules:

                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                  • Code is considered more complex for each "break in the linear flow of the code"
                                  • Code is considered more complex when "flow breaking structures are nested"

                                  Further reading

                                  Function find_received_headers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  function find_received_headers (ips, body, connection, self) {
                                      if (!body) return;
                                      let match;
                                      while ((match = received_re.exec(body.bodytext))) {
                                          const ip = match[1];
                                  Severity: Minor
                                  Found in plugins/bounce.js - About 25 mins to fix

                                  Cognitive Complexity

                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                  A method's cognitive complexity is based on a few simple rules:

                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                  • Code is considered more complex for each "break in the linear flow of the code"
                                  • Code is considered more complex when "flow breaking structures are nested"

                                  Further reading

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                      if (domains.length === 0) {
                                          connection.loginfo(this, 'no domain(s) parsed from Message-ID headers');
                                          transaction.results.add(this, { fail: 'Message-ID parseable' });
                                          if (!this.cfg.reject.non_local_msgid) return next();
                                          return next(DENY, `bounce with invalid Message-ID, I didn't send it.`);
                                  Severity: Major
                                  Found in plugins/bounce.js and 1 other location - About 2 hrs to fix
                                  plugins/bounce.js on lines 223..228

                                  Duplicated Code

                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                  Tuning

                                  This issue has a mass of 75.

                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                  Refactorings

                                  Further Reading

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                      if (!matches.length) {
                                          connection.loginfo(this, 'no Message-ID matches');
                                          transaction.results.add(this, { fail: 'Message-ID' });
                                          if (!this.cfg.reject.non_local_msgid) return next();
                                          return next(DENY, `bounce without Message-ID in headers, unable to verify that I sent it`);
                                  Severity: Major
                                  Found in plugins/bounce.js and 1 other location - About 2 hrs to fix
                                  plugins/bounce.js on lines 237..242

                                  Duplicated Code

                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                  Tuning

                                  This issue has a mass of 75.

                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                  Refactorings

                                  Further Reading

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                      for (let i=0,l=body.children.length; i < l; i++) {
                                          // Recurse in any MIME children
                                          find_received_headers(ips, body.children[i], connection, self);
                                      }
                                  Severity: Major
                                  Found in plugins/bounce.js and 1 other location - About 1 hr to fix
                                  plugins/bounce.js on lines 192..195

                                  Duplicated Code

                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                  Tuning

                                  This issue has a mass of 56.

                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                  Refactorings

                                  Further Reading

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                      for (let i=0,l=body.children.length; i < l; i++) {
                                          // Recure to any MIME children
                                          find_message_id_headers(headers, body.children[i], connection, self);
                                      }
                                  Severity: Major
                                  Found in plugins/bounce.js and 1 other location - About 1 hr to fix
                                  plugins/bounce.js on lines 284..287

                                  Duplicated Code

                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                  Tuning

                                  This issue has a mass of 56.

                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                  Refactorings

                                  Further Reading

                                  There are no issues that match your filters.

                                  Category
                                  Status