Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import defaultImg from "../../content/assets/default-blog.webp"
import kebabCase from "lodash/kebabCase"
import Img from "gatsby-image"
import getTimeToRead from "../utils/timeToRead"
import DOMPurify from 'dompurify'; // Import DOMPurify

const Card = ({ node }) => {
const tags = node.frontmatter.tags || ""
Expand Down Expand Up @@ -51,7 +52,7 @@ const Card = ({ node }) => {
</h3>
<p
dangerouslySetInnerHTML={{
__html: descriptionText,
__html: DOMPurify.sanitize(descriptionText), // Sanitize the HTML
}}
/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/pinnedCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Img from "gatsby-image"
import kebabCase from "lodash/kebabCase"
import React from "react"
import ReactGA from "react-ga"
import DOMPurify from "dompurify" // Import DOMPurify
import defaultImg from "../../content/assets/default-blog.webp"
import freeTrialImg from "../../content/assets/freetrial.webp"
import getTimeToRead from "../utils/timeToRead"
Expand Down Expand Up @@ -58,7 +59,7 @@ const PinnedCard = props => {
<p
className={`${styles.descriptiontext} ${styles.pinned}`}
dangerouslySetInnerHTML={{
__html: node.frontmatter.description || node.excerpt,
__html: DOMPurify.sanitize(node.frontmatter.description || node.excerpt), // Sanitize HTML
}}
/>
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/components/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import IdentityTagMenu from "./tagmenu/identity"
import getTimeToRead from "../utils/timeToRead"
import Bio from "./bio"
import ToC from "./toc"
import DOMPurify from 'dompurify';

const eventLogger = function ({ category, action, label }) {
ReactGA.event({
Expand Down Expand Up @@ -88,7 +89,7 @@ const Post = ({ post, relatedPost, type }) => {
}
})

setModifiedHtml(doc.body.innerHTML)
setModifiedHtml(DOMPurify.sanitize(doc.body.innerHTML))
}, [post.html])
const faqJsonData = extractFAQs(post.html)
let faqSchema = {}
Expand Down Expand Up @@ -125,7 +126,7 @@ const Post = ({ post, relatedPost, type }) => {
<p
className={`${headStyles.descriptiontext} ${headStyles.pinned}`}
dangerouslySetInnerHTML={{
__html: post.frontmatter.description || post.excerpt,
__html: DOMPurify.sanitize(post.frontmatter.description || post.excerpt),
}}
/>
</div>
Expand Down Expand Up @@ -185,7 +186,7 @@ const Post = ({ post, relatedPost, type }) => {
{author.id}
</Link>
</h3>
<p dangerouslySetInnerHTML={{ __html: author.bio }}></p>
<p dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(author.bio) }}></p>
</div>
</div>
</div>
Expand Down