EXERCISE 1 — The root cause of XSS in "data vs code" terms ========================================================== THE ROOT CAUSE (data vs code): A web page is HTML -- a mix of MARKUP (code: tags, scripts, attributes the browser ACTS on) and TEXT (data: content meant only to be DISPLAYED). XSS occurs when untrusted input that should be treated as DATA (just shown to the user) is instead inserted into the page in a position where the browser treats it as CODE (parses and executes it). - The browser parses whatever bytes are in the HTML. It has no idea which characters came from the trusted developer and which from an attacker -- it just follows HTML rules. So if attacker text contains markup like EXECUTES: - The developer wrote a template like:

Hello, NAME

and dropped the raw `name` value into NAME with no encoding. - Intended: name="Philip" ->

Hello, Philip

. Here "Philip" sits in a TEXT position, displayed as data. Fine. - Attack: name="". After substitution the HTML is:

Hello,

- The browser, parsing this HTML, sees a literal " on the page -- as DATA -- and runs nothing. The input stayed data instead of becoming code. That single discipline (encode on output, per context) is the foundation of XSS defence.