-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js): add sequelize fallback (#470)
- Loading branch information
Showing
3 changed files
with
73 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,87 @@ | ||
const { | ||
createNewInvoker, | ||
getEnvironment, | ||
} = require("../../../helper.js") | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname) | ||
const { createNewInvoker, getEnvironment } = require("../../../helper.js"); | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname); | ||
|
||
describe(ruleId, () => { | ||
const invoke = createNewInvoker(ruleId, ruleFile, testBase) | ||
const invoke = createNewInvoker(ruleId, ruleFile, testBase); | ||
|
||
test("knex_sql_injection", () => { | ||
const testCase = "knex_sql_injection.js"; | ||
|
||
test("knex_sql_injection", () => { | ||
const testCase = "knex_sql_injection.js" | ||
const results = invoke(testCase); | ||
|
||
const results = invoke(testCase) | ||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
test("mysql2_sql_injection", () => { | ||
const testCase = "mysql2_sql_injection.js"; | ||
|
||
const results = invoke(testCase); | ||
|
||
test("mysql2_sql_injection", () => { | ||
const testCase = "mysql2_sql_injection.js" | ||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
const results = invoke(testCase) | ||
test("ok_no_sql_injection", () => { | ||
const testCase = "ok_no_sql_injection.js"; | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
const results = invoke(testCase); | ||
|
||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
test("ok_no_sql_injection", () => { | ||
const testCase = "ok_no_sql_injection.js" | ||
test("pg_sql_injection", () => { | ||
const testCase = "pg_sql_injection.js"; | ||
|
||
const results = invoke(testCase) | ||
const results = invoke(testCase); | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
test("sequelize_sql_injection", () => { | ||
const testCase = "sequelize_sql_injection.js"; | ||
|
||
test("pg_sql_injection", () => { | ||
const testCase = "pg_sql_injection.js" | ||
const results = invoke(testCase); | ||
|
||
const results = invoke(testCase) | ||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
test("sequelize_fallback_sql_injection", () => { | ||
const testCase = "sequelize_fallback_sql_injection.js"; | ||
|
||
const results = invoke(testCase); | ||
|
||
test("sequelize_sql_injection", () => { | ||
const testCase = "sequelize_sql_injection.js" | ||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
const results = invoke(testCase) | ||
test("sql_injection_juice", () => { | ||
const testCase = "sql_injection_juice.js"; | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
const results = invoke(testCase); | ||
|
||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
test("sql_injection_juice", () => { | ||
const testCase = "sql_injection_juice.js" | ||
test("sql_injection_juice_safe", () => { | ||
const testCase = "sql_injection_juice_safe.ts"; | ||
|
||
const results = invoke(testCase) | ||
const results = invoke(testCase); | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
|
||
test("sqlite3_sql_injection", () => { | ||
const testCase = "sqlite3_sql_injection.js"; | ||
|
||
test("sql_injection_juice_safe", () => { | ||
const testCase = "sql_injection_juice_safe.ts" | ||
const results = invoke(testCase); | ||
|
||
const results = invoke(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
|
||
|
||
test("sqlite3_sql_injection", () => { | ||
const testCase = "sqlite3_sql_injection.js" | ||
|
||
const results = invoke(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
|
||
}) | ||
expect(results.Missing).toEqual([]); | ||
expect(results.Extra).toEqual([]); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
tests/javascript/lang/sql_injection/testdata/sequelize_fallback_sql_injection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { sequelize, User, Password } = require("./init_db"); | ||
|
||
module.exports.fooBar = function (req, _res) { | ||
var customerQuery = | ||
"SELECT * FROM customers WHERE status = " + req.params.customer.status; | ||
// bearer:expected javascript_lang_sql_injection | ||
sequelize.query(customerQuery); | ||
}; | ||
|
||
module.exports.bad = function (status) { | ||
var customerQuery = "SELECT * FROM customers WHERE status = " + status; | ||
// bearer:expected javascript_lang_sql_injection | ||
sequelize.query(customerQuery); | ||
}; |