win-cliauth 1.0.4 → 1.0.5
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.
- package/dist/src/pshell.js +25 -5
- package/package.json +13 -11
package/dist/src/pshell.js
CHANGED
|
@@ -7,15 +7,33 @@ This source code is licensed under the BSD-style license found in the
|
|
|
7
7
|
LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.powershellEnv = powershellEnv;
|
|
11
|
+
exports.readableError = readableError;
|
|
10
12
|
exports.encrypt = encrypt;
|
|
11
13
|
exports.decrypt = decrypt;
|
|
12
14
|
const child_process_1 = require("child_process");
|
|
15
|
+
// Windows PowerShell must not inherit PowerShell 7's module path (set when win-cliauth runs from pwsh),
|
|
16
|
+
// or it fails to load its own modules such as Microsoft.PowerShell.Security.
|
|
17
|
+
function powershellEnv(env = process.env) {
|
|
18
|
+
return Object.fromEntries(Object.entries(env).filter(([key]) => key.toUpperCase() !== 'PSMODULEPATH'));
|
|
19
|
+
}
|
|
20
|
+
// Turns PowerShell's serialized "#< CLIXML" error output into plain text.
|
|
21
|
+
function readableError(stderr) {
|
|
22
|
+
if (!stderr.startsWith('#< CLIXML'))
|
|
23
|
+
return stderr;
|
|
24
|
+
const errors = [...stderr.matchAll(/<S S="Error">([\s\S]*?)<\/S>/g)].map(([, text]) => text);
|
|
25
|
+
return errors
|
|
26
|
+
.join('')
|
|
27
|
+
.replace(/_x000D__x000A_/g, '\n')
|
|
28
|
+
.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, '&')
|
|
29
|
+
.trim() || stderr;
|
|
30
|
+
}
|
|
13
31
|
// Secrets never appear in the script text (which is visible in process listings):
|
|
14
32
|
// they travel through stdin/stdout as base64-encoded UTF-8.
|
|
15
33
|
function pshell({ script, input = '' }) {
|
|
16
|
-
const encoded = Buffer.from(`$ErrorActionPreference = 'Stop'\n${script}`, 'utf16le').toString('base64');
|
|
34
|
+
const encoded = Buffer.from(`$ErrorActionPreference = 'Stop'\n$ProgressPreference = 'SilentlyContinue'\n${script}`, 'utf16le').toString('base64');
|
|
17
35
|
return new Promise((resolve, reject) => {
|
|
18
|
-
const ps = (0, child_process_1.spawn)('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], { stdio: 'pipe', windowsHide: true });
|
|
36
|
+
const ps = (0, child_process_1.spawn)('powershell.exe', ['-NoProfile', '-NonInteractive', '-OutputFormat', 'Text', '-EncodedCommand', encoded], { stdio: 'pipe', windowsHide: true, env: powershellEnv() });
|
|
19
37
|
let stdout = '';
|
|
20
38
|
let stderr = '';
|
|
21
39
|
ps.stdout.on('data', (chunk) => (stdout += chunk));
|
|
@@ -24,7 +42,7 @@ function pshell({ script, input = '' }) {
|
|
|
24
42
|
ps.on('close', (code) => {
|
|
25
43
|
if (code === 0)
|
|
26
44
|
return resolve(stdout.trim());
|
|
27
|
-
reject(new Error(stderr.trim() || `PowerShell exited with code ${code}`));
|
|
45
|
+
reject(new Error(readableError(stderr.trim()) || `PowerShell exited with code ${code}`));
|
|
28
46
|
});
|
|
29
47
|
ps.stdin.end(input);
|
|
30
48
|
});
|
|
@@ -60,10 +78,12 @@ async function decrypt() {
|
|
|
60
78
|
}
|
|
61
79
|
`,
|
|
62
80
|
});
|
|
81
|
+
// null prototype: names like "toString" or "__proto__" are plain keys, not inherited properties
|
|
82
|
+
const vault = Object.create(null);
|
|
63
83
|
if (!output)
|
|
64
|
-
return
|
|
84
|
+
return vault;
|
|
65
85
|
try {
|
|
66
|
-
return JSON.parse(Buffer.from(output, 'base64').toString('utf8'));
|
|
86
|
+
return Object.assign(vault, JSON.parse(Buffer.from(output, 'base64').toString('utf8')));
|
|
67
87
|
}
|
|
68
88
|
catch {
|
|
69
89
|
throw new Error('The key file is corrupted (a backup may exist at %AppData%\\win-cliauth\\keys.bak).');
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "win-cliauth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "win-cliauth is a CLI-based OTP (One-Time Password) authenticator management tool for Windows.",
|
|
5
5
|
"author": "Pedro Lucas Magalhães <pedrolucasmag@gmail.com>",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"lint": "eslint .
|
|
9
|
+
"lint": "eslint .",
|
|
10
10
|
"test": "tsc && node --test \"dist/test/**/*.test.js\"",
|
|
11
|
+
"prepare": "husky",
|
|
11
12
|
"prepack": "tsc"
|
|
12
13
|
},
|
|
13
14
|
"bin": {
|
|
@@ -23,15 +24,16 @@
|
|
|
23
24
|
"!dist/test"
|
|
24
25
|
],
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@commitlint/cli": "^
|
|
27
|
-
"@commitlint/config-conventional": "^
|
|
28
|
-
"@
|
|
27
|
+
"@commitlint/cli": "^21.2.3",
|
|
28
|
+
"@commitlint/config-conventional": "^21.2.3",
|
|
29
|
+
"@eslint/js": "^10.0.1",
|
|
30
|
+
"@types/node": "^20.19.0",
|
|
29
31
|
"@types/yargs": "^17.0.10",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"typescript": "^
|
|
32
|
+
"eslint": "^10.12.0",
|
|
33
|
+
"globals": "^17.13.0",
|
|
34
|
+
"husky": "^9.1.7",
|
|
35
|
+
"typescript": "^5.4.0",
|
|
36
|
+
"typescript-eslint": "^8.71.1"
|
|
35
37
|
},
|
|
36
38
|
"os": [
|
|
37
39
|
"win32"
|
|
@@ -51,6 +53,6 @@
|
|
|
51
53
|
"yargs": "^17.5.1"
|
|
52
54
|
},
|
|
53
55
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
56
|
+
"node": ">=20"
|
|
55
57
|
}
|
|
56
58
|
}
|