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.

2
  • 1
    "[...] after a successful XSS attack" you have bigger problems than whatever you're trying to solve here. It's like... "they might nuke us, so how do we handle the foot soldiers?" Commented Mar 11, 2021 at 12:52
  • You are right, but sometimes you don't have control over everything. Commented Mar 11, 2021 at 14:06

1 Answer 1

1

make it immutable:

const send = XMLHttpRequest.prototype.send; delete XMLHttpRequest.prototype.send; Object.defineProperty(XMLHttpRequest.prototype, 'send', {value: send}); 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! That's looking promising. As an extra step, the XMLHttpRequest itself could be done as read-only.
what if someone managed to mutate it in the runtime prior to execution of this code?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.