{
  "schema": "aidefend-secureflow-metadata-v1",
  "flow_id": "aidefend-research-sf0086-pgedge-mcp-sql-readonly-approval-bypasses",
  "title": "pgEdge MCP: SQL Injection, Read-Only Bypass and Missing Write Approval",
  "subtitle": "Four advisories expose different gaps between a tool call, an approval prompt and PostgreSQL authority.",
  "summary": "pgEdge disclosed independent SQL-injection, read-only-enforcement and bundled-client approval defects affecting versions through 1.0.0 and repaired in 1.1.0. A custom pl-do tool could turn argument data into SQL; query_database could defeat an application-level read-only setting; two client defects skipped write confirmation. Database permissions still bound the resulting actions. The source establishes controlled validation, not a malicious customer breach.",
  "reviewed": true,
  "import_status": "curated-research",
  "ai_layers": [
    "tool-integrations-mcp"
  ],
  "risk_impact": [
    "data-corruption"
  ],
  "affected_components": [
    "Custom pl-do argument interpolation",
    "query_database protocol and transaction state",
    "Bundled CLI and web approval logic",
    "PostgreSQL connecting role and connection pool"
  ],
  "source_research": {
    "provider": "pgEdge",
    "primary_url": "https://github.com/pgEdge/pgedge-postgres-mcp/security/advisories/GHSA-r5pp-jx86-r6r9",
    "published": "2026-11-11",
    "note": "The four paths have different prerequisites. Client confirmation is not server-enforced authorization; no prompt-injection delivery or malicious exploitation is assumed."
  },
  "attack_steps": [
    {
      "id": "argument",
      "title": "Submit arguments to a custom pl-do tool",
      "zhTitle": "向自訂 pl-do 工具提交參數",
      "summary": "A caller reaches a configured pl-do tool and supplies JSON containing a delimiter used by the SQL wrapper.",
      "zhSummary": "呼叫者存取已設定的 pl-do 工具，並提交含 SQL 包裝所用分隔符號的 JSON。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 0,
        "y": 0
      }
    },
    {
      "id": "interpolate",
      "title": "Escape the outer DO delimiter",
      "zhTitle": "越過外層 DO 分隔符號",
      "summary": "An argument containing the fixed outer delimiter can terminate the wrapper and introduce SQL, including transaction control.",
      "zhSummary": "含有固定外層分隔符號的參數，可以結束包裝區塊並插入 SQL，包含交易控制。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 650,
        "y": -700
      }
    },
    {
      "id": "inner-argument",
      "title": "Escape the inner argument delimiter",
      "zhTitle": "越過內層參數分隔符號",
      "summary": "A separate input uses the fixed argument delimiter to change executable PL/pgSQL inside the DO block.",
      "zhSummary": "另一種輸入利用固定參數分隔符號，改變 DO 區塊內可執行的 PL/pgSQL。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 650,
        "y": 700
      }
    },
    {
      "id": "sql-effect",
      "title": "Execute SQL with the connecting role",
      "zhTitle": "以資料庫連線角色執行 SQL",
      "summary": "The SQL runs with the server connection’s database rights; outer-delimiter injection can also carry transaction control.",
      "zhSummary": "SQL 以伺服器連線的資料庫權限執行；外層分隔符號注入還可能夾帶交易控制。",
      "tactic": "AML.TA0005",
      "technique": "AML.T0050",
      "layout": {
        "x": 1950,
        "y": 0
      }
    },
    {
      "id": "readonly-call",
      "title": "Call query_database on a read-only connection",
      "zhTitle": "呼叫設定為唯讀的 query_database",
      "summary": "The application marks the connection read-only, but its underlying PostgreSQL role can write.",
      "zhSummary": "應用程式把連線標為唯讀，但底層 PostgreSQL 角色仍有寫入權限。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 0,
        "y": 2800
      }
    },
    {
      "id": "smuggle",
      "title": "Pass transaction-changing SQL through the guard",
      "zhTitle": "讓改變交易狀態的 SQL 通過檢查",
      "summary": "Incomplete SQL inspection and the simple-query execution path allow transaction changes and multiple statements.",
      "zhSummary": "SQL 檢查不完整，加上簡單查詢協定的執行路徑，讓交易變更與多個陳述式通過。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 650,
        "y": 2100
      }
    },
    {
      "id": "write-now",
      "title": "Modify data despite the application setting",
      "zhTitle": "繞過應用程式設定修改資料",
      "summary": "The controlled reproduction creates, alters and drops tables. It does not exceed the connecting role’s PostgreSQL permissions.",
      "zhSummary": "受控重現能建立、變更及刪除資料表，但仍未超出連線角色的 PostgreSQL 權限。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 1300,
        "y": 2100
      }
    },
    {
      "id": "reset-pool",
      "title": "Clear a pooled connection’s read-only default",
      "zhTitle": "清除連線池內連線的唯讀預設值",
      "summary": "A separate session-reset route clears default_transaction_read_only; vulnerable pool handling preserves the changed state.",
      "zhSummary": "另一條路徑藉由重設工作階段清除 default_transaction_read_only；有漏洞的連線池處理會保留變更後的狀態。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 650,
        "y": 3500
      }
    },
    {
      "id": "later-write",
      "title": "Reuse the writable pooled connection",
      "zhTitle": "重用已可寫入的連線",
      "summary": "Later calls, including calls under another token, can inherit the writable session state when that connection is reused.",
      "zhSummary": "該連線被再次取用時，後續呼叫，包括使用其他 token 的呼叫，可能沿用可寫入狀態。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 1300,
        "y": 3500
      }
    },
    {
      "id": "query-proposal",
      "title": "Propose a query whose leading keyword appears read-only",
      "zhTitle": "提出開頭看似唯讀的查詢",
      "summary": "With writes enabled, the bundled client receives a query using SELECT INTO, a data-modifying CTE or EXPLAIN ANALYZE.",
      "zhSummary": "啟用寫入後，內附用戶端收到使用 SELECT INTO、會修改資料的 CTE，或 EXPLAIN ANALYZE 的查詢。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 0,
        "y": 4900
      }
    },
    {
      "id": "query-no-prompt",
      "title": "Skip query confirmation",
      "zhTitle": "略過查詢確認",
      "summary": "First-keyword classification treats the query as a read and skips the intended write prompt.",
      "zhSummary": "第一個關鍵字的分類方式把查詢當成讀取，因此略過原定的寫入確認。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 650,
        "y": 4900
      }
    },
    {
      "id": "query-write",
      "title": "Run the write-capable query",
      "zhTitle": "執行會寫入的查詢",
      "summary": "The server executes the query on a connection already permitted to write.",
      "zhSummary": "伺服器在原本就允許寫入的連線上執行查詢。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 1300,
        "y": 4900
      }
    },
    {
      "id": "custom-proposal",
      "title": "Invoke a write-capable custom tool",
      "zhTitle": "呼叫可寫入的自訂工具",
      "summary": "The operator has configured a custom sql, pl-func or pl-do tool with write effects.",
      "zhSummary": "管理者已設定具有寫入效果的自訂 sql、pl-func 或 pl-do 工具。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 0,
        "y": 6300
      }
    },
    {
      "id": "custom-no-prompt",
      "title": "Bypass the client’s query-only prompt check",
      "zhTitle": "避開僅檢查內建查詢的確認邏輯",
      "summary": "The bundled client checks only the query_database tool name, leaving the custom call without write confirmation.",
      "zhSummary": "內附用戶端只檢查 query_database 工具名稱，因此沒有對自訂呼叫要求寫入確認。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 650,
        "y": 6300
      }
    },
    {
      "id": "custom-write",
      "title": "Perform the custom tool’s configured write",
      "zhTitle": "執行自訂工具原有的寫入操作",
      "summary": "The call performs the write operation built into that tool; this path does not itself supply arbitrary SQL injection.",
      "zhSummary": "呼叫執行該工具原本設定的寫入操作；這條路徑本身不會產生任意 SQL 注入。",
      "tactic": null,
      "technique": null,
      "layout": {
        "x": 1300,
        "y": 6300
      }
    }
  ],
  "threat_refs": [
    {
      "id": "AML.T0050",
      "name": "Command and Scripting Interpreter"
    }
  ],
  "reader_narrative": {
    "pathCount": 6,
    "topologyNote": "Four independent advisory families; Path A has alternative outer/inner delimiter routes; Path B has an alternative pooled-session route. No line asserts that one family causes the next.",
    "groups": [
      {
        "id": "pldo",
        "kind": "path",
        "eyebrow": "Path A",
        "label": "Custom-tool SQL injection",
        "summary": "Argument data crosses a code boundary.",
        "stepIds": [
          "argument",
          "interpolate",
          "inner-argument",
          "sql-effect"
        ]
      },
      {
        "id": "readonly",
        "kind": "path",
        "eyebrow": "Path B",
        "label": "Read-only enforcement bypass",
        "summary": "Immediate SQL writes and conditional later pool reuse are alternatives.",
        "stepIds": [
          "readonly-call",
          "smuggle",
          "write-now",
          "reset-pool",
          "later-write"
        ]
      },
      {
        "id": "query",
        "kind": "path",
        "eyebrow": "Path C",
        "label": "Query confirmation skipped",
        "summary": "Writes are already enabled; the missing boundary is user confirmation.",
        "stepIds": [
          "query-proposal",
          "query-no-prompt",
          "query-write"
        ]
      },
      {
        "id": "custom",
        "kind": "path",
        "eyebrow": "Path D",
        "label": "Custom-tool confirmation skipped",
        "summary": "A configured write-capable tool falls outside the client name check.",
        "stepIds": [
          "custom-proposal",
          "custom-no-prompt",
          "custom-write"
        ]
      }
    ]
  }
}
