Skip to content

fix(preview): sandbox markdown, links, and media for prompt previews (#244) - #252

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Prompt-Hash-Stellar:mainfrom
s6pa1rta3n-lab:fix-issue-244
Draft

fix(preview): sandbox markdown, links, and media for prompt previews (#244)#252
s6pa1rta3n-lab wants to merge 1 commit into
Prompt-Hash-Stellar:mainfrom
s6pa1rta3n-lab:fix-issue-244

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Description

Resolves #244 by implementing client-side and server-side preview sanitization, sandboxed markdown and media rendering, and layout constraint protections across prompt previews.

Changes

  • Client-Side Preview Sandboxing (src/components/MarkdownContent.tsx):
    • Enforced strict rehype-sanitize schema disallowing unsafe tags (script, style, iframe, embed, object, form, etc.).
    • Added pre-parser tag sanitizer (stripDangerousRawTags) to prevent raw HTML block absorption from hiding adjacent content.
    • Neutralized unsafe URI protocols (javascript:, data:, vbscript:, file:) by rendering inert fallback elements.
    • Restricted external hyperlinks to safe protocols (http, https, mailto) with mandatory target="_blank" and rel="noopener noreferrer nofollow".
    • Sandboxed images with max-w-full, max-h-96, lazy loading (loading="lazy"), async decoding, and suppressed tracking pixels (1x1 dimensions or tracking beacon URLs).
    • Constrained layout via break-words and [overflow-wrap:anywhere] on containers to prevent horizontal overflows.
    • Implemented length budget limiting with visual truncation indicator.
  • Form and Detail Container Containment (PromptDetailPage.tsx, CreatePromptForm.tsx):
    • Applied break-words [overflow-wrap:anywhere] to preview text and overflow-hidden to preview containers.
    • Added length constraint budget on live seller description previews.
  • Server-Side Sanitization Utility (server/src/utils/previewSanitizer.ts):
    • Added sanitizePreviewText for stripping HTML tags, scripts, tracking beacons, and markdown images/links to construct safe plain-text preview snippets.
    • Added sanitizePreviewMarkdown for neutralizing scripts, frames, inline handlers, and unsafe protocols while preserving valid markdown formatting.
    • Integrated sanitizePreviewText into indexPromptProjection in server/src/services/promptSearchIndex.ts.
  • Test Suites:
    • Frontend Vitest suite in src/components/MarkdownContent.test.tsx (18 tests) covering XSS payloads, unsafe link schemes, embedded frames, tracking pixels, layout breaking text, and length limits.
    • Backend Jest suite in server/src/tests/previewSanitization.test.ts (17 tests) covering script neutralization, event handler removal, tracking pixel detection, length budgets, and search projection indexing.

Verification

  • Frontend Vitest suite: 44 test files passed, 352 tests passed.
  • Server Jest suite: 22 test files passed, 209 tests passed.
  • Frontend build (vite build): Succeeded without errors.

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

…rompt-Hash-Stellar#244)

- Enhance MarkdownContent component with strict rehype-sanitize schema disallowing unsafe tags
- Strip dangerous raw script, iframe, embed, and object tags prior to markdown parsing
- Restrict links to safe protocols (http, https, mailto) and enforce target="_blank" with rel="noopener noreferrer nofollow"
- Restrict images to safe protocols, enforce lazy loading and responsive max-dimensions, and suppress tracking pixels
- Prevent layout breaking by applying break-words and overflow-wrap anywhere across prompt detail and form preview containers
- Enforce length budget with preview truncation indicator
- Implement server-side preview and search index sanitization utility
- Add comprehensive frontend and backend regression test suites
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.

Prompt content previews need sandboxing for markdown, links, and embedded media

1 participant