0

Is there a way to prevent the intercepting of XHR requests from the global scope (like here)?

First, that comes to mind, pass XMLHttpRequest as a parameter to the application entry function (or IIFE) and make requests based on that copy (e.g. JQuery has an option for a custom XHR object). Is it reliable? Or there are other ways to intercept requests without altering XMLHttpRequest?

The concern is to handle a case when after a successful XSS attack, an attacker can intercept requests and steal the JWT from a header.

Ievgen Martynov
  • 7,870
  • 8
  • 36
  • 52

1 Answers1

1

make it immutable:

const send = XMLHttpRequest.prototype.send;
delete XMLHttpRequest.prototype.send;
Object.defineProperty(XMLHttpRequest.prototype, 'send', {value: send});
n--
  • 3,563
  • 4
  • 9