fix: validate vector store connection addresses against SSRF policy
Vector store create and raw connection-test accepted user-supplied connection addresses without SSRF validation, while every other admin-entered endpoint (e.g. model BaseURL) already runs ValidateURLForSSRF. An admin could point an engine address at an internal host and use the connection probe as an SSRF oracle. Add validateConnectionAddrSSRF, applied at the two user-input boundaries only: - CreateStore: validated before any network dial. - TestStoreRaw: a new TestRawConnection wrapper runs an engine-type allowlist, required-field validation, and SSRF validation before delegating to TestConnection. TestConnection stays validation-free for trusted callers (env stores, stored configs already validated at create time). Validation covers every address-bearing field a driver dials (Addr, qdrant Host+Port, weaviate Host and GrpcAddress) and fails closed for unmapped engine types. The Elasticsearch probe no longer follows redirects, closing a 302-to-internal bypass. docker-compose whitelists the bundled vector-store service hostnames (qdrant, milvus, weaviate, doris-fe) via SSRF_WHITELIST_EXTRA so the out-of-box experience is preserved; postgres is intentionally not whitelisted. .env.example and the OpenSearch dev guide document how to whitelist external or local-dev addresses.
This commit is contained in:
@@ -27,6 +27,10 @@ func newFakeESServer(t *testing.T) *httptest.Server {
|
||||
_, _ = w.Write([]byte(`{"version":{"number":"7.10.1"}}`))
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
// CreateStore now SSRF-validates the connection addr before the probe.
|
||||
// The httptest server listens on 127.0.0.1, which the SSRF policy blocks
|
||||
// by default, so whitelist it for the duration of the test.
|
||||
withSSRFWhitelist(t, "127.0.0.1")
|
||||
return srv
|
||||
}
|
||||
|
||||
@@ -308,6 +312,10 @@ func TestCreateStore_ConnectionConfigValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateStore_DuplicateCheck_DBStore(t *testing.T) {
|
||||
// "es" is an unresolvable host on a blocked port (9200); whitelist it so
|
||||
// the test reaches the duplicate check (step 3) rather than failing the
|
||||
// SSRF guard (step 2.1).
|
||||
withSSRFWhitelist(t, "es")
|
||||
repo := &mockVectorStoreRepo{existsByEndpoint: true}
|
||||
svc := NewVectorStoreService(repo, nil, nil, nil, nil)
|
||||
|
||||
@@ -329,6 +337,9 @@ func TestCreateStore_DuplicateCheck_DBStore(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateStore_DuplicateCheck_DBError(t *testing.T) {
|
||||
// Whitelist "es" so the flow reaches the duplicate-check DB error (step 3)
|
||||
// instead of stopping at the SSRF guard (step 2.1).
|
||||
withSSRFWhitelist(t, "es")
|
||||
repo := &mockVectorStoreRepo{
|
||||
existsByEndpointErr: assert.AnError,
|
||||
}
|
||||
@@ -348,6 +359,9 @@ func TestCreateStore_DuplicateCheck_DBError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateStore_DuplicateCheck_EnvStore(t *testing.T) {
|
||||
// Whitelist "es" so the flow reaches the env-store duplicate check rather
|
||||
// than failing the SSRF guard (step 2.1) on the unresolvable es:9200 host.
|
||||
withSSRFWhitelist(t, "es")
|
||||
// Set up env to simulate an existing elasticsearch env store
|
||||
t.Setenv("RETRIEVE_DRIVER", "elasticsearch_v8")
|
||||
t.Setenv("ELASTICSEARCH_ADDR", "http://es:9200")
|
||||
|
||||
Reference in New Issue
Block a user