Make changing engine-run code superuser-only

Writing node source, installing modules and any flow save that adds,
retypes or repoints a code node (Function, Command), edits a Command
node's settings or changes a node's resources.env now answer 403 for
everyone but a superuser. MCP tools and the assistant reach the same
routes, so they inherit the gate. Node types report runs_code.

The editor shows code read-only with a note, disables a Command node's
settings, leaves code nodes and reusable nodes out of the palette and
paste, and the Modules page offers no install.
This commit is contained in:
2026-10-06 11:36:30 +02:00
parent 2914d860b1
commit 6802cd2203
19 changed files with 391 additions and 26 deletions
+42 -5
View File
@@ -42,6 +42,7 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import useAuth from "@/hooks/useAuth"
import useCustomToast from "@/hooks/useCustomToast"
import { useIsMobile } from "@/hooks/useMobile"
import { scaleIn } from "@/lib/motion"
@@ -367,6 +368,22 @@ function FlowEditorInner({
[nodeTypeInfo],
)
// Which types run code of their own, a source or a command. Adding one is a
// superuser's, so nobody else is offered one.
const { user } = useAuth()
const mayEditCode = Boolean(user?.is_superuser)
const lockedTypes = useMemo(
() =>
new Set(
mayEditCode
? []
: (nodeTypeInfo ?? [])
.filter((info) => info.runs_code)
.map((info) => info.type),
),
[nodeTypeInfo, mayEditCode],
)
// Which types came from an installed connector rather than the engine. They
// cannot be in the icon map, so they share one.
const pluginTypes = useMemo(
@@ -1042,9 +1059,18 @@ function FlowEditorInner({
return
}
// A node that runs code is a superuser's to add, so anyone else pastes
// the rest without it.
const nodes = (clipboard.nodes ?? []).filter(
(node) => !lockedTypes.has(node.type ?? "python"),
)
if (nodes.length < (clipboard.nodes ?? []).length) {
notify("Only a superuser can add nodes that run code.", "error")
}
let pool = definitions
const pasted: NodeDef_Input[] = []
for (const node of clipboard.nodes ?? []) {
for (const node of nodes) {
const copy = { ...node, id: uniqueNodeId(pool, node.id) }
pool = [...pool, copy]
pasted.push(copy)
@@ -1063,13 +1089,20 @@ function FlowEditorInner({
commit(pool)
setSelectedId(pasted[pasted.length - 1].id)
clipboard.nodes.forEach((node, index) => {
nodes.forEach((node, index) => {
const code = clipboard.sources?.[node.id]
if (code !== undefined) {
sourceMutation.mutate({ nodeId: pasted[index].id, code })
}
})
}, [canvasNodes, commit, definitions, setCanvasNodes, sourceMutation.mutate])
}, [
canvasNodes,
commit,
definitions,
lockedTypes,
setCanvasNodes,
sourceMutation.mutate,
])
useShortcuts(
{
@@ -1335,10 +1368,14 @@ function FlowEditorInner({
<CommandPalette
open={paletteOpen}
onOpenChange={setPaletteOpen}
nodeTypes={nodeTypeInfo ?? []}
nodeTypes={(nodeTypeInfo ?? []).filter(
(info) => !lockedTypes.has(info.type),
)}
flows={flows.data}
onAddNode={addNode}
onAddSharedNode={(libName) => addNode("python", libName)}
onAddSharedNode={
mayEditCode ? (libName) => addNode("python", libName) : undefined
}
onRun={startRun}
/>