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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"framer-motion": "^12.37.0",
"helmet": "^8.1.0",
"ioredis": "^5.10.1",
"isomorphic-dompurify": "^3.7.1",
"jigsawstack": "^0.4.3",
"jotai": "^2.18.1",
"jsonwebtoken": "^9.0.3",
Expand Down
63 changes: 63 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/components/consent/ResearchConsentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from 'react'

import { authClient } from '@/lib/auth-client'
import { consentService } from '@/lib/security/consent/ConsentService'
import DOMPurify from 'isomorphic-dompurify'
import type { UserConsentStatus } from '@/lib/security/consent/types'

interface ResearchConsentFormProps {
Expand Down Expand Up @@ -279,7 +280,7 @@ export function ResearchConsentForm({
<div className='bg-gray-50 border-gray-200 text-gray-700 mt-4 max-h-96 overflow-auto rounded-lg border p-4 text-sm'>
<div
dangerouslySetInnerHTML={{
__html: consentStatus.currentVersion.documentText,
__html: DOMPurify.sanitize(consentStatus.currentVersion.documentText),
}}
></div>
Comment on lines 281 to 285
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DOMPurify.sanitize() is a good fix, but the current usage leaves a couple of sharp edges:

  • Attack-surface reduction: DOMPurify defaults can allow SVG/MathML (historically higher-risk namespaces). For a HIGH-severity XSS fix, it’s better to explicitly restrict to the HTML profile.
  • Render-time work / branching: Sanitizing inline in render (and gating on typeof window) is harder to reason about and can be wasteful for large documents. If this ever renders in a non-browser environment, it will also silently render an empty document.

Consider computing the sanitized HTML once (memoized) and applying a stricter DOMPurify config.

Suggestion

Refactor to sanitize with an explicit HTML-only profile and memoize the result (and avoid silently blanking the document in non-window contexts):

import { useMemo } from 'react'

// ...inside component
const sanitizedDocumentText = useMemo(() => {
  return DOMPurify.sanitize(consentStatus.currentVersion.documentText, {
    USE_PROFILES: { html: true },
  })
}, [consentStatus.currentVersion.documentText])

// ...
<div dangerouslySetInnerHTML={{ __html: sanitizedDocumentText }} />

If you must support SSR/non-DOM execution, prefer an SSR-safe setup (e.g., dynamic import in useEffect, or an isomorphic DOMPurify wrapper) rather than ''.

Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this refactor.

</div>
Expand Down
Loading