Security · 4 min read · 957 words

XSS in Plain English: The CVE Type That Still Ships

By Chris Clark · AppSec practitioner & AWS Solutions Architect

Disclosure: Some links in this article are affiliate links. We may earn a commission at no extra cost to you if you purchase through them.

XSS in Plain English: The CVE Type That Still Ships

Cross-site scripting (XSS) is not a mysterious "CVE flavor." It is what happens when untrusted data gets treated as code in a browser. Someone's name, a search term, a comment, or a URL fragment ends up in a place where the browser runs it as JavaScript. The attacker does not need to break your server. They need your app to render their payload into another user's session.

OWASP folds XSS into A03:2021 Injection because the root failure is the same as SQL injection: data and commands got mixed. The difference is the interpreter. For XSS, the interpreter is the browser.

Three shapes, one bug

People still talk about three XSS shapes. The names help triage; the fix pattern is shared. Reflected XSS. The payload rides in the request and echoes back in the response. Think a search page that prints You searched for: without encoding. Stored XSS. The payload is saved and later shown to other users. A profile bio or support ticket note is the classic case. One bad write becomes many victims. DOM-based XSS. The server may never see the payload. JavaScript on the page reads something attacker-controlled (location.hash, postMessage, local storage) and writes it into an unsafe sink like innerHTML. Your Spring controller can be clean and the Angular app still opens the door.

If you only scan server templates, you will miss the third shape.

What "encode the output" actually means

The OWASP XSS Prevention Cheat Sheet is blunt: no single control stops XSS. You need the right encoding for the context where the data lands.

Wrong context encoding is a common "we fixed XSS" failure. An interceptor that HTML-encodes every request parameter still fails when that same string lands in a script block or event handler.

Spring Boot and Angular: where the defaults help — and where they stop

Spring Security will not auto-encode your Thymeleaf variables in every context, but it gives you useful response headers. Modern Spring Security defaults X-XS-Protection to 0 because the old browser XSS filter is deprecated. Relying on that header was never a real program. What Spring does support well is shipping a Content Security Policy (CSP) header — a rule set that tells the browser what scripts it can run. Spring's own docs say CSP reduces harm; it does not replace validate-and-encode as the first line of defense. See the Spring Security HTTP headers guide. Angular treats values as untrusted by default when you bind them through templates. Interpolation and most bindings get sanitized. The escapes are APIs you reach for when you "just need raw HTML": bypassSecurityTrustHtml, bypassSecurityTrustUrl, and friends. Those are intentional holes. The Angular security guide warns against building templates from concatenated user input and against treating direct DOM APIs as safe. Framework protection is real until someone opts out of it.

In a Spring Boot API + Angular SPA layout, XSS often lives on the client: a REST field that was never meant to be HTML gets bound with [innerHTML], or a deep-link hash is copied into the DOM.

CSP: useful seatbelt, bad airbag

A Content Security Policy tells the browser which scripts, styles, and resources a page may load. MDN's CSP guide frames it as defense in depth: you still sanitize and encode; CSP limits how bad a miss becomes.

A strict CSP uses nonces (one-time tokens) or hashes for scripts rather than a giant host allowlist. Allowlists rot, grow, and often include something that can host an attacker payload. Start with Content-Security-Policy-Report-Only so you see breaks before you enforce.

CSP with 'unsafe-inline' and 'unsafe-eval' is theater. If your policy allows arbitrary inline script, you paid the complexity cost and kept the XSS door open.

What to do in a Java / Spring / Angular / GitLab CI shop

  • Prefer framework-safe sinks. Angular interpolation over [innerHTML]. textContent over innerHTML in custom JS. Thymeleaf's default escaping over string-concatenated HTML.
  • Treat every bypassSecurityTrust* and th:utext as a review item. Require a ticket comment: what was sanitized, with which library, who owns the allowlist.
  • Encode at render time, in the right context. Do not "clean" input once and assume every future use is safe. Data moves; contexts change.
  • Add CSP as a second control, configured in Spring Security headers, with report-only first. Pair with cookie flags (HttpOnly, Secure, SameSite) so a successful XSS steals less.
  • Wire detection into your pipeline. GitLab SAST and DAST will not catch every DOM sink, but they catch the boring reflected cases and keep regressions visible. Fail the job on high-confidence XSS rules the same way you fail on secret leaks.
  • Test the rich-text path separately. If marketing needs HTML, sanitize with a maintained library and re-test after every upgrade. Sanitizers get bypasses; unpatched sanitizers are just delayed XSS.
  • The short version

    XSS means the browser ran an attacker's string as code in your origin. Fix it by keeping data out of code contexts: context-aware output encoding, careful sanitization when HTML is required, framework defaults you do not casually bypass, and CSP as backup — not as the plan. In a Spring Boot and Angular stack, most modern XSS is someone opting out of those defaults or writing to the DOM by hand.

    Close those exits on purpose.

    Tags: XSS · cybersecurity · web-security · CVE · injection-attacks