mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(MySQL Node): Fix potential sql injection (#13818)
This commit is contained in:
@@ -30,20 +30,21 @@ export async function createConnection(
|
||||
|
||||
export async function searchTables(
|
||||
this: ILoadOptionsFunctions,
|
||||
query?: string,
|
||||
tableName?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const credentials = await this.getCredentials('mySql');
|
||||
const connection = await createConnection(credentials);
|
||||
const sql = `
|
||||
SELECT table_name FROM information_schema.tables
|
||||
WHERE table_schema = '${credentials.database}'
|
||||
and table_name like '%${query || ''}%'
|
||||
ORDER BY table_name
|
||||
`;
|
||||
const [rows] = await connection.query(sql);
|
||||
const results = (rows as IDataObject[]).map((r) => ({
|
||||
name: r.TABLE_NAME as string,
|
||||
value: r.TABLE_NAME as string,
|
||||
const sql = `SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = ?
|
||||
AND table_name LIKE ?
|
||||
ORDER BY table_name`;
|
||||
|
||||
const values = [credentials.database, `%${tableName ?? ''}%`];
|
||||
const [rows] = await connection.query(sql, values);
|
||||
const results = (rows as IDataObject[]).map((table) => ({
|
||||
name: (table.table_name as string) || (table.TABLE_NAME as string),
|
||||
value: (table.table_name as string) || (table.TABLE_NAME as string),
|
||||
}));
|
||||
await connection.end();
|
||||
return { results };
|
||||
|
||||
Reference in New Issue
Block a user