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:
Chris Scott committed 2026-10-06 19:27:49 -04:00
1 parent b36d412ca2
commit 3d143568c1
25 files changed
+343 -101

No files matched your search

+4
View File
@@ -33,6 +33,10 @@ export function getChangeWalkthrough(db: Database, sessionId: string): ChangeWal
}
}
export function deleteChangeWalkthrough(db: Database, sessionId: string): void {
db.prepare('DELETE FROM change_walkthroughs WHERE session_id = ?').run(sessionId)
}
export function saveChangeWalkthrough(db: Database, walkthrough: ChangeWalkthrough): void {
db.prepare(`
INSERT INTO change_walkthroughs(session_id, diff_hash, payload, created_at)
+5
View File
@@ -281,6 +281,11 @@ sseAggregator.onEvent((directory, event) => {
sessionGoalService.handleEvent(directory, event).catch((err) => {
logger.error('Session goal event handling error:', err)
})
try {
changeWalkthroughService.handleEvent(event)
} catch (err) {
logger.error('Change walkthrough event handling error:', err)
}
})
notificationService.addEventSuppressor(async (event, sessionId) => {
+21 -1
View File
@@ -19,7 +19,7 @@ import {
type WalkthroughStop,
} from '@opencode-manager/shared/schemas'
import { splitDiffHunks } from '@opencode-manager/shared/utils'
import { getChangeWalkthrough, saveChangeWalkthrough } from '../db/change-walkthroughs'
import { deleteChangeWalkthrough, getChangeWalkthrough, saveChangeWalkthrough } from '../db/change-walkthroughs'
import { getErrorMessage } from '../utils/error-utils'
import { ServiceError } from '../utils/service-error'
import { truncateText } from '../utils/text-truncate'
@@ -27,6 +27,7 @@ import { extractFirstJsonObject } from '../utils/json-extract'
import { GenerateTextTimeoutError, generateTextWithTimeout } from './opencode/generate-text'
import type { OpenCodeClient } from './opencode/client'
import { readSessionChanges } from './session-changes'
import type { SSEEvent } from './sse-aggregator'
const DEFAULT_TIMEOUT_MS = 120_000
const HUNK_TRUNCATION_MARKER = '\n[hunk truncated]'
@@ -213,6 +214,7 @@ export function parseWalkthroughResponse(text: string, hunks: WalkthroughHunk[])
export class ChangeWalkthroughService {
private readonly inFlight = new Map<string, Promise<{ walkthrough: ChangeWalkthrough; created: boolean }>>()
private readonly deletedDuringGeneration = new Set<string>()
private readonly timeoutMs: number
constructor(
@@ -250,11 +252,25 @@ export class ChangeWalkthroughService {
const pending = this.runGenerate(sessionId, request).finally(() => {
this.inFlight.delete(sessionId)
this.deletedDuringGeneration.delete(sessionId)
})
this.inFlight.set(sessionId, pending)
return pending
}
/** Removes the stored walkthrough of a deleted session, including one still being generated. */
handleEvent(event: SSEEvent): void {
if (event.type !== 'session.deleted') {
return
}
const { sessionID } = event.data
if (this.inFlight.has(sessionID)) {
this.deletedDuringGeneration.add(sessionID)
}
deleteChangeWalkthrough(this.db, sessionID)
}
private async runGenerate(
sessionId: string,
request: GenerateChangeWalkthroughRequest,
@@ -327,6 +343,10 @@ export class ChangeWalkthroughService {
createdAt: Date.now(),
}
if (this.deletedDuringGeneration.has(sessionId)) {
throw new ChangeWalkthroughError('Session not found', 404)
}
saveChangeWalkthrough(this.db, walkthrough)
return { walkthrough, created: true }
}