r/javascript • • Aug 27 '16

Is your JavaScript function actually pure?

http://staltz.com/is-your-javascript-function-actually-pure.html
8 Upvotes

48 comments sorted by

View all comments

2

u/[deleted] Aug 29 '16

Like everyone else, at first I thought he was just being pedantic about the word "pure." But as I read through it, it just reminded me of why I'm not 100% sold on JS and would love to have some type of safer environment (WASM?).

Consider the security implications of what he mentions. You can overwrite, and make crazy, any function call(incl. prototypes) available to the global scope. I mean this is stuff that any JS programmer knows, but doesn't want to think too deeply about.

It is most certainly the type of vector that any XSS could use to do all sorts of nasty stuff. You could write all your code correctly, avoid the global scope like the plague, sanitize inputs, and still someone could use what he is describing here to inject an undesirable function directly into the middle of your code... Just because you assumed a string literal was safe -- to read.

(I know... Why was foreign JS allowed in the first place? That is another issue... [Chrome extension, social engineering, JS console, etc?])