Skip to content

Commit e0f0a68

Browse files
authored
Merge pull request #597 from AikidoSec/report-sql-dialect
Report SQL dialect in event metadata
2 parents 9dc8653 + 9b0328c commit e0f0a68

10 files changed

+28
-0
lines changed

library/agent/context/markUnsafe.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ t.test("it works", async () => {
6666
source: "markUnsafe",
6767
metadata: {
6868
sql: 'SELECT * FROM "users" WHERE id = 1',
69+
dialect: "PostgreSQL",
6970
},
7071
payload: "id = 1",
7172
pathsToPayload: [".[0]"],
@@ -94,6 +95,7 @@ t.test("it works", async () => {
9495
source: "markUnsafe",
9596
metadata: {
9697
sql: 'SELECT * FROM "users" WHERE id = 1',
98+
dialect: "PostgreSQL",
9799
},
98100
payload: "id = 1",
99101
pathsToPayload: [".[0].somePropertyThatContainsSQL"],

library/vulnerabilities/sql-injection/checkContextForSqlInjection.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ t.test("it returns correct path", async () => {
3030
pathsToPayload: [".id"],
3131
metadata: {
3232
sql: "SELECT * FROM users WHERE id = '1' OR 1=1; -- '",
33+
dialect: "MySQL",
3334
},
3435
payload: "1' OR 1=1; --",
3536
}

library/vulnerabilities/sql-injection/checkContextForSqlInjection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export function checkContextForSqlInjection({
3636
pathsToPayload: getPathsToPayload(str, context[source]),
3737
metadata: {
3838
sql: sql,
39+
dialect: dialect.getHumanReadableName(),
3940
},
4041
payload: str,
4142
};

library/vulnerabilities/sql-injection/detectSQLInjection.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,11 @@ function isNotSqlInjection(
361361
);
362362
}
363363
}
364+
365+
t.test("get human readable name", async () => {
366+
t.same(new SQLDialectGeneric().getHumanReadableName(), "Generic");
367+
t.same(new SQLDialectMySQL().getHumanReadableName(), "MySQL");
368+
t.same(new SQLDialectPostgres().getHumanReadableName(), "PostgreSQL");
369+
t.same(new SQLDialectSQLite().getHumanReadableName(), "SQLite");
370+
t.same(new SQLDialectClickHouse().getHumanReadableName(), "ClickHouse");
371+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export interface SQLDialect {
22
getWASMDialectInt(): number;
3+
getHumanReadableName(): string;
34
}

library/vulnerabilities/sql-injection/dialects/SQLDialectClickHouse.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export class SQLDialectClickHouse implements SQLDialect {
44
getWASMDialectInt(): number {
55
return 3;
66
}
7+
getHumanReadableName(): string {
8+
return "ClickHouse";
9+
}
710
}

library/vulnerabilities/sql-injection/dialects/SQLDialectGeneric.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export class SQLDialectGeneric implements SQLDialect {
44
getWASMDialectInt(): number {
55
return 0;
66
}
7+
getHumanReadableName(): string {
8+
return "Generic";
9+
}
710
}

library/vulnerabilities/sql-injection/dialects/SQLDialectMySQL.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export class SQLDialectMySQL implements SQLDialect {
44
getWASMDialectInt(): number {
55
return 8;
66
}
7+
getHumanReadableName(): string {
8+
return "MySQL";
9+
}
710
}

library/vulnerabilities/sql-injection/dialects/SQLDialectPostgres.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export class SQLDialectPostgres implements SQLDialect {
44
getWASMDialectInt(): number {
55
return 9;
66
}
7+
getHumanReadableName(): string {
8+
return "PostgreSQL";
9+
}
710
}

library/vulnerabilities/sql-injection/dialects/SQLDialectSQLite.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export class SQLDialectSQLite implements SQLDialect {
44
getWASMDialectInt(): number {
55
return 12;
66
}
7+
getHumanReadableName(): string {
8+
return "SQLite";
9+
}
710
}

0 commit comments

Comments
 (0)