Skip to content

Code breaks when algorithm=MD5 key value pair occurs in response headers #15

Open

Description

@himanshu219

Sometimes some apis give algorithm=MD5 in the response headers without quotes which breaks the code with below traceback.

// console output of parts array
realm="MMS Public API"
 domain=""
 nonce="7hziqlF0xTs4PbKVmzPlEGq0yZRNiFuY"
 algorithm=MD5
/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:107
      if (part.length > 2) {
               ^

TypeError: Cannot read property 'length' of null
    at HTTPDigest.parseChallenge [as _parseChallenge] (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:107:16)
    at HTTPDigest.handleResponse [as _handleResponse] (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:39:26)
    at ClientRequest.<anonymous> (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:29:12)
    at Object.onceWrapper (events.js:285:13)
    at ClientRequest.emit (events.js:197:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:560:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:113:17)
    at TLSSocket.socketOnData (_http_client.js:447:20)
    at TLSSocket.emit (events.js:197:13)
    at addChunk (_stream_readable.js:288:12)

at line number 106 using the following regex fixes the issue
var part = parts[i].match(/^\s*?([a-zA-Z0-0]+)="(.)"\s?$|^\s*?([a-zA-Z0-0]+)=(.)\s?$/);

Activity

  1. ma0dubois commented on Aug 3, 2021

    @ma0dubois

    Hi,

    @himanshu219 i think it's better to use this:

    var part = parts[i].match(/^\s*?([a-zA-Z0-0]+)="?(.*)"?\s*?$/);
    if (part && part.length > 2) {
        params[part[1]] = (part[2]).replace('"', '');
    }

    because with your suggestion, the group 1 and 2 can be undefined if the regex match your 2nd group

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions