Skip to content

Add DOMPurify sanitization#2

Open
anamwp wants to merge 1 commit intomainfrom
codex/install-and-use-dompurify-for-sanitization
Open

Add DOMPurify sanitization#2
anamwp wants to merge 1 commit intomainfrom
codex/install-and-use-dompurify-for-sanitization

Conversation

@anamwp
Copy link
Copy Markdown
Owner

@anamwp anamwp commented Jul 1, 2025

Summary

  • install dompurify
  • sanitize post and comment HTML
  • sanitize login error output
  • document sanitization step in README

Testing

  • SITE_DOMAIN=example.com npm run lint

https://chatgpt.com/codex/tasks/task_e_686354f4a7ac8328bead2d96edf07e87

Copilot AI review requested due to automatic review settings July 1, 2025 03:28
@vercel
Copy link
Copy Markdown

vercel bot commented Jul 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headless-simple-blog ❌ Failed (Inspect) Jul 1, 2025 3:29am

Copy link
Copy Markdown

Copilot AI left a comment

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 introduces DOMPurify into the codebase to sanitize HTML content in posts, comments, and error messages. It adds the dependency to package.json, updates components to use DOMPurify for sanitization, and documents the sanitization process in the README.

  • Sanitize post content in pages/posts/[slug].js.
  • Sanitize login error messages in components/Login.js.
  • Sanitize comment content and reply messages in components/Comment.js.

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pages/posts/[slug].js Wraps post HTML content with DOMPurify.sanitize
package.json Adds the DOMPurify dependency
components/Login.js Sanitizes error message HTML using DOMPurify
components/Comment.js Sanitizes comment content and reply message HTML
README.md Documents the HTML sanitization process

Comment thread components/Comment.js
if (replyMessageElement) {
replyMessageElement.classList.add('bg-slate-200', 'flex', 'gap-3', 'p-5', 'inline-block', 'w-full', 'rounded');
replyMessageElement.innerHTML = `<strong>Replying to comment:</strong> ${comment.content.rendered}`;
replyMessageElement.innerHTML = `<strong>Replying to comment:</strong> ${DOMPurify.sanitize(comment.content.rendered)}`;
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider centralizing the DOMPurify.sanitize calls in a utility function (e.g., a helper like sanitizeHTML) to reduce duplication and simplify future updates to sanitization behavior.

Suggested change
replyMessageElement.innerHTML = `<strong>Replying to comment:</strong> ${DOMPurify.sanitize(comment.content.rendered)}`;
replyMessageElement.innerHTML = `<strong>Replying to comment:</strong> ${sanitizeHTML(comment.content.rendered)}`;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants