Skip to content

Fix local skill-command import on the host - #79

Draft
salim4n wants to merge 1 commit into
devfrom
fix/63-skills-import-host
Draft

salim4n wants to merge 1 commit into
devfrom
fix/63-skills-import-host

Conversation

@salim4n

@salim4n salim4n commented Nov 16, 2026

Copy link
Copy Markdown
Member

Closes #63

Problem

On local mode, POST /api/skills/import ran npx/npm on the host. The MCP tool cogitator_import_skills could trigger that, including after a prompt injection. Archives kept symbolic links, /api/browser/agent trusted conversationId from the JSON body, subagent front matter was unquoted, and spawn prompt files used default permissions (0644).

Fix

  • Command import is allowed only for a human UI request (browser Origin matching Host). MCP and other non-UI callers get import par commande réservé à une action humaine dans l'interface.
  • cogitator_import_skills rejects npm/npx sources before HTTP; description no longer offers a CLI command. The Agents UI has an explicit command mode.
  • npm/npx always get --ignore-scripts and npm_config_ignore_scripts=true, and run with cwd in the skills destination (not the Cogitator install).
  • Tar extract and skill copy refuse symbolic links.
  • Browser agent identity is the owner-transport header x-cogitator-conversation-id (from the process env). A body conversationId is ignored.
  • Subagent YAML scalars are JSON-quoted. Prompt files are written mode 0600.

Proof: exploit tests fail on dev, pass on this branch

Command:

npx tsx --test test/host-skill-import-security.test.ts

On dev (10 fail / 0 pass)

not ok 1 - MCP / appel sans origine navigateur : npx/npm refusé en local et n'exécute pas de script
  actual: 'commande exécutée mais aucun skill nouveau détecté'

not ok 2 - outil MCP : la source commande est refusée avant tout appel HTTP
  (description still advertised npx CLI import)

not ok 3 - UI humaine (Origin du panneau) : commande possible, scripts npm ignorés
  actual: true   # preinstall marker was written

not ok 4 - runSkillCommand force --ignore-scripts : un preinstall ne s'exécute pas
  actual: true   # preinstall marker was written

not ok 5 - importSkills refuse une source commande sans autorisation humaine
  actual: 'commande exécutée mais aucun skill nouveau détecté'

not ok 6 - extraction d'archive : un lien symbolique est refusé et n'est pas recopié
  actual: ''     # import succeeded; no error

not ok 7 - importFromDir refuse un skill qui contient un lien symbolique
  Missing expected exception.

not ok 8 - conversationId du corps est ignoré : l'identité agent vient de l'en-tête du transport
  # body conversationId was used; forged id listed the other agent's profile

not ok 9 - front-matter des subagents est échappé (pas d'injection de clés YAML)
  description: ok" kind: injected ---

not ok 10 - fichier de prompt spawn écrit en 0600
  420 !== 384    # 0o644 vs 0o600

# tests 10
# pass 0
# fail 10

On this branch (10 pass / 0 fail)

ok 1 - MCP / appel sans origine navigateur : npx/npm refusé en local et n'exécute pas de script
ok 2 - outil MCP : la source commande est refusée avant tout appel HTTP
ok 3 - UI humaine (Origin du panneau) : commande possible, scripts npm ignorés
ok 4 - runSkillCommand force --ignore-scripts : un preinstall ne s'exécute pas
ok 5 - importSkills refuse une source commande sans autorisation humaine
ok 6 - extraction d'archive : un lien symbolique est refusé et n'est pas recopié
ok 7 - importFromDir refuse un skill qui contient un lien symbolique
ok 8 - conversationId du corps est ignoré : l'identité agent vient de l'en-tête du transport
ok 9 - front-matter des subagents est échappé (pas d'injection de clés YAML)
ok 10 - fichier de prompt spawn écrit en 0600
# tests 10
# pass 10
# fail 0

Targeted suite + typecheck / build

npx tsx --test test/host-skill-import-security.test.ts test/skills-import.test.ts test/m1.test.ts test/i18n.test.ts
# tests 38
# pass 38
# fail 0

npm run typecheck
# tsc --noEmit && tsc --noEmit -p web  (exit 0)

npm run build
# typecheck + vite build + tsc  (exit 0)

No project lint script.

Pre-existing failures (same 4 as dev, none added)

Same environment, npx tsx --test test/*.test.ts:

tests pass fail
dev 439 427 4
this branch 449 437 4

The extra 10 tests are the new exploit cases (all passing). The four remaining failures are unchanged:

  • cloneRepo : reprise par forme d'URL équivalente, refus d'une vraie autre source (M2, critère 10)
  • folder picker explains an empty root and retains a named add action
  • subagent panel: loading, model/status, visible refresh failure, explicit retry and recovery in both languages
  • subagent panel: changing conversations or closing aborts requests and ignores late responses

(Issue #55 / PR #70 territory; not touched here.)

Draft PRs #65–#74 were not modified. No push to dev, no deploy.

Open in Web Open in Cursor 

Command npm/npx imports are limited to a browser Origin request, never the MCP import tool. npm/npx always run with --ignore-scripts, archive and skill copies reject symbolic links, browser agent identity is taken from the owner transport header, subagent front matter is quoted, and spawn prompt files are created mode 0600.

Co-authored-by: Salim <salim4n@users.noreply.github.com>
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.

Sécurité (mode local) : l'import de skills exécute npx/npm sur l'hôte

2 participants