fix(pages): escape head tag attributes and show descriptions as text - #720
Merged
Merged
Conversation
The description, canonical, Open Graph, Twitter card and alternate-link tags were built with Wicket's MetaDataHeaderItem, which does not HTML-escape attribute values: it only backslash-escapes double quotes, which HTML does not honour. Values taken from nanopublications, such as a space's description, a user's name or a page title, were therefore not safely contained in their attributes. The tags are now written by a helper that escapes every attribute value for HTML. Meta descriptions are also reduced to plain text before they are shortened: many descriptions are HTML, which search results and link previews showed as raw markup. Markup is removed with the OWASP sanitizer already in use, entities are decoded, and block boundaries are kept as spaces. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Problem
The head tags added for search engines and link previews (#704) and the RDF alternate links (#710) were built with Wicket's
MetaDataHeaderItem. It does not HTML-escape attribute values: it only replaces"with\", which HTML does not treat as an escape. Values taken from nanopublications (a space's description, a user's name, a page title) were therefore not safely contained in their attributes.It also showed up visibly: descriptions are often HTML, and the space page of SEMIC 2026 carried
<span>…<strong>\"…\"</strong>…in itsdescription,og:descriptionandtwitter:description, so search results and link previews would show raw markup.Fix
NanodashPage.headTagwrites themetaandlinktags itself and escapes every attribute value withStrings.escapeMarkup(",',<,>,&). It replacesMetaDataHeaderItemfor the description, canonical, Open Graph and Twitter card tags, and for therel="alternate"RDF links. The tag format is unchanged, so the existing metadata tests pass as they were.setMetaDescriptionnow reduces a description to plain text before the existing one-line and 300-character treatment: markup is removed with the OWASP sanitizer already used byUtils.sanitizeHtml(script contents included), entities are decoded, and block boundaries (p,br,li, …) become spaces so paragraphs do not run together.The embedded JSON-LD block was already safe (every
<is written as<), and<title>goes through Wicket's normal label escaping.Tests
NanodashPageMetadataTestgains 8 tests:description,og:descriptionandtwitter:descriptionall hold the escaped text.headTagescaping of each character, a null value, and odd name/value pairs.Full suite: 1420 tests, 0 failures.
🤖 Generated with Claude Code