mardi 21 septembre 2021

intercept / proxy window.postMessage

In my app, we are using a third party analytics library, which, apart from other things, is also using postMessage to post some info to the parent window (possibly for iframe use cases for the analytics library).

In our case, this info is sensitive and we do not want to send it to parent window (if our app is opened in an iframe or as a child window by someone) as we wouldn't have any control over what the parent window does with this information (even for valid parents). There is no configuration in the library to switch off this functionality.

As a potential solution, we figured out that if we can intercept all postMessages being sent out to the parent window and just filter this message , it would solve our purpose for now. To achieve this, I have been looking at proxying window.postMessage or redefining the method for adding this validation.

I am just trying to understand if this is feasible, and how?

  • is it possible from the current window to override the parentWindow.postMessage (or for that matter, override a childWindow.postMessage?)

Aucun commentaire:

Enregistrer un commentaire