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);
|
}
|
});
|