How can I be sure memory is being overwritten - Javascript

前端 未结 3 1172
广开言路
广开言路 2021-01-24 10:56

When loading sensitive information into memory I want to make sure it is securely erased afterwards. I am working on a Javascript web app, and I want to make sure that my variab

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 11:09

    If you want to replace a value then just assign it a different value - what happens to the memory structures in the background is entirely obfuscated from the developer so there is no way to tell what happens (unless the code is open-source and you want to go rummaging around the innards) and whether it is consistent in every browser (doubtful) or whether it is handled securely (short of poking the memory yourself at run-time, again doubtful) but for a scalar value then it "should" not be re-allocating memory so assigning a different value may be sufficient.

    If you want to delete a reference to an attribute of an object in JavaScript then you can use:

    var x = { data: 'here', other_stuff: 'there' };
    // do stuff
    delete x.data; // remove the data attribute from the x object.
    // do more stuff
    delete x; // remove the x attribute from the current scope.
    

    In this case - the delete keyword has nothing to do with memory management; instead, it just removes properties from objects so they can't be referenced. If all references to an object are removed then the object will be scheduled for garbage collection and the memory may be freed but you have no control over this process.

    Basically, if you want security for (de-)allocating/overwriting memory then don't use JavaScript.

提交回复
热议问题