Skip to content

Commit

Permalink
Add tests for matching keyword with something else
Browse files Browse the repository at this point in the history
Like a dangerous string or space
  • Loading branch information
hansott committed Jul 30, 2024
1 parent 2811e30 commit 5004ed7
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions library/vulnerabilities/sql-injection/detectSQLInjection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,69 @@ t.test("It does not flag SQL keyword if part of another word", async () => {
});
});

t.test("It flags SQL keyword if it contains space", async () => {
SQL_KEYWORDS.forEach((keyword) => {
isSqlInjection(
`
SELECT id,
business_id,
name,
created_at,
updated_at
FROM ${keyword}
WHERE business_id = ?
`,
" " + keyword
);

isSqlInjection(
`
SELECT id,
business_id,
name,
created_at,
updated_at
FROM ${keyword}
WHERE business_id = ?
`,
" " + keyword.toLowerCase()
);
});
});

t.test("It flags SQL keyword if it contains dangerous character", async () => {
SQL_KEYWORDS.forEach((keyword) => {
SQL_DANGEROUS_IN_STRING.forEach((string) => {
const payload = `${string}${keyword}`;
isSqlInjection(
`
SELECT id,
business_id,
name,
created_at,
updated_at
FROM ${payload}
WHERE business_id = ?
`,
payload
);

isSqlInjection(
`
SELECT id,
business_id,
name,
created_at,
updated_at
FROM ${payload}
WHERE business_id = ?
`,
payload.toLowerCase()
);
});
});
});

const files = [
// Taken from https://github.com/payloadbox/sql-injection-payload-list/tree/master
join(__dirname, "payloads", "Auth_Bypass.txt"),
Expand Down

0 comments on commit 5004ed7

Please sign in to comment.