Skip to content

fix: reject direct connect url when connect-backend is set - #870

Open
aroh3006 wants to merge 1 commit into
sosedoff:mainfrom
aroh3006:fix/connect-backend-bypass
Open

fix: reject direct connect url when connect-backend is set#870
aroh3006 wants to merge 1 commit into
sosedoff:mainfrom
aroh3006:fix/connect-backend-bypass

Conversation

@aroh3006

@aroh3006 aroh3006 commented Sep 3, 2026

Copy link
Copy Markdown

Fixes #869.

Connect (pkg/api/api.go) only guards the direct-url path with
bookmark_id and BookmarksOnly, so in connect-backend mode
(--sessions --connect-backend=... --connect-token=...) a client can
still POST a url form value to /api/connect and connect straight
to it, bypassing the backend entirely. The backend exists specifically
to decide which database a session is allowed to reach, so this
defeats the whole point of the feature and lets any client reach
whatever host and database the pgweb process can dial.

Connect now rejects the direct url path with the existing
errNotPermitted when command.Opts.ConnectBackend is set, the same
way it already does for BookmarksOnly. The backend-gated route
(ConnectWithBackend) and bookmark connections are untouched.

Test. Added Test_Connect_RejectsDirectUrlWhenConnectBackendConfigured,
which sets ConnectBackend and POSTs a url pointing at an
unresolvable host. Ran it against the current code first: the handler
actually attempted the connection and returned a DNS lookup error
(proving it really does reach out to an attacker-chosen host), so the
test fails there and passes with this change. Full pkg/api suite
still passes.

Connect fell through to ConnectWithURL for any request that was not
a bookmark, even in connect-backend mode. The backend is supposed to
be the only thing deciding which database a session gets, but a
client could just POST a url to /api/connect and reach any database
the pgweb host can dial, bypassing the backend entirely.

Now Connect rejects the direct url path with the same errNotPermitted
used for bookmarks-only mode when connect-backend is configured,
leaving the backend-gated and bookmark paths untouched.

Added a test that hits /api/connect with connect-backend set and a
url pointing at an unresolvable host. It fails against the old code
(the handler actually tries to dial the host and returns a DNS
error) and passes with the fix (rejected immediately, no connection
attempt).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connect-backend authorization bypass via direct /api/connect arbitrary connection string

1 participant