ProtectJS icon indicating copy to clipboard operation
ProtectJS copied to clipboard

Cant protect prototype and instances together.

Open PedroUrday opened this issue 8 years ago • 3 comments

ProtectJS can not protect the prototype and all of its instances at the same time. When protect prototype and an instance separately, the prototypes methods can access the instance protected attributes. I forked this repository to solve this situation. The fork only contents modified files. Check it.

PedroUrday avatar Jan 07 '17 20:01 PedroUrday

Hi @PedroUrday

I've checked out your fork. Could you give a code example, showing the different objects gaining access?

Thanks!

TremayneChrist avatar Feb 09 '17 16:02 TremayneChrist

Hi @TremayneChrist

When I said "the prototypes methods can access the instance protected attributes", I might say "the public prototype methods of a type can not access to each instance private attributes of the same type". Sorry for the mistake.

Here is an example of the issue:

function MyObject() {
    this._value = "helloworld";
    protect(this);
};

MyObject.prototype.public = function () {
    console.log(this._value);
};

protect(MyObject);

var mo = new MyObject();

mo.public(); // Says undefined and it should says "helloworld" :(

Best regards!

PedroUrday avatar Feb 27 '17 22:02 PedroUrday

Hey @PedroUrday

Confirmed, this definitely needs to be looked at.

Note to self: Look at automatically protecting the constructor and bond both of the protected objects

TremayneChrist avatar Mar 01 '17 11:03 TremayneChrist