Skip to content

hasCookieHeader works only when Cookie header is set as the last property of headers #3205

@syusui-s

Description

@syusui-s

hasCookieHeader in on-user-script-xhr.js hold the boolean value indicates whether the headers contains Cookie.

However, this variable holds true only if the Cookie is the last property of headers because the hascookieHeader will be overwritten with the new value for each loop.

Solution

In order to solve this problem, we can change the code like this:

  let hasCookieHeader = false;
  if (d.headers) {
    for (let prop in d.headers) {
      if (Object.prototype.hasOwnProperty.call(d.headers, prop)) {
        let propLower = prop.toLowerCase();
-        hasCookieHeader = (propLower === 'cookie');
+       hasCookieHeader ||= (propLower === 'cookie');
        if (gHeadersToReplace.includes(propLower)) {
          xhr.setRequestHeader(gDummyHeaderPrefix + propLower, d.headers[prop]);
        }
        else {
          xhr.setRequestHeader(prop, d.headers[prop]);
        }
      }
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions