The webpages below let you explore the complexities of encoding (aka sanitising) and validating data to prevent XSS, the most notorious way for things to go off the rails in modern web-applications.
The central language here is HTML, but this language involves a range of other languages and technologies, including
All the webpages below are totally self-contained: the required JavaScript code is inlined inside the HTML or uses standard APIs provided by any browser, notably the DOM API. Note that the use of inlined JavaScript is considered bad practice as it makes for a poorly maintainable messy mixture of JavaScript code and HTML content. Still, for these demo webpages it has advantages: you can easily make a copy of this webpage on your local file system, tinker around with it, and then view - and execute - the result in a browser to see the effect.
The webpages listed below contain JavaScript code that mimics the behaviour of a web server. More specifically, the pages micic a web template engine that generates a webpage using a web template. The pages contain form fields to supply parameters to these templates and buttons to generate a webpage by inserting them. The resulting HTML is inserted into the webpage using the DOM API so that it is rendered inside the browser.
Two techniques that we use here are interactively changing a webpage and JavaScript template strings:
The second technique, using document.write(), is more realistic as it demonstrates the effect of what would happen if a real web server would send the HTML payload to the browser (as then scripts in the HTML are executed). Still, the first technique, using innerHTML, is useful as it allows you to inspect the HTML that is rendered without execution of scripts.
WARNING: Both techniques are terribly insecure and error-prone ways to interactive modify a webpage. Normally you would steer clear of using them, but for the demos here they are useful.
In the JavaScript code we make extensive use of JavaScript template strings. These strings, written between back-quotes, can contain both single and double quotes without any escaping. More importantly, string literals support an infix substitution operation, called string interpolation, by including expressions between special brackets ${ }. String literals can span multiple lines, i.e. they can contain newline characters without these having to be escaped, which is useful to keep things readable.