Skip to content

Add Trix Editor and Sanitize Comment HTML#1544

Draft
google-labs-jules[bot] wants to merge 3 commits intomasterfrom
add-trix-editor-with-sanitization
Draft

Add Trix Editor and Sanitize Comment HTML#1544
google-labs-jules[bot] wants to merge 3 commits intomasterfrom
add-trix-editor-with-sanitization

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

This change adds the Trix rich text editor for a better user experience when writing comments. It also adds server-side HTML sanitization to ensure that only a safe subset of HTML is allowed, and all links open in a new tab securely. This prevents XSS attacks and improves security.

This commit introduces the Trix rich text editor for comments and implements server-side HTML sanitization to prevent XSS vulnerabilities.

Key changes:
- Added the `trix` and `loofah` gems.
- Integrated Trix assets into the application.
- Replaced comment text areas with the Trix editor.
- Created a `sanitize_comment` helper to:
  - Whitelist `<strong>`, `<em>`, `<p>`, `<u>`, and `<a>` tags.
  - Add `target="_blank"` and `rel="noopener"` to all links.
  - Strip all other HTML tags and attributes.
- Applied the sanitization helper to all comment views.
link['target'] = '_blank'
end

fragment.to_s.html_safe

Check notice

Code scanning / Rubocop

The use of `html_safe` or `raw` may be a security risk. Note

Rails/OutputSafety: Tagging a string as html safe may be a security risk.
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