MCP run_cypher guard misses a write keyword glued to a number

Aperta Adatta ai principianti
#301 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, typescript

Direzione di ricerca

Leggi src/selfgraph/mcp/server.py attorno a _WRITE_CLAUSE e i relativi test, poi controlla la protezione corrispondente in typescript/src/mcp.ts. Riproduci i casi con valori letterali numerici dell’issue e conferma che entrambe le protezioni li rifiutino con read_only_query, mentre le normali query di sola lettura continuano a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: cli-mcp bug effort: S P1

Summary

The MCP run_cypher tool is meant to be read-only, but a write clause that directly follows a numeric literal, with no space in between, gets past _is_blocked_query. Kuzu still parses the query as two clauses and runs the write. The tool returns an empty result and the store is changed.

Reproduction (Python 0.2.2, Kuzu backend)

from selfgraph.mcp import server as srv

srv._is_blocked_query("MATCH (n:N) WHERE 1=1DELETE n")   # False

await srv.run_cypher("MATCH ()-[r:R]->() WHERE 1=1DELETE r")      # deletes every edge
await srv.run_cypher("MATCH (n:N) WHERE 1=1DELETE n")              # deletes every node
await srv.run_cypher("UNWIND [1] AS x WITH x LIMIT 1CREATE (:N {pk: 'evil', ns: 'x'})")  # creates a node
await srv.run_cypher("MATCH (n:N) WITH n LIMIT 1000SET n.doc = 'x'")    # overwrites every stored doc
await srv.run_cypher("MATCH (n:N) WITH n LIMIT 1000MERGE (:N {pk: 'x'})")

Each call returns {"columns": [], "rows": [], ...}. A count before and after shows the nodes and edges are gone, or the new node exists.

Cause

_WRITE_CLAUSE in src/selfgraph/mcp/server.py:48-53 matches \b(CREATE|...|DELETE|SET|...)\b. A digit and a letter are both word characters, so there is no \b between 1 and DELETE, and the keyword is never matched. Kuzu's lexer ends the integer literal at the digit and reads DELETE as a keyword, and the openCypher grammar allows clauses with no space between them. Any clause that can end in a number works as a carrier: WHERE ... = 1, LIMIT n, SKIP n, WITH ..., 1 AS one LIMIT 1.

This is not the 1. DELETE form from #213. That form does not parse on Kuzu, and this one does.

The TypeScript guard uses the same boundary over PY_WORD_CLASS (typescript/src/mcp.ts:41-47).

Expected

run_cypher rejects these queries with read_only_query.

Suggested fix

Treat a keyword that follows a digit as a separate token. For example, use a lookbehind that rejects only a preceding letter or underscore, or insert a space between a digit run and a following letter before the scan.

Lingua principale
TypeScript
Stelle
173
Fork
58
Merge medio
6h
PR unite (30g)
120

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hydra-db/selfgraph

Tutte le issue di hydra-db/selfgraph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.