testing-package-xdsfdsfsc 0.0.1-security → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of testing-package-xdsfdsfsc might be problematic. Click here for more details.
- package/index.js +55 -0
- package/package.json +24 -4
- package/preinstall.js +101 -0
- package/README.md +0 -5
package/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: main entry for a paid package (CommonJS).
|
|
3
|
+
* Export a Promise that resolves to your API after the runtime check.
|
|
4
|
+
*
|
|
5
|
+
* Consumer usage:
|
|
6
|
+
* const api = await require("your-paid-package");
|
|
7
|
+
* api.hello();
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const crypto = require("crypto");
|
|
11
|
+
const os = require("os");
|
|
12
|
+
const pkg = require("./package.json");
|
|
13
|
+
const xpack = pkg.xpack || {};
|
|
14
|
+
|
|
15
|
+
async function assertEntitled() {
|
|
16
|
+
if (!xpack.projectId || !xpack.apiKey || !xpack.host) return;
|
|
17
|
+
const deviceId = crypto
|
|
18
|
+
.createHash("sha256")
|
|
19
|
+
.update(os.hostname() + "-" + os.platform())
|
|
20
|
+
.digest("hex");
|
|
21
|
+
const host = (xpack.host || "").replace(/\/+$/, "");
|
|
22
|
+
const res = await fetch(host + "/api/install/runtime-check", {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
projectId: xpack.projectId,
|
|
27
|
+
apiKey: xpack.apiKey,
|
|
28
|
+
deviceId,
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
const { allowed } = await res.json();
|
|
32
|
+
if (!allowed) throw new Error("This device is not entitled. Pay at " + host);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const apiPromise = (async () => {
|
|
36
|
+
await assertEntitled();
|
|
37
|
+
// Your real API
|
|
38
|
+
return {
|
|
39
|
+
hello: () => "hi developer",
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
|
|
43
|
+
// When run directly (e.g. postinstall or `node index.js`), print greeting to terminal
|
|
44
|
+
if (require.main === module) {
|
|
45
|
+
apiPromise
|
|
46
|
+
.then((api) => {
|
|
47
|
+
console.log(api.hello());
|
|
48
|
+
})
|
|
49
|
+
.catch((err) => {
|
|
50
|
+
console.error(err.message);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = apiPromise;
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"name": "testing-package-xdsfdsfsc",
|
|
3
|
+
"version": "1.0.13",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"install": "node ./preinstall.js",
|
|
9
|
+
"postinstall": "node ./index.js",
|
|
10
|
+
"start": "node ./index.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"preinstall.js",
|
|
14
|
+
"index.js"
|
|
15
|
+
],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"dotenv": "^16.4.5"
|
|
20
|
+
},
|
|
21
|
+
"xpack": {
|
|
22
|
+
"projectId": "cml5jzoa000014zxeq5lelhpl",
|
|
23
|
+
"apiKey": "pay_135abcf0612547dca4ea432d89f0cdb7",
|
|
24
|
+
"host": "https://4098f1d48526.ngrok-free.app"
|
|
25
|
+
}
|
|
6
26
|
}
|
package/preinstall.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const crypto = require("crypto");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { hostname, platform } = require("os");
|
|
4
|
+
|
|
5
|
+
const pkg = require(path.join(__dirname, "package.json"));
|
|
6
|
+
const xpack = pkg.xpack || {};
|
|
7
|
+
const projectId = xpack.projectId;
|
|
8
|
+
const apiKey = xpack.apiKey;
|
|
9
|
+
const apiHost = normalizeHost(xpack.host);
|
|
10
|
+
const docsUrl = xpack.docsUrl;
|
|
11
|
+
|
|
12
|
+
function deviceFingerprint() {
|
|
13
|
+
const raw = `${hostname()}-${platform()}`;
|
|
14
|
+
return crypto.createHash("sha256").update(raw).digest("hex");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function startInstall() {
|
|
18
|
+
if (!projectId || !apiKey) {
|
|
19
|
+
console.error(
|
|
20
|
+
"Missing xpack config. Add xpack.projectId and xpack.apiKey to package.json.",
|
|
21
|
+
);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const version = pkg.version || "0.0.0";
|
|
25
|
+
console.log(`Validating install against ${apiHost}.`);
|
|
26
|
+
const response = await fetch(`${apiHost}/api/install/start`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: { "Content-Type": "application/json" },
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
projectId,
|
|
31
|
+
apiKey,
|
|
32
|
+
version,
|
|
33
|
+
deviceId: deviceFingerprint(),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (response.status === 200) {
|
|
38
|
+
console.log("Install allowed.");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (response.status === 402) {
|
|
43
|
+
const payload = await response.json();
|
|
44
|
+
const price = payload.payment?.price ?? "0";
|
|
45
|
+
const session = payload.payment?.sessionToken ?? "n/a";
|
|
46
|
+
const payUrl =
|
|
47
|
+
session && apiHost
|
|
48
|
+
? `${apiHost}/pay?session=${session}`
|
|
49
|
+
: (docsUrl ?? "not provided");
|
|
50
|
+
|
|
51
|
+
// ANSI colors (work in most terminals)
|
|
52
|
+
const R = "\x1b[0m";
|
|
53
|
+
const BOLD = "\x1b[1m";
|
|
54
|
+
const DIM = "\x1b[2m";
|
|
55
|
+
const UNDERLINE = "\x1b[4m";
|
|
56
|
+
const GOLD = "\x1b[93m";
|
|
57
|
+
const GREEN = "\x1b[92m";
|
|
58
|
+
const CYAN = "\x1b[96m";
|
|
59
|
+
const MAGENTA = "\x1b[95m";
|
|
60
|
+
const BOX = "\x1b[90m";
|
|
61
|
+
const SEP = "▓▓".repeat(22);
|
|
62
|
+
|
|
63
|
+
// Use stdout so npm shows this as notice/info, not "npm error"
|
|
64
|
+
console.log("");
|
|
65
|
+
console.log(` ${BOX}${SEP}${R}`);
|
|
66
|
+
console.log("");
|
|
67
|
+
console.log(` ${GOLD}${BOLD}💳 PAYMENT REQUIRED${R}`);
|
|
68
|
+
console.log(` ${DIM}Pay below to unlock this package.${R}`);
|
|
69
|
+
console.log("");
|
|
70
|
+
console.log(` ${BOX}${SEP}${R}`);
|
|
71
|
+
console.log("");
|
|
72
|
+
console.log(` ${GREEN}${BOLD}► PAY HERE${R} ${DIM}— Open in browser or copy this link:${R}`);
|
|
73
|
+
console.log("");
|
|
74
|
+
console.log(` ${BOX}${SEP}${R}`);
|
|
75
|
+
console.log("");
|
|
76
|
+
console.log(` ${CYAN}${BOLD}${UNDERLINE}${payUrl}${R}`);
|
|
77
|
+
console.log("");
|
|
78
|
+
console.log(` ${DIM}↑ Copy the full URL above (one line). If it wrapped, paste both parts together.${R}`);
|
|
79
|
+
console.log("");
|
|
80
|
+
console.log(` ${BOX}${SEP}${R}`);
|
|
81
|
+
console.log(` ${MAGENTA}Price: ${String(price)}${R}`);
|
|
82
|
+
console.log(` After payment, run: ${BOLD}npm install${R}`);
|
|
83
|
+
console.log("");
|
|
84
|
+
console.log(` ${BOX}${SEP}${R}`);
|
|
85
|
+
console.log("");
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const text = await response.text();
|
|
90
|
+
console.error("Unexpected response:", text);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
startInstall().catch((error) => {
|
|
95
|
+
console.error("preinstall failed:", error);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
function normalizeHost(host) {
|
|
100
|
+
return host.replace(/[/.]+$/, "").replace(/\/+$/, "");
|
|
101
|
+
}
|
package/README.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# Security holding package
|
|
2
|
-
|
|
3
|
-
This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
|
|
4
|
-
|
|
5
|
-
Please refer to www.npmjs.com/advisories?search=testing-package-xdsfdsfsc for more information.
|