Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/NodeSecure/js-x-ray
JavaScript & Node.js open-source SAST scanner. A static analyser for detecting most common malicious patterns π¬.
https://github.com/NodeSecure/js-x-ray
ast ast-analysis javascript nodejs sast security security-audit security-tools supply-chain-security
Last synced: 28 days ago
JSON representation
JavaScript & Node.js open-source SAST scanner. A static analyser for detecting most common malicious patterns π¬.
- Host: GitHub
- URL: https://github.com/NodeSecure/js-x-ray
- Owner: NodeSecure
- License: mit
- Created: 2020-03-26T21:15:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-11-01T09:27:55.000Z (about 1 month ago)
- Last Synced: 2024-11-12T01:24:18.038Z (about 1 month ago)
- Topics: ast, ast-analysis, javascript, nodejs, sast, security, security-audit, security-tools, supply-chain-security
- Language: JavaScript
- Homepage:
- Size: 1.15 MB
- Stars: 229
- Watchers: 5
- Forks: 26
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-nodejs-security - js-x-ray - JavaScript and Node.js SAST scanner capable of detecting various well-known malicious code patterns (Unsafe import, Unsafe stmt, Unsafe RegEx, encoded literals, minified and obfuscated codes). (Static Code Analysis)
- awesome-hacking-lists - NodeSecure/js-x-ray - JavaScript & Node.js open-source SAST scanner. A static analyser for detecting most common malicious patterns π¬. (JavaScript)
README
JavaScript AST analysis. This package has been created to export the [NodeSecure](https://github.com/NodeSecure/cli) AST Analysis to enable better code evolution and allow better access to developers and researchers.
The goal is to quickly identify dangerous code and patterns for developers and Security researchers. Interpreting the results of this tool will still require you to have a set of security notions.
## Goals
The objective of the project is to successfully detect all potentially suspicious JavaScript codes.. The target is obviously codes that are added or injected for malicious purposes..Most of the time these hackers will try to hide the behaviour of their codes as much as possible to avoid being spotted or easily understood... The work of the library is to understand and analyze these patterns that will allow us to detect malicious code..
## Features Highlight
- Retrieve required dependencies and files for Node.js.
- Detect unsafe RegEx.
- Get warnings when the AST Analysis as a problem or when not able to follow a statement.
- Highlight common attack patterns and API usages.
- Capable to follow the usage of dangerous Node.js globals.
- Detect obfuscated code and when possible the tool that has been used.## Getting Started
This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
```bash
$ npm i @nodesecure/js-x-ray
# or
$ yarn add @nodesecure/js-x-ray
```## Usage example
Create a local `.js` file with the following content:
```js
try {
require("http");
}
catch (err) {
// do nothing
}
const lib = "crypto";
require(lib);
require("util");
require(Buffer.from("6673", "hex").toString());
```---
Then use `js-x-ray` to run an analysis of the JavaScript code:
```js
import { AstAnalyser } from "@nodesecure/js-x-ray";
import { readFileSync } from "node:fs";const scanner = new AstAnalyser();
const { warnings, dependencies } = await scanner.analyseFile(
"./file.js"
);console.log(dependencies);
console.dir(warnings, { depth: null });
```The analysis will return: `http` (in try), `crypto`, `util` and `fs`.
> [!TIP]
> There is also a lot of suspicious code example in the `./examples` cases directory. Feel free to try the tool on these files.## API
- [AstAnalyser](./docs/api/AstAnalyser.md)
- [EntryFilesAnalyser](./docs/api/EntryFilesAnalyser.md)## Warnings
This section describes how use `warnings` export.
```ts
type WarningName = "parsing-error"
| "encoded-literal"
| "unsafe-regex"
| "unsafe-stmt"
| "short-identifiers"
| "suspicious-literal"
| "suspicious-file"
| "obfuscated-code"
| "weak-crypto"
| "unsafe-import"
| "shady-link";declare const warnings: Record;
```We make a call to `i18n` through the package `NodeSecure/i18n` to get the translation.
```js
import * as jsxray from "@nodesecure/js-x-ray";
import * as i18n from "@nodesecure/i18n";console.log(i18n.getTokenSync(jsxray.warnings["parsing-error"].i18n));
```### Legends
This section describe all the possible warnings returned by JSXRay. Click on the warning **name** for additional information and examples.
| name | experimental | description |
| --- | :-: | --- |
| [parsing-error](./docs/parsing-error.md) | β | The AST parser throw an error |
| [unsafe-import](./docs/unsafe-import.md) | β | Unable to follow an import (require, require.resolve) statement/expr. |
| [unsafe-regex](./docs/unsafe-regex.md) | β | A RegEx as been detected as unsafe and may be used for a ReDoS Attack. |
| [unsafe-stmt](./docs//unsafe-stmt.md) | β | Usage of dangerous statement like `eval()` or `Function("")`. |
| [encoded-literal](./docs/encoded-literal.md) | β | An encoded literal has been detected (it can be an hexa value, unicode sequence or a base64 string) |
| [short-identifiers](./docs/short-identifiers.md) | β | This mean that all identifiers has an average length below 1.5. |
| [suspicious-literal](./docs/suspicious-literal.md) | β | A suspicious literal has been found in the source code. |
| [suspicious-file](./docs/suspicious-file.md) | β | A suspicious file with more than ten encoded-literal in it |
| [obfuscated-code](./docs/obfuscated-code.md) | βοΈ | There's a very high probability that the code is obfuscated. |
| [weak-crypto](./docs/weak-crypto.md) | β | The code probably contains a weak crypto algorithm (md5, sha1...) |
| [shady-link](./docs/shady-link.md) | β | The code contains shady/unsafe link |## Workspaces
Click on one of the links to access the documentation of the workspace:
| name | package and link |
| --- | --- |
| estree-ast-utils | [@nodesecure/estree-ast-utils](./workspaces/estree-ast-utils) |
| sec-literal | [@nodesecure/sec-literal ](./workspaces/sec-literal) |
| ts-source-parser | [@nodesecure/ts-source-parser ](./workspaces/ts-source-parser) |These packages are available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
```bash
$ npm i @nodesecure/estree-ast-util
# or
$ yarn add @nodesecure/estree-ast-util
```## Contributors β¨
[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors-)
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Gentilhomme
π» π π π‘οΈ π
Nicolas Hallaert
π
Antoine
π»
Mathieu
π»
Vincent Dhennin
π» β οΈ
Tony Gorez
π» π β οΈ
PierreD
β οΈ π»
Franck Hallaert
π»
Maji
π»
MichaΓ«l Zasso
π» π
Kouadio Fabrice Nguessan
π§ π»
Jean
β οΈ π» π
tchapacan
π» β οΈ
mkarkkainen
π»
FredGuiou
π π»
Madina
π»
SairussDev
π»
Abdou-Raouf ATARMLA
π»
## License
MIT