News for hackers. Stuff that matters.
Re:Show HN: Enlight – Learn to code by building projects by warent on Sunday December 10, 2017 @02:30PM (#15893050)
The [nodejs chat application](https://tryenlight.github.io/nodejs-chat) should at least briefly run through the perils of XSS and ways to sanitize inputs. The chat app lets you inject arbitrary javascript/html/css which noobs may not consider at all.

Otherwise, great idea! Should help a lot of people

Re:Show HN: Enlight – Learn to code by building projects by mncolinlee on Monday December 11, 2017 @03:42AM (#15895859)

  There once was a coder from Texas
  Who browsed websites on his Nexus.
  He used Dev Console
  Exploited a loophole
  And found a bevy of XSS.
Re:Show HN: Enlight – Learn to code by building projects by shamdasani on Sunday December 10, 2017 @02:56PM (#15893190)
Good point - will add something on that soon. I by no means am a professional programmer, just a hobbyist sharing what I've learned.
Re:Show HN: Enlight – Learn to code by building projects by ColinFCodeChef on Sunday December 10, 2017 @04:09PM (#15893514)
The gap between a professional and hobbyist is nowhere near as wide as one might think. Great idea, keep at it.
Re:Show HN: Enlight – Learn to code by building projects by warent on Sunday December 10, 2017 @05:01PM (#15893716)
Unrelated: you joined >400 days ago and this appears to be your first post? Cool!
Re:Show HN: Enlight – Learn to code by building projects by s4vi0r on Sunday December 10, 2017 @03:10PM (#15893249)
Why the `var`s everywhere in the example? They should really be `const`s
Re:Show HN: Enlight – Learn to code by building projects by inimino on Sunday December 10, 2017 @06:25PM (#15894073)
`var` still works everywhere, right?
Re:Show HN: Enlight – Learn to code by building projects by akvadrako on Monday December 11, 2017 @05:10AM (#15896130)
Current coding examples should be using the current best practice, which is const. If you want to support old browsers without compiling the JS, you are going to have a lot more issues than const/var and is not for beginners.
Re:Show HN: Enlight – Learn to code by building projects by inimino on Tuesday December 12, 2017 @01:39AM (#15903461)
The difference between `var` and `const` is irrelevant for beginners. `var` also happens to be the standard on deployed browsers and existing code, and every beginner should recognize it. It’s the least substantive thing you could pick to criticize about this code.
Re:Show HN: Enlight – Learn to code by building projects by rapind on Monday December 11, 2017 @03:24PM (#15900099)
It's actually pretty easy to support older browser's without getting into the packaging mess if you don't need a modern framework. Learning webpack is a distraction from learning programming and would overwhelm a lot of the audience IMO.
Re:Show HN: Enlight – Learn to code by building projects by inimino on Sunday December 10, 2017 @06:23PM (#15894068)
Typing `<script>alert(0)</script>` into the chat box shows the injection hazard.

In fact this is caused by using jQuery, which (inexcusably) runs embedded scripts when adding HTML to the page. The simplest solution to this entire class of bugs is simply to not use jQuery and use the better-designed DOM methods instead, which is probably a more modern approach anyway.

Using innerHTML would solve the script injection, but you probably want to use innerText or createTextNode instead, since supporting HTML tags in a basic chat app seems more bug than feature.

The server side should be safe already as it looks like there’s no persistence.

Re:Show HN: Enlight – Learn to code by building projects by shamdasani on Sunday December 10, 2017 @08:23PM (#15894555)
Thanks for the heads up. DOM methods are more clear and better. Will update the tutorial soon.
Re:Show HN: Enlight – Learn to code by building projects by foota on Sunday December 10, 2017 @06:36PM (#15894137)
innerHtml wouldn't eliminate xss vectors though, things like load=something could bypass this.
Re:Show HN: Enlight – Learn to code by building projects by inimino on Tuesday December 12, 2017 @10:10PM (#15911724)
Yes, it's not completely safe. In a beginner tutorial, if you allow arbitrary HTML you should state that it shouldn't be done that way in a real app.
Re:Show HN: Enlight – Learn to code by building projects by hxtk on Sunday December 10, 2017 @11:28PM (#15895162)
Would running inputs through a markdown engine on the server side fix this, assuming it didn't break some other design requirement?
Re:Show HN: Enlight – Learn to code by building projects by girvo on Sunday December 10, 2017 @11:47PM (#15895218)
Markdown allows HTML, though. You have to pick your engine or configuration carefully there, but the idea is sound.