[CONJS-266] Option `infileStreamFactory` addition for compatibility Created: 2023-09-06  Updated: 2023-09-08  Resolved: 2023-09-07

Status: Closed
Project: MariaDB Connector/node.js
Component/s: compatibility
Affects Version/s: None
Fix Version/s: 3.2.1

Type: Task Priority: Minor
Reporter: Diego Dupin Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

Option `infileStreamFactory` permit having a callback for LOAD LOCAL commands.
In other mysql connectors, this callback permits 2 behaviors :

  • validate file name
  • permit to return a stream, so this can permit not using local file

MariaDB connector already validate file name, but this will be implemented for compatibility



 Comments   
Comment by Diego Dupin [ 2023-09-08 ]

example of use:

  function isWithin(outer, inner) {
    const rel = path.relative(outer, inner);
    return !rel.startsWith('../') && rel !== '..';
  }
 const conn = await mariadb.createConnection({
      host: 'localhost',
      user: 'root',
      permitLocalInfile: true,
      infileStreamFactory: (filePath) => {
        // this is an example, that required local file to only comes from temporay folder
        if (!isWithin(os.tmpdir(), filePath)) {
          throw new Error(`Application only expect to send file from ${os.tmpdir()}, but file ${filePath} was asked`);
        }
        return fs.createReadStream(smallFileName);
      }
    });

Generated at Thu Feb 08 03:23:58 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.