Skip to content

Sanitize markdown output in edit history and TOC edit views - #392

Merged
djmb merged 1 commit into
mainfrom
sanitize-edit-history-xss
Mar 18, 2026
Merged

Sanitize markdown output in edit history and TOC edit views#392
djmb merged 1 commit into
mainfrom
sanitize-edit-history-xss

Conversation

@djmb

@djmb djmb commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

The edit history view and TOC edit partial render Markdown content via to_html without passing through sanitize_content(), unlike the normal page view. This allows stored XSS via img onerror payloads for anyone who can view the edit history of a page with injected content.

Apply sanitize_content() consistently to all to_html output, matching the existing safe pattern in leafables/show.html.erb.

The edit history view and TOC edit partial render Markdown content via
to_html without passing through sanitize_content(), unlike the normal
page view. This allows stored XSS via img onerror payloads for anyone
who can view the edit history of a page with injected content.

Apply sanitize_content() consistently to all to_html output, matching
the existing safe pattern in leafables/show.html.erb.
Copilot AI review requested due to automatic review settings March 18, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens page rendering against XSS by sanitizing HTML output for page bodies, including in the edit history view and page thumbnails, and adds regression tests to verify dangerous attributes are stripped.

Changes:

  • Sanitize rendered HTML for both “previous version” and “current” page bodies in the page edit history view.
  • Sanitize rendered HTML for page thumbnails in the leaves edit partial.
  • Add controller/integration tests ensuring dangerous attributes (e.g., onerror) are removed from rendered output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
app/views/pages/edits/show.html.erb Sanitizes HTML output for both the selected edit’s page body and the current page body.
app/views/leaves/_edit.html.erb Sanitizes page-body HTML used in the leaf thumbnail preview.
test/controllers/pages/edits_controller_test.rb Adds tests covering sanitization for previous and current versions.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@djmb
djmb merged commit 01791b2 into main Mar 18, 2026
11 checks passed
@djmb
djmb deleted the sanitize-edit-history-xss branch March 18, 2026 14:59
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.

2 participants