Summary
pgweb leaves its database connection endpoint insufficiently protected when connect-backend authorization is enabled. An attacker who can reach the endpoint may submit a custom session identifier and connection string to bypass resource-to-database mapping and access unauthorized databases or internal services.
Affected context
The issue occurs in pgweb deployments using connect-backend authorization where the POST /api/connect endpoint remains accessible without equivalent authorization enforcement. Risk is higher when the service can reach sensitive databases or internal network destinations and accepts user-controlled connection parameters.
Exploit preconditions
- Attack surface: The pgweb HTTP API, specifically the POST
/api/connectendpoint - Required access: Network reachability to the endpoint; authentication requirements depend on the surrounding deployment
- Trigger point: Submission of a connection request containing attacker-controlled session and database connection details
- Why exploitation is possible: The endpoint does not consistently enforce the configured authorization policy, allowing supplied identifiers and connection strings to bypass intended resource-to-database mappings
Why this happens
The underlying flaw is an authorization enforcement gap. The application protects or configures access through resource-to-database mappings but does not apply equivalent authorization checks to the connection endpoint before using caller-controlled connection information. This behavior maps to CWE-862, Missing Authorization, because a sensitive operation can proceed without verifying that the requester is permitted to access the selected resource.
Potential impact
- Attackers could connect to databases outside their authorized scope.
- Attackers may access sensitive data or perform unauthorized database actions.
- The service could be used to reach internal network services from a trusted environment.
- Credentials, metadata, or other protected information could be exposed.
- Unauthorized connections could cause data modification or service disruption.
General mitigation guidance
Mitigation generally focuses on enforcing authorization at every endpoint that creates or changes backend connections, rather than relying only on resource-to-database mappings. Secure-by-default designs should permit connections only to explicitly approved targets, bind session identifiers to authenticated principals, and avoid accepting arbitrary connection strings from untrusted clients. Input trust should be reduced through strict allowlists and schema validation, while database and service identities should use least privilege and constrained network access. Deployment policy can also restrict the pgweb service from reaching sensitive internal destinations.
How teams detect issues like this
Detection can include static and dynamic checks for connection endpoints that accept client-controlled targets without an authorization decision. Code review should examine whether authorization is performed before connection creation and whether session identifiers are bound to authenticated users. API security testing can verify that configured mappings cannot be bypassed with alternate identifiers or connection parameters. Policy enforcement may restrict outbound database and internal-service access from administrative web tools, while centralized logs can flag unusual connection destinations, repeated failed authorization checks, and access outside approved mappings.

