-
Notifications
You must be signed in to change notification settings - Fork 2
Adds support for npm
and xsjslib
modules
#143
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
b920fba
Adds support for npm and xsjslib
mbaluda 2e6d302
Merge branch 'main' into mbaluda/xsjslib
mbaluda f31c6ee
Add support for XSS sanitizer lib
mbaluda f70a4e2
Reapply "Replace location in external file"
mbaluda 3859a18
modify expected file
mbaluda 44f7acf
Format cds files
mbaluda 8b0b5ac
Fix url
mbaluda 5aef039
changed query @id
mbaluda 1530e1d
expected
mbaluda 90ceb4c
update qlpack
mbaluda 9845134
try using hasLocationInfo
mbaluda 6d62c81
Merge branch 'main' into mbaluda/xsjslib
mbaluda 6f25abd
Merge branch 'main' into mbaluda/external-cds
mbaluda aee5bd2
Update code_scanning.yml
mbaluda 6d1b531
index cds files
mbaluda 3b4c070
fix expected file
mbaluda fe09676
Correct location in tests and code scanning
mbaluda e298c08
Update expected SARIF file
mbaluda 1672d5b
modify alert location
mbaluda f0b07bc
standardized query ids
mbaluda f524389
update expected file
mbaluda 614695d
fix tests
mbaluda c035863
fix location
mbaluda d3810c4
Update expected files
mbaluda 61bc15e
Merge branch 'mbaluda/external-cds' into mbaluda/xsjslib
mbaluda 62c0d0a
Deals with external .cds files
mbaluda 43b4427
Fix error message
mbaluda dce19fd
Error message updated based on SAP feedback
mbaluda c47778d
Address review
mbaluda a769f99
Update to CodeQL v2.19.0
mbaluda ce599be
Deals with external .cds files
mbaluda 73ac321
Address review
mbaluda 2ffb055
Update to CodeQL v2.19.0
mbaluda fe26838
Update code_scanning.yml
mbaluda ddbfcc9
index cds files
mbaluda 18896cb
update expected file
mbaluda a310fd0
Xsjslib modules
mbaluda 4ed1079
Merge branch 'mbaluda/cds' into mbaluda/xsjslib
mbaluda 7f58632
Update expected file
mbaluda bbec0c7
xss-secure sanitizers
mbaluda cc8990d
XSJSLibModules
mbaluda 21509a8
remove duplicated test
mbaluda 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
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
59 changes: 59 additions & 0 deletions
59
...cript/frameworks/xsjs/lib/advanced_security/javascript/frameworks/xsjs/XSJSLibModules.qll
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,59 @@ | ||
/** Provides classes for working with XSJSLib modules. */ | ||
|
||
import javascript | ||
|
||
/** | ||
* An XSJS module. | ||
*/ | ||
class XSJSModule extends Module { | ||
XSJSModule() { this.getFile().getExtension() = ["xsjs", "xsjslib"] } | ||
|
||
override XSJSImportExpr getAnImport() { result.getTopLevel() = this } | ||
|
||
/** Gets a module from which this module imports. */ | ||
override XSJSModule getAnImportedModule() { result = this.getAnImport().getImportedModule() } | ||
|
||
override DataFlow::ValueNode getAnExportedValue(string name) { | ||
result.getFile() = this.getFile() and | ||
exists(FunctionDeclStmt fds | fds = result.getAstNode() | | ||
fds.getParent() instanceof TopLevel and | ||
name = fds.getName() | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* An import declaration. | ||
* | ||
* Example: | ||
* | ||
* ``` | ||
* $.import("module.xsjslib"); | ||
* ``` | ||
*/ | ||
class XSJSImportExpr extends CallExpr, Import { | ||
XSJSImportExpr() { | ||
this.getReceiver().(GlobalVarAccess).getName() = "$" and | ||
this.getFile().getExtension() = ["xsjs", "xsjslib"] and | ||
this.getCalleeName() = "import" and | ||
this.getNumArgument() = 1 | ||
} | ||
|
||
override Module getEnclosingModule() { result = this.getTopLevel() } | ||
|
||
override XSJSLiteralImportPath getImportedPath() { result = this.getArgument(0) } | ||
|
||
override DataFlow::Node getImportedModuleNode() { result = DataFlow::valueNode(this) } | ||
} | ||
|
||
/** A literal path expression appearing in an `import` declaration. */ | ||
private class XSJSLiteralImportPath extends PathExpr, ConstantString { | ||
XSJSLiteralImportPath() { exists(XSJSImportExpr req | this = req.getArgument(0)) } | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
override Folder getAdditionalSearchRoot(int priority) { | ||
priority = 0 and | ||
result = this.getFile().getParentContainer() | ||
} | ||
mbaluda marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
override string getValue() { result = this.getStringValue() } | ||
} |
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
2 changes: 2 additions & 0 deletions
2
javascript/frameworks/xsjs/test/models/modules/npm/npm.expected
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,2 @@ | ||
| npm.xsjs:3:14:3:71 | crypto. ... 1024 }) | | ||
| npm.xsjs:5:15:5:72 | crypto. ... 4096 }) | |
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 @@ | ||
import javascript | ||
|
||
from CryptographicKeyCreation crypto | ||
select crypto |
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,5 @@ | ||
const crypto = $.require("crypto"); | ||
|
||
const bad1 = crypto.generateKeyPairSync("rsa", { modulusLength: 1024 }); // NOT OK | ||
|
||
const good1 = crypto.generateKeyPairSync("rsa", { modulusLength: 4096 }); // OK |
2 changes: 2 additions & 0 deletions
2
javascript/frameworks/xsjs/test/models/modules/xsjslib/xsjslib.expected
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,2 @@ | ||
| xsjslib.xsjs:1:1:4:0 | <toplevel> | | ||
| xsjslib.xsjslib:1:1:15:2 | <toplevel> | |
4 changes: 4 additions & 0 deletions
4
javascript/frameworks/xsjs/test/models/modules/xsjslib/xsjslib.ql
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 @@ | ||
import javascript | ||
import advanced_security.javascript.frameworks.xsjs.XSJSLibModules | ||
|
||
select any(Module m) |
3 changes: 3 additions & 0 deletions
3
javascript/frameworks/xsjs/test/models/modules/xsjslib/xsjslib.xsjs
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,3 @@ | ||
var injection1=$.import("xsjslib.xsjslib"); | ||
|
||
injection1.test1(requestParameters); |
15 changes: 15 additions & 0 deletions
15
javascript/frameworks/xsjs/test/models/modules/xsjslib/xsjslib.xsjslib
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,15 @@ | ||
/** | ||
* True positive case: Sink being `$.db.Connection.prepareStatement(query, arguments...)`, | ||
* the API in the older namespace. The remote value is concatenated raw into the query. | ||
*/ | ||
function test1(requestParameters) { | ||
let someParameterValue1 = JSON.parse(requestParameters.get("someParameter1")); | ||
let someParameterValue2 = JSON.parse(requestParameters.get("someParameter2")); | ||
let query = "INSERT INTO " + someParameterValue1 + ".ENTITY (COL1) VALUES (" + someParameterValue2 + ")"; | ||
|
||
let dbConnection = $.db.getConnection(); | ||
let preparedStatement = dbConnection.prepareStatement(query); | ||
preparedStatement.executeUpdate(); | ||
dbConnection.commit(); | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/XSJSLibSqlInjection.expected
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,32 @@ | ||
nodes | ||
| lib/injection1.xsjslib:6:7:6:79 | someParameterValue1 | | ||
| lib/injection1.xsjslib:6:29:6:79 | JSON.pa ... ter1")) | | ||
| lib/injection1.xsjslib:6:40:6:78 | request ... eter1") | | ||
| lib/injection1.xsjslib:6:40:6:78 | request ... eter1") | | ||
| lib/injection1.xsjslib:7:7:7:79 | someParameterValue2 | | ||
| lib/injection1.xsjslib:7:29:7:79 | JSON.pa ... ter2")) | | ||
| lib/injection1.xsjslib:7:40:7:78 | request ... eter2") | | ||
| lib/injection1.xsjslib:7:40:7:78 | request ... eter2") | | ||
| lib/injection1.xsjslib:8:7:8:106 | query | | ||
| lib/injection1.xsjslib:8:15:8:106 | "INSERT ... 2 + ")" | | ||
| lib/injection1.xsjslib:8:32:8:50 | someParameterValue1 | | ||
| lib/injection1.xsjslib:8:82:8:100 | someParameterValue2 | | ||
| lib/injection1.xsjslib:11:57:11:61 | query | | ||
| lib/injection1.xsjslib:11:57:11:61 | query | | ||
edges | ||
| lib/injection1.xsjslib:6:7:6:79 | someParameterValue1 | lib/injection1.xsjslib:8:32:8:50 | someParameterValue1 | | ||
| lib/injection1.xsjslib:6:29:6:79 | JSON.pa ... ter1")) | lib/injection1.xsjslib:6:7:6:79 | someParameterValue1 | | ||
| lib/injection1.xsjslib:6:40:6:78 | request ... eter1") | lib/injection1.xsjslib:6:29:6:79 | JSON.pa ... ter1")) | | ||
| lib/injection1.xsjslib:6:40:6:78 | request ... eter1") | lib/injection1.xsjslib:6:29:6:79 | JSON.pa ... ter1")) | | ||
| lib/injection1.xsjslib:7:7:7:79 | someParameterValue2 | lib/injection1.xsjslib:8:82:8:100 | someParameterValue2 | | ||
| lib/injection1.xsjslib:7:29:7:79 | JSON.pa ... ter2")) | lib/injection1.xsjslib:7:7:7:79 | someParameterValue2 | | ||
| lib/injection1.xsjslib:7:40:7:78 | request ... eter2") | lib/injection1.xsjslib:7:29:7:79 | JSON.pa ... ter2")) | | ||
| lib/injection1.xsjslib:7:40:7:78 | request ... eter2") | lib/injection1.xsjslib:7:29:7:79 | JSON.pa ... ter2")) | | ||
| lib/injection1.xsjslib:8:7:8:106 | query | lib/injection1.xsjslib:11:57:11:61 | query | | ||
| lib/injection1.xsjslib:8:7:8:106 | query | lib/injection1.xsjslib:11:57:11:61 | query | | ||
| lib/injection1.xsjslib:8:15:8:106 | "INSERT ... 2 + ")" | lib/injection1.xsjslib:8:7:8:106 | query | | ||
| lib/injection1.xsjslib:8:32:8:50 | someParameterValue1 | lib/injection1.xsjslib:8:15:8:106 | "INSERT ... 2 + ")" | | ||
| lib/injection1.xsjslib:8:82:8:100 | someParameterValue2 | lib/injection1.xsjslib:8:15:8:106 | "INSERT ... 2 + ")" | | ||
#select | ||
| lib/injection1.xsjslib:11:57:11:61 | query | lib/injection1.xsjslib:6:40:6:78 | request ... eter1") | lib/injection1.xsjslib:11:57:11:61 | query | This query depends on a $@. | lib/injection1.xsjslib:6:40:6:78 | request ... eter1") | user-provided value | | ||
| lib/injection1.xsjslib:11:57:11:61 | query | lib/injection1.xsjslib:7:40:7:78 | request ... eter2") | lib/injection1.xsjslib:11:57:11:61 | query | This query depends on a $@. | lib/injection1.xsjslib:7:40:7:78 | request ... eter2") | user-provided value | |
1 change: 1 addition & 0 deletions
1
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/XSJSLibSqlInjection.qlref
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 @@ | ||
XSJSSqlInjection/XSJSSqlInjection.ql |
9 changes: 9 additions & 0 deletions
9
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/XSJSLibSqlInjection.xsjs
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,9 @@ | ||
$.import("lib/injection1.xsjslib"); | ||
let t1=$.import("lib/injection2.xsjslib"); | ||
$.import("lib/injection3.xsjslib"); | ||
$.import("lib/injection4.xsjslib"); | ||
|
||
var requestParameters = $.request.parameters; | ||
|
||
test1(requestParameters); | ||
t1.test1(requestParameters); |
14 changes: 14 additions & 0 deletions
14
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/lib/injection1.xsjslib
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,14 @@ | ||
/** | ||
* True positive case: Sink being `$.db.Connection.prepareStatement(query, arguments...)`, | ||
* the API in the older namespace. The remote value is concatenated raw into the query. | ||
*/ | ||
function test1(requestParameters) { | ||
let someParameterValue1 = JSON.parse(requestParameters.get("someParameter1")); | ||
let someParameterValue2 = JSON.parse(requestParameters.get("someParameter2")); | ||
let query = "INSERT INTO " + someParameterValue1 + ".ENTITY (COL1) VALUES (" + someParameterValue2 + ")"; | ||
|
||
let dbConnection = $.db.getConnection(); | ||
let preparedStatement = dbConnection.prepareStatement(query); | ||
preparedStatement.executeUpdate(); | ||
dbConnection.commit(); | ||
} |
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 |
---|---|---|
|
@@ -36,3 +36,16 @@ function test3(requestParameters) { | |
test1(requestParameters); | ||
test2(requestParameters); | ||
test3(requestParameters); | ||
|
||
/** | ||
* False positive case: the value is sanitized | ||
*/ | ||
var xssSecure = $.require('@sap/xss-secure'); | ||
function test4(requestParameters) { | ||
let someParameterValue4 = requestParameters.get("someParameter4"); | ||
$.response.contentType = "text/html"; | ||
$.response.setBody(requestParameterHandler(xssSecure.encodeHTML(someParameterValue4))); | ||
Check failureCode scanning / CodeQL XSJS Reflected XSS High test
Reflected XSS vulnerability due to user-provided value.
|
||
$.response.status = $.net.http.OK; | ||
} | ||
|
||
test4(requestParameters); |
Oops, something went wrong.
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.