---
title: "An XSS comment on raw HTML: trace the data before you sanitize | Proofline"
description: "Decide by where the string comes from and which context it lands in."
url: https://proofline.sh/learn/ai-review-xss-comment/
---

[Learning center](/learn/)

# An XSS comment on raw HTML: trace the data before you sanitize

Decide by where the string comes from and which context it lands in. Text your framework escapes on output needs no change; a raw-HTML escape hatch fed by users or third parties needs a sanitizer, and data inside a <script> tag needs escaping for that context even when your own repository wrote it.

Code review The Proofline team November 22, 2026 4 min read

## Find the escape hatch and the data behind it

Modern frameworks escape by default. React renders `{value}` as text, and "By default in Django, every template automatically escapes the output of every variable tag." [Django automatic HTML escaping](https://docs.djangoproject.com/en/stable/ref/templates/language/#automatic-html-escaping) An XSS comment is worth reading closely only where code steps around that default: React's `dangerouslySetInnerHTML`, the DOM's `innerHTML`, Django's `|safe` filter or a Jinja environment with autoescaping off.

React's documentation states the condition plainly: "If the HTML inside isn't trusted (for example, if it's based on user data), you risk introducing an XSS vulnerability." [React `dangerouslySetInnerHTML`](https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html) So the first question is the data's origin, and the second is the context. OWASP notes that "The appropriate protection depends on how the data is used": user-authored HTML needs "a maintained HTML sanitizer", while text placed in a context that interprets syntax needs that context's encoding. [OWASP XSS Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#xss-defense-philosophy) [MDN on `innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#security_considerations) gives the same warning for the DOM API.

## JSON-LD written from repository files

In April 2026, a pull request to vLLM's recipes site added structured data for search engines. Each recipe page rendered a JSON-LD block with `dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}`, filled from the recipe's title, description and provider. Two AI reviewers flagged it.

Gemini Code Assist wrote: "Injecting JSON-LD using `dangerouslySetInnerHTML` without escaping can lead to Cross-Site Scripting (XSS)" "if any field in the metadata (like the title or description) contains a closing `</script>` tag." It then named the data's origin itself: "Although the data currently comes from the repository, it is a security best practice to escape the JSON string" "to prevent potential injection from malicious contributions." [Gemini's comment](https://github.com/vllm-project/recipes/pull/397#discussion_r3144687507) Codex added a comment titled "Escape JSON-LD before injecting into script tag": "`JSON.stringify(jsonLd)` is injected with `dangerouslySetInnerHTML` without escaping `<`," "so any recipe field containing `</script>` can terminate the JSON-LD block and execute arbitrary JS." [Codex's comment](https://github.com/vllm-project/recipes/pull/397#discussion_r3144690752)

The pull request merged on 27 April 2026 without a reply or a change. [Pull request](https://github.com/vllm-project/recipes/pull/397)

Both comments were technically right about the context. `JSON.stringify` escapes quotes and backslashes for JSON, but leaves `<` alone, and the HTML parser ends a script element at `</script>` whatever JSON thinks. In Node:

```
> JSON.stringify({ name: "a</script>b" })
'{"name":"a</script>b"}'
> JSON.stringify({ name: "a</script>b" }).replace(/</g, "\\u003c")
'{"name":"a\\u003c/script>b"}'
```

The escaped form parses back to the same string, so the structured data is unchanged. Next.js's JSON-LD guide recommends exactly this replacement, noting that `JSON.stringify` "does not sanitize malicious strings used in XSS injection". [Next.js JSON-LD](https://nextjs.org/docs/app/guides/json-ld)

The origin lowers the severity without changing the fix. The recipe data comes from YAML files under `models/` in the same repository, loaded with `js-yaml`. A malicious title has to get through a pull request review first. The risk was a careless or hostile contribution, and the practical failure was more likely a broken page than an attack on readers.

The project made the change later anyway. A pull request merged on 15 September 2026 added a `jsonLdScript` helper that applies `.replace(/</g, "\\u003c")`, with a comment that "a stray `</script>` inside a stringified value would break the document." [Later pull request](https://github.com/vllm-project/recipes/pull/980) The escape is one line, it fixes correctness as well as security, and it keeps working if the data later comes from somewhere less reviewed. Reviewers sometimes suggest a sanitizer here, but a sanitizer suits HTML fragments, not JSON inside a script element, where it would strip or mangle data instead of escaping it.

## Dismiss when the framework escapes it

The common false positive is a comment on ordinary interpolation, `<p>{comment.body}</p>` in React or `{{ comment.body }}` in a Django template. Both escape on output, so the reply can cite the framework's documentation and close the thread. Escaping does not cover a URL's scheme, though: a user-supplied `href` or `src` can still carry `javascript:`, and OWASP lists unvalidated URL values among the gaps frameworks leave, so check the scheme before dismissing a comment on one. [OWASP framework security](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#framework-security) If you are unsure, render a value containing `<b>` and look at the page: escaped output shows the tag as text.

The opposite case needs no debate. HTML from users, from a CMS, from a third-party API or from a model's output, written through `dangerouslySetInnerHTML`, `innerHTML` or `|safe`, needs a maintained sanitizer such as DOMPurify at the point of rendering, or a change to render it as text.

## Decide from origin and context

| What is rendered | Evidence to check | Response |
| --- | --- | --- |
| A value through the framework's default escaping | The template or JSX renders it as text | Dismiss, citing the framework |
| HTML from users, a CMS, an external API or a model | Where the string is produced | Change: sanitize it, or render it as text |
| Data inside a `<script>` tag, such as JSON-LD | Whether `<` is escaped | Change: escape `<` as `\u003c`, whatever the origin |
| HTML built by your own code from escaped parts | Every interpolation inside the builder | Test with `<b>` in each input, then dismiss or fix |
| Repository-authored HTML, such as rendered Markdown docs | Who can merge content | Dismiss with the trust boundary, or sanitize if contributions are open |

When the reviewer's suggested fix does not suit the context, such as a sanitizer for JSON, accept the finding and use the right fix. The [guide to accepted findings](/learn/reconstruct-accepted-review-finding/) covers how to record a finding that was right with a different fix.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Does this SQL injection comment point at query text or a bound value?](/learn/ai-review-sql-injection-comment/)
    
    Code review The Proofline team November 22, 2026 5 min read
    
-   ### [Trace an accepted code review finding to the lines it changed](/learn/reconstruct-accepted-review-finding/)
    
    Code review The Proofline team November 20, 2026 3 min read
