{"id":"fb3b1badbd3fe997","repo":"go-sql-driver/mysql","slug":"local-file-s-is-not-registered","errorCode":null,"errorMessage":"local file '%s' is not registered","messagePattern":"local file '(.+?)' is not registered","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"infile.go","lineNumber":141,"sourceCode":"\t\t_, exists := fileRegister[name]\n\t\tfileRegisterLock.RUnlock()\n\t\tif mc.cfg.AllowAllFiles || exists {\n\t\t\tvar file *os.File\n\t\t\tvar fi os.FileInfo\n\n\t\t\tif file, err = os.Open(name); err == nil {\n\t\t\t\tdefer deferredClose(&err, file)\n\n\t\t\t\t// get file size\n\t\t\t\tif fi, err = file.Stat(); err == nil {\n\t\t\t\t\trdr = file\n\t\t\t\t\tif fileSize := int(fi.Size()); fileSize < packetSize {\n\t\t\t\t\t\tpacketSize = fileSize\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\terr = fmt.Errorf(\"local file '%s' is not registered\", name)\n\t\t}\n\t}\n\n\t// send content packets\n\tvar data []byte\n\n\t// if packetSize == 0, the Reader contains no data\n\tif err == nil && packetSize > 0 {\n\t\tdata = make([]byte, 4+packetSize)\n\t\tvar n int\n\t\tfor err == nil {\n\t\t\tn, err = rdr.Read(data[4:])\n\t\t\tif n > 0 {\n\t\t\t\tif ioErr := mc.conn().writePacket(data[:4+n]); ioErr != nil {\n\t\t\t\t\treturn ioErr\n\t\t\t\t}\n\t\t\t}\n\t\t}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/go-sql-driver/mysql/blob/c426bd93799de0f0e094c8f0582872c529d0ed0a/infile.go#L123-L159","documentation":"Thrown during a 'LOAD DATA LOCAL INFILE' operation: the MySQL server asked the driver to send a local file (infile.go:141), but that path is neither in the driver's allowlist (registered via mysql.RegisterLocalFile) nor covered by the allowAllFiles=true DSN option. The driver deliberately refuses to send arbitrary files to prevent a rogue server from exfiltrating sensitive data. Only explicitly allowlisted paths are readable.","triggerScenarios":"Calling db.Exec(\"LOAD DATA LOCAL INFILE '/data/sales.csv' INTO TABLE sales\") without first calling mysql.RegisterLocalFile(\"/data/sales.csv\") and without allowAllFiles=true in the DSN. The server requests the file by name; the driver looks it up in fileRegister (infile.go:123) and rejects it.","commonSituations":"Forgetting to register the file before the query; the path in the SQL string differs from the registered path (relative vs absolute, trailing slash, quoting); migrating away from allowAllFiles=true toward least privilege; the server echoes back an absolute path that does not match the registered one.","solutions":["Register the exact file path with mysql.RegisterLocalFile(filepath) before executing the LOAD DATA statement.","If you fully trust the server, add allowAllFiles=true to the DSN to permit any local file (less secure).","Ensure the path string in the SQL matches the registered path exactly, including quotes and trailing characters.","For in-memory/dynamic data, use mysql.RegisterReaderHandler(\"name\", fn) and reference 'Reader::name' in the SQL."],"exampleFix":"// before\nerr := db.Exec(\"LOAD DATA LOCAL INFILE '/data/sales.csv' INTO TABLE sales\")\n\n// after\nmysql.RegisterLocalFile(\"/data/sales.csv\")\nerr := db.Exec(\"LOAD DATA LOCAL INFILE '/data/sales.csv' INTO TABLE sales\")","handlingStrategy":"validation","validationCode":"// register the exact path before issuing LOAD DATA LOCAL INFILE\nfilePath := \"/data/sales.csv\"\nmysql.RegisterLocalFile(filePath)\n// only then:\ndb.Exec(\"LOAD DATA LOCAL INFILE '\" + filePath + \"' INTO TABLE sales\")","typeGuard":null,"tryCatchPattern":"res, err := db.Exec(\"LOAD DATA LOCAL INFILE '/data/sales.csv' INTO TABLE sales\")\nif err != nil {\n    if strings.Contains(err.Error(), \"is not registered\") {\n        // path not allowlisted: register it or enable allowAllFiles=true in the DSN\n    }\n}","preventionTips":["Register each file path with mysql.RegisterLocalFile before referencing it in SQL.","Keep the registered path and the SQL path string byte-for-byte identical.","Prefer the explicit allowlist over allowAllFiles=true for least privilege."],"tags":["security","local-infile","load-data","configuration"],"analyzedSha":"c426bd93799de0f0e094c8f0582872c529d0ed0a","analyzedAt":"2026-08-04T21:52:59.219Z","schemaVersion":2}