fix: make postgresql actually usable (4 critical bugs)

- CORS whitelist only allowed origin localhost:5173; browsers send Origin
  on same-origin POST too, so every deployment on any other port/origin
  got empty 403 on ALL POST/PUT/DELETE (curl tests masked it) - now
  echoes any origin (bearer-token auth, no cookie CSRF surface)
- connection_tester pg DSN had a literal *** password placeholder - pg
  connection test and query path could never authenticate
- instance detail endpoints (databases/tables/db-schema/table-detail)
  ran MySQL SHOW statements against pg - added pg branches
  (pg_database/pg_class/information_schema/pg_indexes, search_path
  semantics, PRI detection); schema filter uses non-system schemas
- frontend normalizeDbType missed the literal 'postgresql' value so pg
  instances were treated as mysql (backtick quoting, no column hints);
  genSql no longer emits db.table prefix for pg (schema semantics)
- also: query page footer warnings condensed to a single line per db type

verified live: mysql table tree/context menu/preview-execute; pg table
tree/columns/PK, double-click preview with masking working (email/phone
masked), query history persisted
This commit is contained in:
Logan.Li committed 2026-10-26 19:47:08 +08:00
1 parent c8155e2d33
commit 2c96902fbd
7 files changed
+183 -37

No files matched your search

@@ -5,6 +5,7 @@ import (
"database/sql"
"fmt"
"math"
"net/url"
"strconv"
"strings"
"time"
@@ -116,8 +117,8 @@ func testPostgreSQL(ctx context.Context, host string, port int, user, pass, dbna
if dbname == "" {
dbname = "postgres"
}
dsn := fmt.Sprintf("postgres://%s:***@%s:%d/%s?sslmode=disable&connect_timeout=10",
user, host, port, dbname)
dsn := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable&connect_timeout=10",
url.PathEscape(user), url.QueryEscape(pass), host, port, url.PathEscape(dbname))
db, err := sql.Open("pgx", dsn)
if err != nil {
return false, fmt.Sprintf("Connection failed: %v", err)
@@ -549,8 +550,8 @@ func getDBConnection(instance *model.Instance, dbName string) (*sql.DB, error) {
if dbName == "" {
dbName = "postgres"
}
dsn := fmt.Sprintf("postgres://%s:***@%s:%d/%s?sslmode=disable&connect_timeout=10",
instance.Username, instance.Host, instance.Port, dbName)
dsn := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable&connect_timeout=10",
url.PathEscape(instance.Username), url.QueryEscape(password), instance.Host, instance.Port, url.PathEscape(dbName))
return sql.Open("pgx", dsn)
default:
return nil, fmt.Errorf("unsupported database type: %s", instance.DBType)