Overwrite variable content javascript

后端 未结 2 1167
南笙
南笙 2021-01-27 17:52

If you have a variable set with sensitive data:

var secretPassword = \'myPa$sW0rd\';

and you overwrite it:

secretPassword = \'0         


        
相关标签:
2条回答
  • 2021-01-27 18:09

    Try to use an array of fixed size and assign 0 values to all elements on clean-up. This does not reallocate a new object.

    However, it will be difficult to control where the value is passed around once you use it as a string.

    0 讨论(0)
  • 2021-01-27 18:27

    Does a javascript engine allocate new memory for the new data?

    yes

    is the data myPa$sW0rd potentially somewhere in unallocated memory still?

    yes if no garbage collection cleaned it up

    My main question is this: is there a way to guarantee that you overwrite the data? (ie zero it out or securely delete the data).

    Not really, except if you play with the garbage collector. See related post

    I wonder if looping through the characters in the string and resetting them that way would do it.

    No

    Edit : As pointed out by doldt, there is no real security threat even if the previous data is still somewhere in memory.

    0 讨论(0)
提交回复
热议问题