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
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-07-04 - XSS Prevention via Sandboxed Iframe in Email Preview
**Vulnerability:** Email preview rendered using `dangerouslySetInnerHTML`.
**Learning:** Even with DOMPurify, rendering dynamic HTML directly into the DOM can lead to XSS or styling clashes. Using an `iframe` with `srcDoc` and a `sandbox` attribute (`allow-popups allow-popups-to-escape-sandbox`) provides true isolation without needing a separate endpoint.
**Prevention:** For untrusted or complex HTML previews, default to sandboxed iframes. Manually inject necessary styles into the `srcDoc` to ensure correct rendering.
28 changes: 26 additions & 2 deletions components/accounts/ppp-savings-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,32 @@ export function PppSavingsPanel({ orgSlug, accountId }: PppSavingsPanelProps) {
)}
</div>
</div>
<div className="min-h-[24rem] w-full overflow-auto bg-white p-6 text-sm text-black">
<div dangerouslySetInnerHTML={{ __html: sanitizedEmailHtml }} />
<div className="flex min-h-[24rem] w-full bg-white text-sm text-black">
<iframe
title="Email Preview"
className="w-full border-none h-full"
sandbox="allow-popups allow-popups-to-escape-sandbox"
srcDoc={`
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
padding: 1.5rem;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
background-color: #fff;
}
</style>
</head>
<body>
${sanitizedEmailHtml}
</body>
</html>
`}
/>
</div>
</div>
</div>
Expand Down
Loading