mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
fix: sanitize rendered markdown HTML
Add a shared rehype pipeline (rehype-raw -> rehype-sanitize -> rehype-highlight) to every markdown renderer so scripts, frames and event handlers are stripped from model output and repository files while safe HTML and highlighting survive. Also delete change walkthroughs when their session is deleted (including in-flight generation), build schedule model options from default/favorite/recent state, and include 127.0.0.1 origins in the default trusted origins.
This commit is contained in:
1 parent
b36d412ca2
commit
3d143568c1
25 files changed
+343
-101
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MarkdownRenderer } from './MarkdownRenderer'
|
||||
|
||||
describe('MarkdownRenderer', () => {
|
||||
it('toggles a task list item in the source content', () => {
|
||||
const onContentChange = vi.fn()
|
||||
render(<MarkdownRenderer content={'- [ ] first\n- [x] second'} onContentChange={onContentChange} />)
|
||||
|
||||
const [first, second] = screen.getAllByRole('checkbox')
|
||||
expect(first).not.toBeChecked()
|
||||
expect(first).toBeEnabled()
|
||||
expect(second).toBeChecked()
|
||||
|
||||
fireEvent.click(first!)
|
||||
expect(onContentChange).toHaveBeenCalledWith('- [x] first\n- [x] second')
|
||||
})
|
||||
|
||||
it('strips unsafe raw HTML from a repository file and keeps safe HTML', () => {
|
||||
const { container } = render(
|
||||
<MarkdownRenderer
|
||||
content={'# Readme\n\n<script>document.documentElement.dataset.fileProbe = 1</script>\n\n<p align="center"><img src="docs/logo.png" alt="Logo"></p>'}
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(container.querySelector('script')).toBeNull()
|
||||
expect(document.documentElement.dataset.fileProbe).toBeUndefined()
|
||||
expect(screen.getByAltText('Logo')).toHaveAttribute('src', 'docs/logo.png')
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,8 @@
|
||||
import { memo, useMemo, useCallback } from 'react'
|
||||
import ReactMarkdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import rehypeHighlight from 'rehype-highlight'
|
||||
import rehypeRaw from 'rehype-raw'
|
||||
import { markdownComponents } from './MarkdownComponents'
|
||||
import { markdownRehypePlugins } from '@/lib/markdownRehypePlugins'
|
||||
import { MarkdownLink } from '@/components/ui/markdown-link'
|
||||
import { resolvePathFromFile } from '@/lib/markdownLinks'
|
||||
import type { Components } from 'react-markdown'
|
||||
@@ -95,7 +94,7 @@ export const MarkdownRenderer = memo(function MarkdownRenderer({ content, classN
|
||||
<div className={`pb-[200px] p-4 prose prose-invert prose-enhanced max-w-none text-foreground overflow-hidden break-words leading-snug ${className}`}>
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
rehypePlugins={[rehypeHighlight, rehypeRaw]}
|
||||
rehypePlugins={markdownRehypePlugins}
|
||||
components={components}
|
||||
>
|
||||
{content}
|
||||
|
||||
Reference in new issue
Block a user