-
Notifications
You must be signed in to change notification settings - Fork 1
Adds support for npm and xsjslib modules #155
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
Open
mbaluda
wants to merge
2
commits into
main
Choose a base branch
from
mbaluda/modules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
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.
Check failure
Code scanning / CodeQL
XSJS Reflected XSS High test