🐛 Fixed stored XSS in structured data via unescaped tag names#28957
Closed
swithek wants to merge 1 commit into
Closed
🐛 Fixed stored XSS in structured data via unescaped tag names#28957swithek wants to merge 1 commit into
swithek wants to merge 1 commit into
Conversation
swithek
force-pushed
the
fix/escape-tag-name-xss
branch
from
June 28, 2026 20:26
10d59b7 to
4ac9b64
Compare
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9larsons
force-pushed
the
fix/escape-tag-name-xss
branch
from
July 1, 2026 14:26
4ac9b64 to
6702db4
Compare
no ref - tag names, post keywords and site title were written into the inline JSON-LD <script> via JSON.stringify with no HTML-escaping, letting an editor-set tag name break out of the script and run JS for any visitor - escaped those fields in getTagSchema/getPostSchema/getHomeSchema
swithek
force-pushed
the
fix/escape-tag-name-xss
branch
from
July 1, 2026 14:30
6702db4 to
493fdab
Compare
Contributor
9larsons
added a commit
that referenced
this pull request
Jul 1, 2026
ref #28957 - tag names, post keywords, and the site title were serialized raw into the inline <script type="application/ld+json"> block, letting an Editor-controlled value like `foo</script><script>...` break out of the script element and run arbitrary JS for anonymous visitors on tag and post pages - escapes the breakout-relevant characters (< > U+2028 U+2029) as JSON \u escapes at the single serialization boundary in ghost_head, so every field is covered at once instead of relying on per-field escaping that is easy to forget - removed the per-field escapeExpression calls from schema.js: HTML-entity escaping is the wrong layer here — JSON-LD consumers (Google et al.) parse the block as JSON and never HTML-decode, so it silently corrupted structured data (e.g. `Tom & Jerry` was indexed as `Tom & Jerry`). JSON \u escapes are both safe and lossless, so legitimate `& ' "` now round-trip correctly - added a regression test proving breakout is neutralised while data round-trips, and updated the snapshot/assertions that were capturing the old corruption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tag names, post keywords, and the site title were written into the inline JSON-LD <script type="application/ld+json"> block via JSON.stringify, which doesn't escape </script>. An Editor-controlled tag name like foo</script><script>alert(document.domain)</script> broke out of the script element and executed arbitrary JS for any anonymous visitor on tag and post pages.
Fix
Escape the three affected fields with escapeExpression in getTagSchema, getPostSchema, and getHomeSchema. This is consistent with every other text field in the file (headline, description, author/publisher name), which were already escaped.
Testing
Added regression tests asserting a </script> payload is HTML-escaped in tag, post-keywords, and home schema output.
Updated the existing ghost_head snapshot that was silently capturing the previously-unescaped post keywords.