Bug report: Javascript prototyping can destroy the whole app

When adding prototype functions to the preloaded javascript, the content of the function can end up nuking the whole app.

How to reproduce:

  1. Add any amount of elements to the app;
  2. Add the following code to the Preloaded Javascript tab:
Object.prototype.nuke = function() {
  const keys = Object.keys(this);
  for (let i = 0; i < keys.length; i++) {
    this[keys[i]]; // this nukes it
  }
}
  1. Release a new version;
  2. Open the new version and see that every element is gone;
  3. Press the edit button on the app page and see that there are no elements to be edited, making the app completely blank.

About the code, what I noticed after some trial and error is that, when accessing the this element via a keyed array (keys[i]) is when the bug happens.

Another way to reproduce it is by doing the following:

function nuke() {
  const keys = Object.keys(this);
  for (let i = 0; i < keys.length; i++) {
    this[keys[i]];
  }
}

Object.prototype.nuke = nuke;

Workaround
Instead of using a prototyped function, simply make a function and give it, as an argument, what would be the this element.

function wontNuke(obj) {
  const keys = Object.keys(obj);
  for (let i = 0; i < keys.length; i++) {
    obj[keys[i]]; // Won't nuke
  }
}

Which leads me to believe that there might be something going wrong with how prototyped functions are getting parsed or how they are being interpreted.

Video demonstration: Bug demonstration

Hey @pvpscript! Thank you for the incredibly clear and thorough bug report (and workaround). I was able to reproduce the issue (good and bad news I suppose :sweat_smile: ) and filed an internal report.

I really appreciate all the effort you put into sharing this with us and hopefully we can get this addressed soon.

1 Like