-
Notifications
You must be signed in to change notification settings - Fork 2k
JS: support hana db client
#19118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
JS: support hana db client
#19118
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
032cfc1
Added test cases for `hana` clients.
Napalys 9229962
Add sink model for SQL injection detection in `exec` clients.
Napalys d28af95
Added sink models for `hana`'s client `prepare` function.
Napalys e595def
Modeled `execute` as potential `hana`'s sink.
Napalys 0285cb6
Added `@sap/hdbext.loadProccedure` as sql sink.
Napalys 7cc0634
Added `createProcStatement` as potential sql sink.
Napalys 4cdc40d
Added SQL injection detection for `exec` method embeded Express clien…
Napalys 62ab7f5
Added change note.
Napalys e69929e
Update javascript/ql/lib/change-notes/2025-03-26-hana-db-client.md
Napalys f7264d8
Merge branch 'main' into js/hana_db_client
Napalys f3af23e
Refactored hana's DB client to use `GuardedRouteHandler`, improving p…
Napalys d0e2aa8
Added sources from `hana` db as `MaD`.
Napalys 45c8ec9
Added test cases for `hana` db additional sources.
Napalys 32d6ac8
Add test case to ensure `exec` calls without middleware injection int…
Napalys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Added support for `@sap/hana-client`, `@sap/hdbext` and `hdb` packages. | ||
This file contains hidden or 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,10 @@ | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/javascript-all | ||
| extensible: sinkModel | ||
| data: | ||
| - ["@sap/hana-client", "Member[createConnection].ReturnValue.Member[exec,prepare].Argument[0]", "sql-injection"] | ||
| - ["hdb", "Member[createClient].ReturnValue.Member[exec,prepare,execute].Argument[0]", "sql-injection"] | ||
| - ["@sap/hdbext", "Member[loadProcedure].Argument[2]", "sql-injection"] | ||
| - ["@sap/hana-client/extension/Stream", "Member[createProcStatement].Argument[1]", "sql-injection"] | ||
| - ["express", "ReturnValue.Member[get].Argument[1].Parameter[0].Member[db].Member[exec].Argument[0]", "sql-injection"] |
This file contains hidden or 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
86 changes: 86 additions & 0 deletions
86
javascript/ql/test/query-tests/Security/CWE-089/untyped/hana.js
This file contains hidden or 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,86 @@ | ||
| const hana = require('@sap/hana-client'); | ||
| const express = require('express'); | ||
|
|
||
| const app = express(); | ||
| const connectionParams = {}; | ||
| app.post('/documents/find', (req, res) => { | ||
| const conn = hana.createConnection(); | ||
| conn.connect(connectionParams, (err) => { | ||
| let maliciousInput = req.body.data; // $ Source | ||
| const query = `SELECT * FROM Users WHERE username = '${maliciousInput}'`; | ||
| conn.exec(query, (err, rows) => {}); // $ Alert | ||
| conn.disconnect(); | ||
| }); | ||
|
|
||
| conn.connect(connectionParams, (err) => { | ||
| const maliciousInput = req.body.data; // $ Source | ||
| const stmt = conn.prepare(`SELECT * FROM Test WHERE ID = ? AND username = ` + maliciousInput); // $ Alert | ||
| stmt.exec([maliciousInput], (err, rows) => {}); // maliciousInput is treated as a parameter | ||
| conn.disconnect(); | ||
| }); | ||
|
|
||
| conn.connect(connectionParams, (err) => { | ||
| const maliciousInput = req.body.data; // $ Source | ||
| var stmt = conn.prepare(`INSERT INTO Customers(ID, NAME) VALUES(?, ?) ` + maliciousInput); // $ Alert | ||
| stmt.execBatch([[1, maliciousInput], [2, maliciousInput]], function(err, rows) {}); // maliciousInput is treated as a parameter | ||
| conn.disconnect(); | ||
| }); | ||
|
|
||
| conn.connect(connectionParams, (err) => { | ||
| const maliciousInput = req.body.data; // $ Source | ||
| var stmt = conn.prepare("SELECT * FROM Customers WHERE ID >= ? AND ID < ?" + maliciousInput); // $ Alert | ||
| stmt.execQuery([100, maliciousInput], function(err, rs) {}); // $ maliciousInput is treated as a parameter | ||
| conn.disconnect(); | ||
| }); | ||
| }); | ||
|
|
||
| var hdbext = require('@sap/hdbext'); | ||
| var express = require('express'); | ||
| var dbStream = require('@sap/hana-client/extension/Stream'); | ||
|
|
||
| var app1 = express(); | ||
| const hanaConfig = {}; | ||
| app1.use(hdbext.middleware(hanaConfig)); | ||
|
|
||
| app1.get('/execute-query', function (req, res) { | ||
| var client = req.db; | ||
| let maliciousInput = req.body.data; // $ Source | ||
| client.exec('SELECT * FROM DUMMY' + maliciousInput, function (err, rs) {}); // $ Alert | ||
|
|
||
| dbStream.createProcStatement(client, 'CALL PROC_DUMMY (?, ?, ?, ?, ?)' + maliciousInput, function (err, stmt) { // $ Alert | ||
| stmt.exec({ A: maliciousInput, B: 4 }, function (err, params, dummyRows, tablesRows) {}); // maliciousInput is treated as a parameter | ||
| }); | ||
|
|
||
| hdbext.loadProcedure(client, null, 'PROC_DUMMY' + maliciousInput, function(err, sp) { // $ Alert | ||
| sp(3, maliciousInput, function(err, parameters, dummyRows, tablesRows) {}); // maliciousInput is treated as a parameter | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| var hdb = require('hdb'); | ||
| const async = require('async'); | ||
|
|
||
| const options = {}; | ||
| const app2 = express(); | ||
|
|
||
| app2.post('/documents/find', (req, res) => { | ||
| var client = hdb.createClient(options); | ||
| let maliciousInput = req.body.data; // $ Source | ||
|
|
||
| client.connect(function onconnect(err) { | ||
| async.series([client.exec.bind(client, "INSERT INTO NUMBERS VALUES (1, 'one')" + maliciousInput)], function (err) {}); // $ Alert | ||
|
|
||
| client.exec('select * from DUMMY' + maliciousInput, function (err, rows) {}); // $ Alert | ||
| client.exec('select * from DUMMY' + maliciousInput, options, function(err, rows) {}); // $ Alert | ||
|
|
||
| client.prepare('select * from DUMMY where DUMMY = ?' + maliciousInput, function (err, statement){ // $ Alert | ||
| statement.exec([maliciousInput], function (err, rows) {}); // maliciousInput is treated as a parameter | ||
| }); | ||
|
|
||
| client.prepare('call PROC_DUMMY (?, ?, ?, ?, ?)' + maliciousInput, function(err, statement){ // $ Alert | ||
| statement.exec({A: 3, B: maliciousInput}, function(err, parameters, dummyRows, tableRows) {}); | ||
| }); | ||
|
|
||
| client.execute('select A, B from TEST.NUMBERS order by A' + maliciousInput, function(err, rs) {}); // $ Alert | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.