JavaScript request filter - MySQL

The JavaScript request filter is the most flexible of all request filters. It can potentially be called for any packet type, and can modify traffic in any way it sees fit.

Parameters

Context

The following variables will always be defined when your JavaScript executes:

Example

When connecting, it's common for a database client to issue the command show databases (MySQL documentation). We could restrict this with the following filter (appropriately configured) for Query packets:

let sql = context.packet.sql;
if (sql.trim().toLowerCase().startsWith("show databases")) {
    log.info("Changing show databases");
    context.packet.sql = "show databases like 'public_%'";
}