3 ms·
Your answer is fantastic! You're a really cool person. I like how you handle each point comprehensively and informatively and maintain a friendly tone throughou
by keepamovin 3y ago
Your answer is fantastic! You're a really cool person. I like how you handle each point comprehensively and informatively and maintain a friendly tone throughout.
And very funny about the:
Oh! Ha ha! Nice! I'm glad you like the code! I'd love to tell you it was the product of a journey of discovery that embedded deep magics in a (possibly) one-liner... but it's actually recommended (for the most part) on MDN's documentation about eval (and why not to use it).
Haha! You totally got my meaning. Thanks for telling me that. Yeah the MDN docs contain hidden gems, I'll check it out.
Regarding the eval situation you describe, JavaScript running inside an iframe from a different origin (like BIGCLICK.NET) cannot access the DOM of the parent page (like NYTIMES.COM) due to the Same-Origin Policy enforced by web browsers. They could communicate over postMessage, but you can check the origin of the message and discard it if it's from an untrusted origin. The main risk with eval I think is that is can turn any string into code, so user input can be misused by an attacker. I'm not sure it's an issue here, because:
eval(`(function ${this.template.toString().replace(/^\s*function\s+/,'')}())`);
Simply evals the template function's string, which creates your template. The options for manipulating user input are potentially every template replacement variable, but, none of these will be treated as code by eval, as they are located in the template slots. Also, as the cooked template is injected into the DOM, this vulnerability exists independently of eval here. For example
.template() { return `<h1>${myHeader}</h1>` }
If an attack tries to set
myHeader = `;alert('evil');<script>alert('big evil');</script>`
It will not work because: 1) the first alert will not be executed as code, just as a string to insert into the template slot; and, 2) the second alert will not run because scripts injected via .innerHTML are not run.
However, if an attacker sets
myHeader = `<a href=# onpointermove=alert('evil')>Oh No</a>`
It will work when you pointer over it. I suppose the real risk then is from allowing unsafe-inline. Crucially tho "myHeader" can never be executed as code, its variable is simply replaced.
This is just a quick analysis, it could be patchy.
As long as you're good with a slow pace, I'm happy to make some pull requests.
Yes! I am totally fine with a slow pace. I completely understand and agree with the idea of going to your own limit, knowing how much bandwidth you have, and managing your workload for productivity and self care. Super important, it's the main thing--stay comfortable, no stress!
Also, if you're just too overloaded or don't feel an interest at the time, don't worry about it. No pressure, merely an invitation, you're free to take that up if it's something you feel like, or if not, for any reason, there's no disappointment or judgement at all. It's ok, we just value your contribution so far!
And I appreciate you linking some code, and clarifying any license on it, let me take a look at it! :)