Skip to content

fix(template): allow title attribute on span in sanitizer policy - #8305

Open
heavry wants to merge 1 commit into
gogs:mainfrom
heavry:fix/tooltip-sanitizer-policy
Open

heavry wants to merge 1 commit into
gogs:mainfrom
heavry:fix/tooltip-sanitizer-policy

Conversation

@heavry

@heavry heavry commented May 30, 2026

Copy link
Copy Markdown

Fixes #8277

Problem

The TimeSince function generates <span class="time-since" title="..."> elements to display date tooltips on hover. However, the template sanitizer uses bluemonday.UGCPolicy() which strips the title attribute from span elements. This causes the tooltip to silently disappear in issue views where the output passes through the Sanitize template function.

Solution

Create a custom sanitizer policy that extends UGCPolicy with AllowAttrs("title").OnElements("span"). This preserves the date tooltip while keeping all other sanitization rules intact.

The title attribute on span is safe. It carries only the formatted timestamp that TimeSince already generates from trusted internal data, not from user input.

The TimeSince function generates <span title=...> elements for date
tooltips, but bluemonday's UGCPolicy strips the title attribute. This
causes the tooltip over time-since strings (e.g. "3 weeks later") to
not appear in issue views.

Create a custom sanitizer policy that extends UGCPolicy to allow the
title attribute on span elements.

Fixes gogs#8277
@heavry
heavry requested a review from unknwon as a code owner May 30, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tooltip over issues "3 weeks later" does not appear

1 participant