Skip to content

Sanitize blog post HTML#34

Open
phucnguyen1707 wants to merge 1 commit into
profullstack:masterfrom
phucnguyen1707:fix-blog-content-sanitizer
Open

Sanitize blog post HTML#34
phucnguyen1707 wants to merge 1 commit into
profullstack:masterfrom
phucnguyen1707:fix-blog-content-sanitizer

Conversation

@phucnguyen1707

Copy link
Copy Markdown

Summary

  • sanitize stored blog HTML before rendering it with dangerouslySetInnerHTML
  • keep common prose tags and safe attributes while blocking scripts, event handlers, and unsafe URL schemes
  • add sanitize-html as an explicit web dependency

Fixes #15

Checks

  • pnpm --filter @c0upons/web run typecheck
  • pnpm --filter @c0upons/web exec eslint 'app/blog/[slug]/page.tsx' lib/sanitize-blog-html.ts
  • pnpm --filter @c0upons/web run build

Note: full app lint still reports pre-existing errors outside this change in about, home, privacy, terms, offline, and api/webhooks/crawlproof.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​sanitize-html@​2.16.11001007081100
Addedsanitize-html@​2.17.510010010094100

View full report

@socket-security

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm entities is 91.0% likely obfuscated

Confidence: 0.91

Location: Package overview

From: pnpm-lock.yamlnpm/@types/sanitize-html@2.16.1npm/sanitize-html@2.17.5npm/entities@4.5.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/entities@4.5.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm htmlparser2 is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: pnpm-lock.yamlnpm/@types/sanitize-html@2.16.1npm/sanitize-html@2.17.5npm/htmlparser2@10.1.0

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/htmlparser2@10.1.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@phucnguyen1707

Copy link
Copy Markdown
Author

Quick note on the Socket advisory comments: they come from sanitize-html's standard parser dependencies (htmlparser2/entities). I kept a maintained sanitizer here rather than a custom parser/regex because this PR is specifically closing an XSS sink. The Socket checks are successful, and I can switch sanitizer approach if you prefer another package.

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.

Bug: Stored XSS via unsanitized dangerouslySetInnerHTML in blog post rendering

1 participant