Black Box Driven Development in JavaScript
hacks.mozilla.org
hacks.mozilla.org
for(var i=0; i<products.length; i++) {
content += products[i].name + '<br />';
}
$('.content').html(content);
Use a template library, do not concatenate strings and then just set HTML. Most template libraries will have safeguards in place to prevent XSS vulnerabilities. Even if the product name is always trusted to be non-malicious, it's still a dangerous anti-pattern.XSS will eat your lunch. It breaks every safeguard there is, it even defeats 2 factor auth and lets the attacker adopt the identity and privileges of whoever has been exposed to the attack. It's prudent to be extra careful and never have code that looks like this.
var products = window.localStorage.getItem('products') || [], content = '';
If an attacker can set a localStorage value then they can already run JS making this entire attack vector completely superfluous. In order for your claimed attack to work someone has to have already conducted a XSS.It is like talking about the risks of XSS within locally set cookies. It might technically be true but how do you set the cookie in order to later run the JS taken back out of it? Same issue here. How do you set the localstorage to give you back the JS to commit XSS, more XSS?
Of course it could be possible that the 'name' value is HTML and not TEXT and has already been pre-escaped. :)
Regardless of whether this is exploitable XSS or not this is probably a correctness issue. Stuff shouldn't start breaking when people start inputting '<' somewhere.
You bring the word twice in your article ,so no need for that "BBDD" expression.
var Box = function(a, b) {};
as opposed to the simpler: function Box(a, b) {}
makes no sense. It is more verbose for zero benefit and makes all functions anonymous so you will never see that it is the Box function being called in your debuggers and profilers. If you want to enforce functions being declared before they are called, use JSLint (which you should be doing anyway.) var MyProject = {};
MyProject.func = function() {}
If you ever want to assign a function to an object, you might as well do it with global-scope functions. Most debuggers/profilers I am aware of can handle this notation well. If they don't, there is still the possibility of doing var Box = function Box (a, b) {}
The function does not have to be anonymous! var Box = (a, b) => {};
I guess I just think that the more verbose form is more readable.It would be great if you mentioned what works with browserify, webpack, gulp etc..
I'm not sure what percentage of front-end developers still just link a bunch on JS files in the HTML.
http://en.wikipedia.org/wiki/Composition_over_inheritance
The take away part in the article is this: "... so there is no way to produce collisions."
$(document).ready(application.init());
I think you meant to say: $(document).ready(application.init);