-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
179 additions
and
16 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
61 changes: 61 additions & 0 deletions
61
...cript/frameworks/xsjs/lib/advanced_security/javascript/frameworks/xsjs/XSJSLibModules.qll
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,61 @@ | ||
/** Provides classes for working with XSJSLib modules. */ | ||
|
||
import javascript | ||
|
||
/** | ||
* An XSJSLib module. | ||
*/ | ||
class XSJSModule extends Module { | ||
XSJSModule() { this.getFile().getExtension() = ["xsjs", "xsjslib"] } | ||
|
||
/** | ||
* Get a value that is explicitly exported from this module with under `name`. | ||
*/ | ||
override DataFlow::ValueNode getAnExportedValue(string name) { | ||
exists(FunctionDeclStmt fds | | ||
fds.getParent() = this.getTopLevel() and | ||
fds.getName() = name and | ||
result.getAstNode() = fds | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* An XSJSLib module import declaration. | ||
* ``` | ||
* $.import("module.xsjslib"); | ||
* ``` | ||
*/ | ||
class XSJSImportExpr extends CallExpr, Import { | ||
XSJSImportExpr() { | ||
this.getReceiver().(GlobalVarAccess).getName() = "$" and | ||
this.getFile().getExtension() = ["xsjs", "xsjslib"] and | ||
this.getCalleeName() = "import" | ||
} | ||
|
||
override XSJSModule getEnclosingModule() { result = this.getTopLevel() } | ||
|
||
override PathExpr getImportedPath() { result = this.getLastArgument() } | ||
|
||
override DataFlow::Node getImportedModuleNode() { result = DataFlow::valueNode(this) } | ||
} | ||
|
||
private class XSJSModuleImportPath extends PathExpr, ConstantString { | ||
XSJSModuleImportPath() { this = any(XSJSImportExpr e).getLastArgument() } | ||
|
||
override Folder getSearchRoot(int priority) { | ||
priority = 0 and | ||
result = this.getFile().getParentContainer() | ||
} | ||
|
||
override string getValue() { | ||
exists(XSJSImportExpr e | | ||
this = e.getArgument(0) and result = this.getStringValue() | ||
or | ||
this = e.getArgument(1) and | ||
result = | ||
e.getArgument(0).getStringValue().replaceAll(".", "/") + "/" + this.getStringValue() + | ||
".xsjslib" | ||
) | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
javascript/frameworks/xsjs/test/models/modules/npm/npm.expected
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,2 @@ | ||
| npm.xsjs:3:14:3:71 | crypto. ... 1024 }) | | ||
| npm.xsjs:5:15:5:72 | crypto. ... 4096 }) | |
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,4 @@ | ||
import javascript | ||
|
||
from CryptographicKeyCreation crypto | ||
select crypto |
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,5 @@ | ||
const crypto = $.require("crypto"); | ||
|
||
const bad1 = crypto.generateKeyPairSync("rsa", { modulusLength: 1024 }); // NOT OK | ||
|
||
const good1 = crypto.generateKeyPairSync("rsa", { modulusLength: 4096 }); // OK |
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
3 changes: 3 additions & 0 deletions
3
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/XSJSLibSqlInjection.expected
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,3 @@ | ||
nodes | ||
edges | ||
#select |
1 change: 1 addition & 0 deletions
1
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/XSJSLibSqlInjection.qlref
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 @@ | ||
XSJSSqlInjection/XSJSSqlInjection.ql |
11 changes: 11 additions & 0 deletions
11
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/XSJSLibSqlInjection.xsjs
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,11 @@ | ||
var requestParameters = $.request.parameters; | ||
var param = JSON.parse(requestParameters.get("param")); | ||
|
||
let t1=$.import("lib/injection1.xsjslib"); | ||
t1.test1(requestParameters); | ||
|
||
$.import("lib/injection2.xsjslib"); | ||
$.lib.injection2.test2(param); | ||
|
||
let t3=$.import("lib.test3","injection3"); | ||
t3.test3(param); |
8 changes: 8 additions & 0 deletions
8
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/lib/injection1.xsjslib
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,8 @@ | ||
function test1(requestParameters) { | ||
let query = "INSERT INTO " + requestParameters + ".ENTITY (COL1) VALUES (" + requestParameters + ")"; | ||
|
||
let dbConnection = $.db.getConnection(); | ||
let preparedStatement = dbConnection.prepareStatement(query); | ||
preparedStatement.executeUpdate(); | ||
dbConnection.commit(); | ||
} |
8 changes: 8 additions & 0 deletions
8
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/lib/injection2.xsjslib
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,8 @@ | ||
function test2(requestParameters) { | ||
let query = "INSERT INTO " + requestParameters + ".ENTITY (COL1) VALUES (" + requestParameters + ")"; | ||
|
||
let dbConnection = $.db.getConnection(); | ||
let preparedStatement = dbConnection.prepareStatement(query); | ||
preparedStatement.executeUpdate(); | ||
dbConnection.commit(); | ||
} |
8 changes: 8 additions & 0 deletions
8
javascript/frameworks/xsjs/test/queries/XSJSLibSqlInjection/lib/test3/injection3.xsjslib
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,8 @@ | ||
function test3(requestParameters) { | ||
let query = "INSERT INTO " + requestParameters + ".ENTITY (COL1) VALUES (" + requestParameters + ")"; | ||
|
||
let dbConnection = $.db.getConnection(); | ||
let preparedStatement = dbConnection.prepareStatement(query); | ||
preparedStatement.executeUpdate(); | ||
dbConnection.commit(); | ||
} |
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