Skip to content

Commit 863d4ab

Browse files
committed
refactor: migrate to NodeSecure org
1 parent 532de80 commit 863d4ab

40 files changed

+2508
-5074
lines changed

.editorconfig

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
# Editor configuration, see https://editorconfig.org
12
root = true
23

34
[*]
4-
indent_size = 4
5-
indent_style = space
6-
end_of_line = lf
75
charset = utf-8
8-
trim_trailing_whitespace = true
6+
indent_style = space
7+
indent_size = 2
98
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
12+
[*.md]
13+
max_line_length = off
14+
trim_trailing_whitespace = false

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
test/fixtures
2-
test/utils
32
cases/
43
temp.js

.eslintrc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"extends": "@slimio/eslint-config",
3-
"rules": {
4-
"jsdoc/require-jsdoc": "off",
5-
"lines-between-class-members": "off"
2+
"extends": "@nodesecure/eslint-config",
3+
"parserOptions": {
4+
"sourceType": "module",
5+
"requireConfigFile": false
66
}
77
}

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# js-x-ray
2-
![version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/fraxken/js-x-ray/master/package.json&query=$.version&label=Version)
3-
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/fraxken/js-x-ray/commit-activity)
2+
![version](https://img.shields.io/badge/dynamic/json.svg?url=https://raw.githubusercontent.com/NodeSecure/js-x-ray/master/package.json&query=$.version&label=Version)
3+
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/NodeSecure/js-x-ray/commit-activity)
44
[![Security Responsible Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/nodejs/security-wg/blob/master/processes/responsible_disclosure_template.md
55
)
6-
[![mit](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/fraxken/js-x-ray/blob/master/LICENSE)
7-
![dep](https://img.shields.io/david/fraxken/js-x-ray)
6+
[![mit](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/NodeSecure/js-x-ray/blob/master/LICENSE)
7+
![dep](https://img.shields.io/david/NodeSecure/js-x-ray)
88
![size](https://img.shields.io/bundlephobia/min/js-x-ray)
99

1010

@@ -32,9 +32,9 @@ Most of the time these hackers will try to hide the behaviour of their codes as
3232
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).
3333

3434
```bash
35-
$ npm i js-x-ray
35+
$ npm i @nodesecure/js-x-ray
3636
# or
37-
$ yarn add js-x-ray
37+
$ yarn add @nodesecure/js-x-ray
3838
```
3939

4040
## Usage example
@@ -57,8 +57,8 @@ require(Buffer.from("6673", "hex").toString());
5757

5858
Then use `js-x-ray` to run an analysis of the JavaScript code:
5959
```js
60-
const { runASTAnalysis } = require("js-x-ray");
61-
const { readFileSync } = require("fs");
60+
import { runASTAnalysis } from "@nodesecure/js-x-ray";
61+
import { readFileSync } from "fs";
6262

6363
const str = readFileSync("./file.js", "utf-8");
6464
const { warnings, dependencies } = runASTAnalysis(str);

babel.config.js

-15
This file was deleted.

index.js

+53-58
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,56 @@
1-
"use strict";
2-
3-
// Require Third-party Dependencies
4-
const { walk } = require("estree-walker");
5-
const meriyah = require("meriyah");
6-
7-
// Require Internal Dependencies
8-
const Analysis = require("./src/Analysis");
9-
10-
function runASTAnalysis(str, options = Object.create(null)) {
11-
const { module = true, isMinified = false } = options;
12-
13-
// Note: if the file start with a shebang then we remove it because 'parseScript' may fail to parse it.
14-
// Example: #!/usr/bin/env node
15-
const strToAnalyze = str.charAt(0) === "#" ? str.slice(str.indexOf("\n")) : str;
16-
const { body } = meriyah.parseScript(strToAnalyze, {
17-
next: true, loc: true, raw: true, module: Boolean(module)
18-
});
19-
20-
const sastAnalysis = new Analysis();
21-
22-
// we walk each AST Nodes, this is a purely synchronous I/O
23-
walk(body, {
24-
enter(node) {
25-
// Skip the root of the AST.
26-
if (Array.isArray(node)) {
27-
return;
28-
}
29-
30-
const action = sastAnalysis.walk(node);
31-
if (action === "skip") {
32-
this.skip();
33-
}
34-
}
35-
});
36-
37-
const dependencies = sastAnalysis.dependencies;
38-
const { idsLengthAvg, stringScore, warnings } = sastAnalysis.getResult(isMinified);
39-
const isOneLineRequire = body.length <= 1 && dependencies.size <= 1;
40-
41-
return {
42-
dependencies, warnings, idsLengthAvg, stringScore, isOneLineRequire
43-
};
1+
// Import Third-party Dependencies
2+
import { walk } from "estree-walker";
3+
import * as meriyah from "meriyah";
4+
5+
// Import Internal Dependencies
6+
import Analysis from "./src/Analysis.js";
7+
8+
export function runASTAnalysis(str, options = Object.create(null)) {
9+
const { module = true, isMinified = false } = options;
10+
11+
// Note: if the file start with a shebang then we remove it because 'parseScript' may fail to parse it.
12+
// Example: #!/usr/bin/env node
13+
const strToAnalyze = str.charAt(0) === "#" ? str.slice(str.indexOf("\n")) : str;
14+
const { body } = meriyah.parseScript(strToAnalyze, {
15+
next: true, loc: true, raw: true, module: Boolean(module)
16+
});
17+
18+
const sastAnalysis = new Analysis();
19+
20+
// we walk each AST Nodes, this is a purely synchronous I/O
21+
walk(body, {
22+
enter(node) {
23+
// Skip the root of the AST.
24+
if (Array.isArray(node)) {
25+
return;
26+
}
27+
28+
const action = sastAnalysis.walk(node);
29+
if (action === "skip") {
30+
this.skip();
31+
}
32+
}
33+
});
34+
35+
const dependencies = sastAnalysis.dependencies;
36+
const { idsLengthAvg, stringScore, warnings } = sastAnalysis.getResult(isMinified);
37+
const isOneLineRequire = body.length <= 1 && dependencies.size <= 1;
38+
39+
return {
40+
dependencies, warnings, idsLengthAvg, stringScore, isOneLineRequire
41+
};
4442
}
4543

46-
module.exports = {
47-
runASTAnalysis,
48-
CONSTANTS: {
49-
Warnings: Object.freeze({
50-
parsingError: "ast-error",
51-
unsafeImport: "unsafe-import",
52-
unsafeRegex: "unsafe-regex",
53-
unsafeStmt: "unsafe-stmt",
54-
unsafeAssign: "unsafe-assign",
55-
encodedLiteral: "encoded-literal",
56-
shortIdentifiers: "short-identifiers",
57-
suspiciousLiteral: "suspicious-literal",
58-
obfuscatedCode: "obfuscated-code"
59-
})
60-
}
44+
export const CONSTANTS = {
45+
Warnings: Object.freeze({
46+
parsingError: "ast-error",
47+
unsafeImport: "unsafe-import",
48+
unsafeRegex: "unsafe-regex",
49+
unsafeStmt: "unsafe-stmt",
50+
unsafeAssign: "unsafe-assign",
51+
encodedLiteral: "encoded-literal",
52+
shortIdentifiers: "short-identifiers",
53+
suspiciousLiteral: "suspicious-literal",
54+
obfuscatedCode: "obfuscated-code"
55+
})
6156
};

jest.setup.js

-2
This file was deleted.

0 commit comments

Comments
 (0)