Skip to content
Merged
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
18 changes: 16 additions & 2 deletions server/session-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,22 @@ export function createSessionRouter(
router.get('/api/opencode/models', async (req, res) => {
const token = extractToken(req)
if (!verifyToken(token)) return res.status(401).json({ error: 'Unauthorized' })
const workingDir = (req.query.workingDir as string) || osHomedir()
const result = await fetchOpenCodeModels(workingDir)
const rawDir = (req.query.workingDir as string) || osHomedir()

// Bounds-check: workingDir must be under home or REPOS_ROOT (same as /api/sessions/create)
const home = osHomedir()
const allowedRoots = [home, REPOS_ROOT]
let resolvedDir: string
try {
resolvedDir = fsRealpathSync(pathResolve(rawDir))
} catch {
return res.status(400).json({ error: 'workingDir could not be resolved (path does not exist or is inaccessible)' })
}
if (!allowedRoots.some(root => resolvedDir === root || resolvedDir.startsWith(root + '/'))) {
return res.status(403).json({ error: 'workingDir is outside allowed directories' })
}

const result = await fetchOpenCodeModels(resolvedDir)
res.json(result)
})

Expand Down
6 changes: 6 additions & 0 deletions server/ws-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ const commitEventState: { handler: CommitEventHandler | undefined } = { handler:
// ---------------------------------------------------------------------------
const app = express()

// Trust X-Forwarded-For headers when behind a reverse proxy so that
// req.ip returns the real client IP for rate limiters and logging.
if (TRUST_PROXY) {
app.set('trust proxy', true)
}

// In Docker / standalone mode (FRONTEND_DIST set), the server is reached directly without nginx.
// nginx normally strips the /cc prefix before proxying; we replicate that here so the frontend
// (which hardcodes BASE = '/cc') works against the Node server without modification.
Expand Down
5 changes: 4 additions & 1 deletion src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ function AssistantMessage({ msg, fontSize, variant = 'default', repeatCount }: {
return <a href={safeHref} target="_blank" rel="noopener noreferrer" {...props}>{children}</a>
},
img({ src, alt, ...props }) {
// Only allow https: and data: URIs to prevent tracking beacons and arbitrary protocol access
const safeSrc = src && /^(https:|data:image\/)/i.test(src) ? src : undefined
if (!safeSrc) return <span className="text-neutral-5">[image blocked: untrusted source]</span>
return (
<img
src={src}
src={safeSrc}
alt={alt || 'Image'}
className="max-w-full max-h-96 rounded-lg border border-neutral-8 my-2"
loading="lazy"
Expand Down
Loading