mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-11-16 19:25:23 -06:00
In server mode, get_complete_file_path() joined the user's storage directory with the path they supplied after stripping only leading slashes, so a password file, SSL certificate, key, CRL or SSH tunnel identity file set to "../<another user>/.pgpass" (through the server dialog, the API or a servers.json import) would connect with another user's credentials or key. The sslkeylogfile parameter was copied into the connection string unchanged, so a traversal path let libpq create or append a file as the pgAdmin service account. The resolved path, with symbolic links followed, must now stay inside the user's storage directory, or inside the named shared storage directory for a "Name:/file" path, as the file manager already requires. sslkeylogfile is confined the same way, is refused in a shared storage directory that is read-only for the user, and is no longer inherited by non-owners of a shared server. A path that escapes, or whose storage directory cannot be determined, raises PermissionError rather than letting libpq fall back to its default file, and the message says where the file has to live. Desktop mode is unchanged. make_conninfo() quotes connection-parameter values but not their keys, so a key such as 'sslmode=require passfile' smuggled its own keyword=value pairs past these checks. Only exact libpq keywords, read from the linked libpq at runtime, are now accepted as connection parameter keys: when a server is created, updated, imported from servers.json or used for an ad-hoc connection, and again when the connection string is built, for rows saved earlier. Connecting, the SSH tunnel and the utilities' job creation report a refused path or key instead of proceeding, and a job whose environment cannot be resolved is removed rather than left in the Processes list. A server with a refused path or key can still be listed and edited to correct it. On Windows, the short path of a not-yet-existing file is resolved via its parent directory instead of being dropped. Co-authored-by: Dave Page <dpage@pgadmin.org> Co-authored-by: hiteshjambhale <hitesh.jambhale@enterprisedb.com>