Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(pam): MySQL line comment requires trailing space, disable backslash escape in backtick identifiers, add metadata query timeout
bernie-g4892e409331c
diff --git a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.test.ts b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.test.tsindex a0ac0046d1..20f5882977 100644--- a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.test.ts+++ b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.test.ts@@ -115,6 +115,36 @@ describe("splitMysqlStatements", () => {]);});+ test("double-dash without trailing space is not a line comment", () => {+ expect(splitMysqlStatements("SELECT 1--1; SELECT 2")).toEqual(["SELECT 1--1", "SELECT 2"]);+ });++ test("double-dash with trailing space is a line comment", () => {+ expect(splitMysqlStatements("SELECT 1 -- comment\n; SELECT 2")).toEqual([+ "SELECT 1 -- comment",+ "SELECT 2"+ ]);+ });++ test("double-dash at end of input is a line comment", () => {+ expect(splitMysqlStatements("SELECT 1 --")).toEqual(["SELECT 1 --"]);+ });++ test("double-dash with tab is a line comment", () => {+ expect(splitMysqlStatements("SELECT 1 --\tcomment\n; SELECT 2")).toEqual([+ "SELECT 1 --\tcomment",+ "SELECT 2"+ ]);+ });++ test("backtick identifier with backslash is not escaped", () => {+ expect(splitMysqlStatements("SELECT `col\\`; SELECT 2")).toEqual(["SELECT `col\\`", "SELECT 2"]);+ });++ test("backslash in single-quoted string still escapes", () => {+ expect(splitMysqlStatements("SELECT 'a\\';b'; SELECT 2")).toEqual(["SELECT 'a\\';b'", "SELECT 2"]);+ });+test("unterminated single-quoted string", () => {expect(splitMysqlStatements("SELECT 'abc")).toEqual(["SELECT 'abc"]);});@@ -149,6 +179,10 @@ describe("extractCommand", () => {expect(extractCommand("-- first\n/* second */ # third\nDELETE FROM t")).toBe("DELETE");});+ test("double-dash without space is not a comment in extractCommand", () => {+ expect(extractCommand("--nospc")).toBe("--NOSPC");+ });+test("START TRANSACTION", () => {expect(extractCommand("START TRANSACTION")).toBe("START");});diff --git a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.ts b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.tsindex 9c9c0caede..115e779dfc 100644--- a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.ts+++ b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.ts@@ -1,7 +1,8 @@const skipQuoted = (sql: string, pos: number, quote: string): number => {let i = pos + 1;+ const backslashEscape = quote !== "`";while (i < sql.length) {- if (sql[i] === "\\") {+ if (backslashEscape && sql[i] === "\\") {i += 2;} else if (sql[i] === quote) {if (i + 1 < sql.length && sql[i + 1] === quote) {@@ -34,7 +35,10 @@ const skipBlockComment = (sql: string, pos: number): number => {return Math.min(i + 2, sql.length);};-const isLineComment = (sql: string, pos: number) => sql[pos] === "-" && sql[pos + 1] === "-";+const isLineComment = (sql: string, pos: number) =>+ sql[pos] === "-" &&+ sql[pos + 1] === "-" &&+ (pos + 2 >= sql.length || sql[pos + 2] === " " || sql[pos + 2] === "\t" || sql[pos + 2] === "\n");const isBlockComment = (sql: string, pos: number) => sql[pos] === "/" && sql[pos + 1] === "*";diff --git a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.tsindex 500dfcb6a2..a39ad7c73a 100644--- a/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts+++ b/backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts@@ -21,6 +21,7 @@ const buildConnection = async ({ relayPort, username, database }: OneShotOptionsconst withConnection = async <T>(opts: OneShotOptions, fn: (conn: mysql.Connection) => Promise<T>): Promise<T> => {const conn = await buildConnection(opts);try {+ await conn.query("SET SESSION max_execution_time = 30000");return await fn(conn);} finally {await conn.end().catch((err) => {