PLAIN/TEXT — ISSUE 251/456 COMPUTER SCIENCE · FOUNDATION / SAFE WEB OUTPUT · ~4 MIN READING DATE: 2027-06-09 ARCHIVE: https://plaintext.click/newsletter/ SUBJECT: When does a comment become a browser instruction? When does a comment become a browser instruction? ================================================= / START HERE A comment box should let people publish words without giving them control of another reader’s browser. A browser interprets page instructions as well as displaying ordinary text. A cross-site scripting flaw lets attacker-controlled content run as instructions within a trusted website. The critical boundary is whether supplied data stays data when the page is assembled. / WHY NOW A book review containing angle brackets should remain a review. If the application inserts it into page markup without suitable handling, the browser may treat part of it as page structure or executable code. / THE IDEA HTML is the notation used to describe a webpage’s structure. Some characters have special jobs in it: an opening angle bracket can begin an element. Output encoding replaces characters with representations that display as text in the particular place where they are inserted. Context means that place’s interpretation rules. Text between elements, a quoted attribute, a web address and a script are different contexts. A method suitable for ordinary HTML text is not a general way to make arbitrary script content safe. For plain text, an interface that creates a text node avoids interpreting the supplied value as HTML at all. If rich formatting is genuinely required, sanitization uses an explicit policy to keep permitted markup and remove dangerous features. These are different jobs, not interchangeable spellings of the same operation. / THE FORMAL IDEA untrusted text + intended output context → context-appropriate handling - The arrow means choose the protection matching the browser’s next interpretation step. - A text node is page content treated as characters rather than markup. Sanitization is policy-based removal of unsafe structure, not a guarantee from deleting one suspicious word. / RUN THE TINY EXAMPLE Change one thing. Predict what happens. Review text is excellent. Put it into an ordinary element using textContent → show the angle brackets literally. Change only the insertion method to raw HTML parsing → produce bold formatting. In an HTML template text context, encoding < as < also keeps it from opening an element. The same characters produced different results because the interpretation changed. The harmless formatting example exposes the boundary without needing malicious code. Dangerous instructions become possible when a broader set of browser features is accidentally allowed through the same route. / SO WHAT? A useful review therefore follows data to its final destination. Validating that a review is under 500 characters does not establish that it is safe inside a script. Keep template protections enabled, prefer safe text interfaces and make any rich-content exceptions explicit and testable. / ONE CAVEAT Encoding is context-specific; some contexts should not accept untrusted values at all. Browser security policies can reduce consequences, but do not replace correct handling at the insertion point. / KEEP THIS Text stays harmless when the browser receives it through an interface or encoding that preserves its intended text-only meaning. / SOURCE TRAIL [1] OWASP — Cross Site Scripting Prevention https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html NEXT: Why does a bound nucleus weigh less than its parts? --- HARD IDEAS. PLAIN TEXT. You are receiving this because you asked for one clear computer-science or physics idea each day. Unsubscribe: https://plaintext.click/unsubscribe View in browser: https://plaintext.click/newsletter/2027/06/2027-06-09-xss-context-escaping.html From: Plain/Text / Brickston Consulting · 30 N Gould St Ste N, Sheridan, WY 82801 US · knowledge@plaintext.click