← MCP server and skill grades

dbhub

bytebase/dbhub

B
Type
MCP server
Scanned
Nov 13, 2026
Version
cc9e3c7ad36b
Files read
307

...Wait—NO! Do not output extra text or markdown fences! Let me output ONLY the raw JSON object.` -> good thing I caught that! Outputting strictly the raw JSON now.{

Findings

4 medium5 low
  1. MediumMySQL and MariaDB '#' comments bypass read-only mode, engine backstop, and explain_sql

    src/utils/sql-parser.ts:233

    MySQL and MariaDB treat '#' as a single-line comment to the end of the line, but none of DBHub's MySQL/MariaDB token scanners recognize '#' comments. Because both connectors also enable multipleStatements: true on every pool connection, a prompt-injected agent can place a single quote after '#' on line 1 and close it inside another '#' comment on line 2 (for example, SELECT 1 # ' followed on the next line by ; COMMIT; SET SESSION TRANSACTION READ WRITE; DROP TABLE users; SELECT 1 # '). DBHub's statement splitter and read-only classifier see everything between the two quotes as one harmless string literal inside a single SELECT, while MySQL and MariaDB ignore the quote inside the '#' comment, end the read-only transaction, re-enable session writes, and execute arbitrary DDL, DML, or LOAD_FILE calls via execute_sql (with readonly = true, including in the Claude Code plugin and MCPB bundle) or explain_sql.

    Fix: Add a '#' single-line comment scanner to scanTokenMySQL, scanTokenMySQLAnsiQuotes, and scanTokenMySQLNoBackslashEscapes in src/utils/sql-parser.ts, and disable multipleStatements on connections or queries that only expect a single statement such as explain_sql.

  2. MediumBare carriage returns in '--' comments bypass read-only mode and explain_sql on PostgreSQL and SQL Server

    src/utils/sql-parser.ts:15

    scanSingleLineComment scans '--' comments until a line feed (0x0A) and ignores a bare carriage return (0x0D). However, both PostgreSQL and SQL Server terminate '--' comments at a bare carriage return (0x0D). A prompt-injected agent calling execute_sql (with readonly = true) or explain_sql can pass a query containing '--' followed by a 0x0D byte and '; COMMIT; DROP TABLE ...' on PostgreSQL (sent as a multi-statement Simple Query because single statements omit bind values, while ConnectorManager does not set connection-level default_transaction_read_only) or 'COMMIT' followed by 0x0D and 'DROP TABLE ...' or 'EXEC ...' on SQL Server (bypassing both isReadOnlySQL and assertNoReadOnlyEscapes, and committing the outer rollback guard transaction early).

    Fix: Update scanSingleLineComment (and scanSingleLineCommentMySQL if applicable) in src/utils/sql-parser.ts to terminate single-line comments at both 0x0A (LF) and 0x0D (CR), matching continuedQuote in the same file.

  3. MediumOracle SQL*Plus '/' line separators bypass read-only SQL classification and transaction guard

    src/connectors/oracle/index.ts:786

    When execute_sql validates a query against a read-only policy, classifySQL uses splitSQLStatementVariants in src/utils/sql-parser.ts, which only splits statements on semicolons (';'). However, OracleConnector.executeSQL splits batches using OracleConnector.splitStatements, which also splits on standalone SQL*Plus '/' lines. If a prompt-injected agent sends statements separated only by '/' lines without semicolons (such as SELECT 1 FROM dual, '/', COMMIT, '/', DELETE FROM users, '/', COMMIT, or SELECT 1 FROM dual, '/', DROP TABLE users), classifySQL sees a single statement starting with SELECT and allows it, and OracleConnector then executes each split statement sequentially—where COMMIT or implicit DDL commits end SET TRANSACTION READ ONLY and permanently persist changes.

    Fix: Split on standalone '/' lines in splitSQLStatementVariants when the dialect is 'oracle', and re-check each statement produced by OracleConnector.splitStatements against isReadOnlySQL (rejecting COMMIT and DDL) when options.readonly is true.

  4. MediumAutomatic .env loading from working directory allows untrusted repositories to inject settings

    src/config/env.ts:95

    Whenever --config is used (including in the Claude Code plugin, which passes --config ${CLAUDE_PLUGIN_ROOT}/dbhub.toml), resolveSourceConfigs() calls loadEnvFiles(), which loads .env (and .env.local in development) from process.cwd() before checking the package directory. When an AI coding agent launches DBHub inside a cloned untrusted repository containing a crafted .env file, any unset environment variables are populated into process.env—allowing the repository to switch a default transport to HTTP with DBHUB_ALLOWED_HOSTS=* (if --transport was omitted), supply driver environment variables (such as PG* or TNS_ADMIN), or point AWS_CONFIG_FILE at a repo file containing credential_process for command execution when aws_iam_auth is used.

    Fix: Do not auto-load .env from process.cwd() when an explicit --config path is provided (or load only from an explicitly requested --env-file flag), matching the safeguard already used in resolveTomlConfigPath().

  5. LowHTTP transport binds to 0.0.0.0 without authentication and auto-allows LAN Host headers

    src/config/env.ts:216

    When started with --transport=http (as shown in the README installation command), DBHub defaults to binding on 0.0.0.0:8080 with bearer token authentication disabled, and server.ts passes getSelfHosts() into buildAllowedHosts() so the machine's hostname and all non-loopback network interface IPs are automatically added to the Host/Origin allow-list. Anyone on the same local network, Wi-Fi, or VPC can reach /mcp, /api/sources, /api/requests, and the Workbench UI directly by the machine's IP address without authentication or AI involvement to run SQL queries and read recent query logs.

    Fix: Default resolveHost() to 127.0.0.1 instead of 0.0.0.0 so network exposure requires an explicit --host flag, and update README examples to include --host 127.0.0.1 or --auth-token.

  6. LowSSH tunnel accepts any server host key without verification

    src/utils/ssh-tunnel.ts:321

    SSHTunnel.connectToHost passes host, port, and credentials to ssh2's client.connect() without configuring a hostVerifier callback or checking ~/.ssh/known_hosts. Because ssh2 accepts all server host keys by default when hostVerifier is omitted, a network attacker in a man-in-the-middle position between the user and the SSH bastion (or jump host) can impersonate the SSH server, capture SSH passwords, and intercept tunneled database traffic and credentials when database TLS verification is not separately enabled.

    Fix: Verify the remote server's host key against ~/.ssh/known_hosts (or an explicit fingerprint/known_hosts option in the source config) via ssh2's hostVerifier callback before completing the SSH handshake.

  7. LowQuoted SQLite PRAGMA names bypass read-only classifier and can alter shared session flags

    src/utils/allowed-keywords.ts:257

    In checkReadOnly(), SQLite parenthesized pragma setters are detected with sqlitePragmaParenPattern on SQL that has already passed through stripCommentsAndStrings(). Because SQLite allows pragma names to be quoted with double quotes, brackets, or backticks (for example, PRAGMA "ignore_check_constraints"(1) or PRAGMA [foreign_keys](0)), stripCommentsAndStrings blanks the quoted pragma name, causing sqlitePragmaParenPattern not to match and checkReadOnly() to return true. Although SQLiteConnector's PRAGMA query_only = ON backstop blocks disk writes, session-level pragma flags persist on the shared DatabaseSync connection and can weaken constraints for subsequent custom write tools on the same source.

    Fix: Reject any SQLite PRAGMA statement in checkReadOnly() that does not strictly match an unquoted allow-listed read-only pragma name (with optional unquoted schema) after comment/string stripping.

  8. LowPlugin setup skill runs unpinned @bytebase/dbhub@latest from npm

    plugin/skills/setup/SKILL.md:41

    Although the Claude Code plugin pins @bytebase/dbhub@1.6.1 in plugin/.mcp.json, the bundled /dbhub:setup skill instructs the agent to run npx -y @bytebase/dbhub@latest both when testing a connection (passing DBHUB_DSN in the shell command) and when registering a custom TOML config. Using -y with @latest silently downloads and runs whatever version is currently tagged latest on npm without confirmation, bypassing the plugin's version pin if a future npm release is compromised.

    Fix: Pin @bytebase/dbhub to the plugin's exact version (such as @bytebase/dbhub@1.6.1) in plugin/skills/setup/SKILL.md instead of @latest, and check the skill version in plugin-consistency.test.ts.

  9. LowDocker image runs the DBHub server as root

    Dockerfile:63

    The production stage of Dockerfile (FROM node:22-alpine) never switches to the built-in unprivileged node user before starting node dist/index.js, so the server runs as root inside the container. If a writable SQLite source (including --demo) is used or a runtime vulnerability is triggered, the process can modify root-owned files inside the container such as /app/dist or /etc.

    Fix: Add USER node before ENTRYPOINT in the production stage of Dockerfile, and pin pnpm with --frozen-lockfile in the builder stage.