Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ t.test("It works with non-UTF-8 characters and emojis", async () => {
isNotSqlInjection("SELECT * FROM users WHERE id = 'a 🛡️'", "a 🛡️");
});

t.test("detects injection with trailing spaces in user input", async () => {
isSqlInjection(
"INSERT INTO pets (name, owner) VALUES ('x', 'dummy'), ('injected', 'hacker'); --', 'owner')",
"x', 'dummy'), ('injected', 'hacker'); -- "
);
});

const files = [
// Taken from https://github.com/payloadbox/sql-injection-payload-list/tree/master
join(__dirname, "payloads", "Auth_Bypass.txt"),
Expand Down
5 changes: 3 additions & 2 deletions library/vulnerabilities/sql-injection/detectSQLInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ export function detectSQLInjection(
userInput: string,
dialect: SQLDialect
): SQLInjectionDetectionResultType {
if (shouldReturnEarly(query, userInput)) {
const userInputNormalized = userInput.toLowerCase().trim();
if (shouldReturnEarly(query, userInputNormalized)) {
return SQLInjectionDetectionResult.SAFE;
}

const code = wasm_detect_sql_injection(
query.toLowerCase(),
userInput.toLowerCase(),
userInputNormalized,
dialect.getWASMDialectInt()
);

Expand Down