Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: block insecure MySQL allowAllFiles parameter (#17727)

p0ny692bca40d86f
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 1853cbe4f6..a2fd80c550 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -471,6 +471,11 @@ func (s *InstanceService) checkDataSource(instance *store.InstanceMessage, dataS
return missingFeatureError
}
+ // Validate extra connection parameters for MySQL-based engines
+ if err := validateExtraConnectionParameters(instance.Metadata.GetEngine(), dataSource.GetExtraConnectionParameters()); err != nil {
+ return connect.NewError(connect.CodeInvalidArgument, err)
+ }
+
return nil
}
@@ -1668,3 +1673,21 @@ func (s *InstanceService) instanceCountGuard(ctx context.Context) error {
return nil
}
+
+// validateExtraConnectionParameters validates extra connection parameters for security risks.
+func validateExtraConnectionParameters(engine storepb.Engine, params map[string]string) error {
+ // Validate MySQL-based engines
+ switch engine {
+ case storepb.Engine_MYSQL, storepb.Engine_MARIADB, storepb.Engine_OCEANBASE:
+ for key := range params {
+ normalizedKey := strings.ToLower(strings.TrimSpace(key))
+ if normalizedKey == "allowallfiles" {
+ // Disables file allowlist for LOAD DATA LOCAL INFILE and allows all files (might be insecure)
+ return errors.Errorf("connection parameter %q is not allowed for security reasons. This parameter can allow a malicious database server to read arbitrary files from the client", key)
+ }
+ }
+ default:
+ // No validation needed for other engines
+ }
+ return nil
+}
diff --git a/backend/plugin/db/mysql/mysql.go b/backend/plugin/db/mysql/mysql.go
index 32ff99b376..e91f83485f 100644
--- a/backend/plugin/db/mysql/mysql.go
+++ b/backend/plugin/db/mysql/mysql.go
@@ -47,6 +47,19 @@ func init() {
db.Register(storepb.Engine_OCEANBASE, newDriver)
}
+// validateMySQLExtraConnectionParameters validates that no dangerous parameters are present.
+func validateMySQLExtraConnectionParameters(params map[string]string) error {
+ for key := range params {
+ // Normalize key to lowercase for case-insensitive comparison
+ normalizedKey := strings.ToLower(strings.TrimSpace(key))
+ if normalizedKey == "allowallfiles" {
+ // Disables file allowlist for LOAD DATA LOCAL INFILE and allows all files (might be insecure)
+ return errors.Errorf("connection parameter %q is not allowed for security reasons", key)
+ }
+ }
+ return nil
+}
+
// Driver is the MySQL driver.
type Driver struct {
dbType storepb.Engine
@@ -106,6 +119,9 @@ func (d *Driver) getMySQLConnection(connCfg db.ConnectionConfig) (string, error)
}
params := []string{"multiStatements=true", "maxAllowedPacket=0"}
+ if err := validateMySQLExtraConnectionParameters(connCfg.DataSource.GetExtraConnectionParameters()); err != nil {
+ return "", err
+ }
for key, value := range connCfg.DataSource.GetExtraConnectionParameters() {
params = append(params, fmt.Sprintf("%s=%s", key, value))
}
diff --git a/backend/plugin/db/mysql/mysql_test.go b/backend/plugin/db/mysql/mysql_test.go
index baf819f426..2be5c24087 100644
--- a/backend/plugin/db/mysql/mysql_test.go
+++ b/backend/plugin/db/mysql/mysql_test.go
@@ -6,6 +6,77 @@ import (
"github.com/stretchr/testify/require"
)
+func TestValidateMySQLExtraConnectionParameters(t *testing.T) {
+ tests := []struct {
+ name string
+ params map[string]string
+ wantError bool
+ }{
+ {
+ name: "empty parameters",
+ params: map[string]string{},
+ wantError: false,
+ },
+ {
+ name: "safe parameters",
+ params: map[string]string{
+ "timeout": "10s",
+ "readTimeout": "30s",
+ "writeTimeout": "30s",
+ },
+ wantError: false,
+ },
+ {
+ name: "dangerous parameter - allowAllFiles",
+ params: map[string]string{
+ "allowAllFiles": "true",
+ },
+ wantError: true,
+ },
+ {
+ name: "dangerous parameter - allowAllFiles lowercase",
+ params: map[string]string{
+ "allowallfiles": "true",
+ },
+ wantError: true,
+ },
+ {
+ name: "dangerous parameter - allowAllFiles with mixed case",
+ params: map[string]string{
+ "AllowAllFiles": "true",
+ },
+ wantError: true,
+ },
+ {
+ name: "mixed safe and dangerous parameters",
+ params: map[string]string{
+ "timeout": "10s",
+ "allowAllFiles": "true",
+ },
+ wantError: true,
+ },
+ {
+ name: "parameter with whitespace",
+ params: map[string]string{
+ " allowAllFiles ": "true",
+ },
+ wantError: true,
+ },
+ }
+
+ a := require.New(t)
+ for _, tc := range tests {
+ t.Run(tc.name, func(_ *testing.T) {
+ err := validateMySQLExtraConnectionParameters(tc.params)
+ if tc.wantError {
+ a.Error(err, "expected error for test case: %s", tc.name)
+ } else {
+ a.NoError(err, "expected no error for test case: %s", tc.name)
+ }
+ })
+ }
+}
+
func TestParseVersion(t *testing.T) {
tests := []struct {
version string