Automattic / knox

S3 Lib
MIT License
1.74k stars 285 forks source link

auth: canonicalizeResource crashed on CentOS 7 #269

Closed abernardobr closed 9 years ago

abernardobr commented 9 years ago

Using:

Parsing a URL w/o any query string on CentOS, returns url.query: null and not url.query: {}.

By calling url.query crashes since it was expecting at least an empty object and now it is null.

exports.canonicalizeResource = function(resource){
  var url = parse(resource, true)
    , path = url.pathname
    , buf = [];

  // apply the query string whitelist
  Object.keys(url.query).forEach(function (key) {
      if (whitelist.indexOf(key) != -1) {
          buf.push(key + (url.query[key] ? "=" + url.query[key] : ''));
      }
  });

  return path + (buf.length
    ? '?' + buf.sort().join('&')
    : '');
};

possible fix:

exports.canonicalizeResource = function(resource){
  var url = parse(resource, true)
    , path = url.pathname
    , buf = [];

  url.query = url.query == null ? {} : url.query;

  // apply the query string whitelist
  Object.keys(url.query).forEach(function (key) {
      if (whitelist.indexOf(key) != -1) {
          buf.push(key + (url.query[key] ? "=" + url.query[key] : ''));
      }
  });

  return path + (buf.length
    ? '?' + buf.sort().join('&')
    : '');
};
domenic commented 9 years ago

Dupe of #250, #251, #252, #253, #256.