@pixlcore/xycli 1.2.1 → 1.2.3
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/.github/workflows/docker.yml +1 -0
- package/CHANGELOG.md +73 -0
- package/docs/help.md +2 -0
- package/index.js +7 -5
- package/lib/categories.js +1 -1
- package/lib/config.js +41 -3
- package/lib/groups.js +1 -1
- package/lib/plugins.js +1 -1
- package/lib/sync-buckets.js +2 -2
- package/lib/sync-syshook.js +2 -2
- package/lib/sync.js +17 -5
- package/lib/transfer.js +2 -1
- package/lib/upgrade.js +7 -1
- package/lib/utils.js +7 -2
- package/lib/webhook.js +1 -1
- package/package.json +4 -4
- package/test/config.test.js +62 -3
- package/test/secure-json-unit.test.js +140 -0
- package/test/sync-syshook-unit.test.js +21 -0
- package/test/sync-unit.test.js +26 -0
- package/test/utils-unit.test.js +25 -0
- package/tools/changelog.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
1
|
# xyCLI Changelog
|
|
2
2
|
|
|
3
|
+
## Version v1.2.2
|
|
4
|
+
|
|
5
|
+
> November 2, 2026
|
|
6
|
+
|
|
7
|
+
- [`660ba0a`](https://github.com/pixlcore/xycli/commit/660ba0afe7187d97313ca9bf9260a1db64a377cb): Version 1.2.2
|
|
8
|
+
- [`b302242`](https://github.com/pixlcore/xycli/commit/b3022422a340e088f4bab89bbaece233addd94b3): Fix: Reject unsupported config keys with typo suggestions
|
|
9
|
+
- [`b7973a9`](https://github.com/pixlcore/xycli/commit/b7973a9ad1cead3b746bd304feb3193abeb59b28): Meta: Add flag to force fresh pull of base docker image on GH actions build.
|
|
10
|
+
|
|
11
|
+
## Version v1.2.1
|
|
12
|
+
|
|
13
|
+
> October 29, 2026
|
|
14
|
+
|
|
15
|
+
- [`c5b6e1c`](https://github.com/pixlcore/xycli/commit/c5b6e1c43296ba8d58d68ebee245b7d27dc4fbfb): Version 1.2.1
|
|
16
|
+
- [`a2fca91`](https://github.com/pixlcore/xycli/commit/a2fca9138e5748d70b1e139b6d0b84f082ec7406): Feature: Follow live job retries automatically
|
|
17
|
+
- [`6b3686d`](https://github.com/pixlcore/xycli/commit/6b3686d18c72139e32d18e1c90e10f8910565224): Feature: Set custom process title for MCP server.
|
|
18
|
+
- [`099444b`](https://github.com/pixlcore/xycli/commit/099444bd87765c1a1e97a65bae6a2b2ea7f4f757): Add LICENSE.md file
|
|
19
|
+
- [`2d6c1c4`](https://github.com/pixlcore/xycli/commit/2d6c1c44a73e265fba38b4feb1c2a7aaea843487): Meta: Fix offline test trigger to only run on tag pushes
|
|
20
|
+
|
|
21
|
+
## Version v1.2.0
|
|
22
|
+
|
|
23
|
+
> October 25, 2026
|
|
24
|
+
|
|
25
|
+
- [`3f99851`](https://github.com/pixlcore/xycli/commit/3f9985186f3cba6e04c2fb0cc7b6eae3a7fc7fcb): Fix Windows MCP shutdown tests and update Node.js CI matrix
|
|
26
|
+
- [`2034c48`](https://github.com/pixlcore/xycli/commit/2034c48626f999ffb969d4cebb7343cb233d565d): Version 1.2.0
|
|
27
|
+
- [`e9693fb`](https://github.com/pixlcore/xycli/commit/e9693fbc527135b45ac2fc39659adb96923d9272): Feature: Expand MCP tools with tickets, alerts, snapshots and servers
|
|
28
|
+
- [`1c12b76`](https://github.com/pixlcore/xycli/commit/1c12b76b747d97ccf358501d438e6deb8b97ca4e): Feature: Add Docker image and automated GHCR publishing for xyCLI
|
|
29
|
+
- [`fa33af6`](https://github.com/pixlcore/xycli/commit/fa33af6b793786da33d6ae0bf832bcdea182e6b0): Feature: Add MCP server with shared STDIO and HTTP transports
|
|
30
|
+
|
|
31
|
+
## Version v1.1.1
|
|
32
|
+
|
|
33
|
+
> October 2, 2026
|
|
34
|
+
|
|
35
|
+
- [`5f924c6`](https://github.com/pixlcore/xycli/commit/5f924c69ad8c5ed3c04be40d600b95fa3eee5f66): Version 1.1.1
|
|
36
|
+
- [`759f8db`](https://github.com/pixlcore/xycli/commit/759f8db93f1763b7e876d16066b7dd04a9681ec3): Doc: Update xyOps version to v1.1.4 in two-way delete tutorial, and add in sys activity exclusions.
|
|
37
|
+
- [`551be24`](https://github.com/pixlcore/xycli/commit/551be2413b4e584daebb2ed57710a620a7006372): Dep: Override "basic-ftp" (sub-sub-sub-sub-dep of pixl-request) to v6.2.1 for vuln fix, that isn't fixed in any of the parents.
|
|
38
|
+
|
|
39
|
+
## Version v1.1.0
|
|
40
|
+
|
|
41
|
+
> September 30, 2026
|
|
42
|
+
|
|
43
|
+
- [`50ff6e6`](https://github.com/pixlcore/xycli/commit/50ff6e6f5f11a29287bcf0ffe2d8f7d966d34ee3): Version 1.1.0
|
|
44
|
+
- [`5bf07a8`](https://github.com/pixlcore/xycli/commit/5bf07a87cfdc649abd8058c10f73c44b037c8cf4): Fix ticket unit test (due to API key bug fix over in xyOps)
|
|
45
|
+
- [`5493608`](https://github.com/pixlcore/xycli/commit/5493608d71dbf8cfd9fbb3f2fef958d1bb107ee1): Feature: Down-sync delete mode, and a new two-way delete setup tut.
|
|
46
|
+
|
|
47
|
+
## Version v1.0.9
|
|
48
|
+
|
|
49
|
+
> September 28, 2026
|
|
50
|
+
|
|
51
|
+
- [`9cbc6c7`](https://github.com/pixlcore/xycli/commit/9cbc6c753e9351243e13a942a3ad19c2012884cb): Version 1.0.9
|
|
52
|
+
- [`6a0d739`](https://github.com/pixlcore/xycli/commit/6a0d739c3d85f61758bc9ea25c77a3b00968c79d): Feature: New system hook (syshook) deletion system, for active deletes from xyOps.
|
|
53
|
+
- [`eeae786`](https://github.com/pixlcore/xycli/commit/eeae7863361c1f343dedae301a00d99db3fccdbb): Feature: New "--ignore_missing" parameter to suppress missing item warnings. Fixes #9
|
|
54
|
+
- [`80e77d4`](https://github.com/pixlcore/xycli/commit/80e77d40edfdb1c7fb4285235c6cc9fb2f0bcb2a): Bug Fix: Always print all errors and warnings, even in quiet mode. Fixes #8
|
|
55
|
+
|
|
56
|
+
## Version v1.0.8
|
|
57
|
+
|
|
58
|
+
> September 25, 2026
|
|
59
|
+
|
|
60
|
+
- [`3cc0914`](https://github.com/pixlcore/xycli/commit/3cc0914dd00211e6215ef3f2e5f7b2467570c9d0): Version 1.0.8
|
|
61
|
+
- [`04d0f31`](https://github.com/pixlcore/xycli/commit/04d0f31eaee9b89bb5f2518c9bf813d24b5235eb): Meta: Fix offline unit tests on Windows (was using colon in filename)
|
|
62
|
+
- [`5570628`](https://github.com/pixlcore/xycli/commit/557062875ab99a4cca41ae419204bc4992962ef1): Bug Fix: Remove some redundant dry run toasts.
|
|
63
|
+
- [`536685e`](https://github.com/pixlcore/xycli/commit/536685eae72bc9bea1be24f4ba7e4998f17386fb): Feature: Allow buckets, bucket data and bucket files to all be synced. Fixes #6
|
|
64
|
+
- [`3cc2ccb`](https://github.com/pixlcore/xycli/commit/3cc2ccb93202bce52de6fe09dead7854ca274640): Docs: Added instructions for deleting items with two-way sync
|
|
65
|
+
- [`38d336b`](https://github.com/pixlcore/xycli/commit/38d336b20797e435664924623e94d877a74c3c0a): Bug Fix: Allow unknown object properties to sync without error (i.e. for legacy Cronicle imports).
|
|
66
|
+
- [`dc1e994`](https://github.com/pixlcore/xycli/commit/dc1e994c3b55eb4040210c8882cf01cd47b0defb): Bug FIx: For printing Emoji, do not use cursor save/restore width-fix when stdout is not a TTY.
|
|
67
|
+
|
|
68
|
+
## Version v1.0.7
|
|
69
|
+
|
|
70
|
+
> September 23, 2026
|
|
71
|
+
|
|
72
|
+
- [`0cce2eb`](https://github.com/pixlcore/xycli/commit/0cce2eb70bc3f17e54fb19c8db43ce937701b68c): Version 1.0.7
|
|
73
|
+
- [`4089e78`](https://github.com/pixlcore/xycli/commit/4089e78e9dc67894afa9d5c325af0e7c37e762a6): Bug Fix: Typo in custom job user HTML content when trying to rendering the caption. Fixes #7.
|
|
74
|
+
- [`76a247c`](https://github.com/pixlcore/xycli/commit/76a247c9abadeb9ee6f9c7bfb89d06cd375c41dd): Feature: Sync: Support workflow node sub-property neighbor files. Fixes #5.
|
|
75
|
+
|
|
3
76
|
## Version v1.0.6
|
|
4
77
|
|
|
5
78
|
> September 22, 2026
|
package/docs/help.md
CHANGED
|
@@ -394,6 +394,8 @@ xy config --base_url http://localhost:5522 --api_key YOUR_API_KEY
|
|
|
394
394
|
|
|
395
395
|
Updates load the user file separately and apply only the settings specified on the command line, preserving other user settings. System settings and environment overrides are not copied into the file. If the user file does not exist, it is created with only the supplied settings.
|
|
396
396
|
|
|
397
|
+
Unknown top-level configuration keys are rejected before saving any changes, with a spelling suggestion when available. Use underscores in names such as `--base_url` and `--api_key`. Structured settings still support nested updates, such as `xy config --sync.down false` or `xy config --mcp.port 8080`.
|
|
398
|
+
|
|
397
399
|
Configuration loads the machine file first, then the user file, then `XYOPS_`-prefixed environment variables. The machine and user files are `/etc/xyops/cli.json` and `~/.config/xyops/cli.json` on Unix and macOS, or `%PROGRAMDATA%\xyops\cli.json` and `%USERPROFILE%\.config\xyops\cli.json` on Windows. Later sources override matching top-level settings. Environment overrides still take precedence over saved user settings. Common keys include `api_key`, `base_url`, `temp_dir`, `color`, `suggest`, `items_per_page`, `cache_ttl`, `raw`, and `invisible`.
|
|
398
400
|
|
|
399
401
|
Environment values that look like JSON objects or arrays are parsed automatically for any setting. For example, `XYOPS_SYNC='{"up":["events"],"down":false}'` supplies a structured `sync` setting. Boolean and numeric values keep their usual conversions. Malformed JSON-looking values report the environment variable name. Objects and arrays are serialized as JSON when the CLI exports its effective configuration back into the environment.
|
package/index.js
CHANGED
|
@@ -203,7 +203,8 @@ const app = {
|
|
|
203
203
|
delete args.format;
|
|
204
204
|
|
|
205
205
|
this.raw = args.raw || this.config.raw || false;
|
|
206
|
-
|
|
206
|
+
// The config command saves --raw as a preference for future commands.
|
|
207
|
+
if (cmd != 'config') delete args.raw;
|
|
207
208
|
|
|
208
209
|
this.dry = args.dry || false;
|
|
209
210
|
delete args.dry;
|
|
@@ -285,7 +286,8 @@ const app = {
|
|
|
285
286
|
this.toast('⚠️', 'orange', bold("DRY RUN: ") + "No changes will actually be made.");
|
|
286
287
|
}
|
|
287
288
|
|
|
288
|
-
//
|
|
289
|
+
// Parse user JSON securely before any argument objects can be merged.
|
|
290
|
+
// Optionally read STDIN into a named arg (use curl @- convention).
|
|
289
291
|
var stdin_arg_key = null;
|
|
290
292
|
for (var key in args) {
|
|
291
293
|
if (args[key] === '@-') { stdin_arg_key = key; break; }
|
|
@@ -298,7 +300,7 @@ const app = {
|
|
|
298
300
|
|
|
299
301
|
// Some API parameters are opaque strings even when they look like JSON.
|
|
300
302
|
if (!JSON_ARG_EXCEPTIONS.includes(stdin_arg_key) && (args[stdin_arg_key].trim().match(/^\{[\s\S]*\}$/) || args[stdin_arg_key].trim().match(/^\[[\s\S]*\]$/))) {
|
|
301
|
-
try { args[stdin_arg_key] =
|
|
303
|
+
try { args[stdin_arg_key] = Tools.sjson.parse(args[stdin_arg_key]); }
|
|
302
304
|
catch (err) { this.die("Failed to parse JSON from STDIN: " + err); }
|
|
303
305
|
}
|
|
304
306
|
}
|
|
@@ -308,7 +310,7 @@ const app = {
|
|
|
308
310
|
if (String(args[key]).match(/^@(.+)$/)) {
|
|
309
311
|
var file = RegExp.$1;
|
|
310
312
|
if (!fs.existsSync(file)) this.die("File not found: " + file);
|
|
311
|
-
if (!JSON_ARG_EXCEPTIONS.includes(key) && file.match(/\.json$/i)) args[key] =
|
|
313
|
+
if (!JSON_ARG_EXCEPTIONS.includes(key) && file.match(/\.json$/i)) args[key] = Tools.sjson.parse( fs.readFileSync(file, 'utf8') );
|
|
312
314
|
else args[key] = fs.readFileSync(file, 'utf8');
|
|
313
315
|
}
|
|
314
316
|
}
|
|
@@ -323,7 +325,7 @@ const app = {
|
|
|
323
325
|
// any arg value that looks like json will be parsed
|
|
324
326
|
for (var key in args) {
|
|
325
327
|
if (!JSON_ARG_EXCEPTIONS.includes(key) && args[key] && (typeof(args[key]) == 'string') && (args[key].trim().match(/^\{[\s\S]*\}$/) || args[key].trim().match(/^\[[\s\S]*\]$/))) {
|
|
326
|
-
try { args[key] =
|
|
328
|
+
try { args[key] = Tools.sjson.parse( args[key] ); }
|
|
327
329
|
catch (err) { this.die("Failed to parse JSON from argument: " + err); }
|
|
328
330
|
}
|
|
329
331
|
}
|
package/lib/categories.js
CHANGED
|
@@ -283,7 +283,7 @@ module.exports = {
|
|
|
283
283
|
Tools.alwaysArray(params[singular]).forEach( item => {
|
|
284
284
|
// Repeated options arrive as an array of unparsed JSON strings.
|
|
285
285
|
if (typeof(item) == 'string') {
|
|
286
|
-
try { item =
|
|
286
|
+
try { item = Tools.sjson.parse(item); }
|
|
287
287
|
catch (err) { this.die("Category --" + singular + " must contain a JSON object."); }
|
|
288
288
|
}
|
|
289
289
|
if (!Tools.isaHash(item)) this.die("Category --" + singular + " must contain a JSON object.");
|
package/lib/config.js
CHANGED
|
@@ -7,6 +7,27 @@ const cli = require('pixl-cli');
|
|
|
7
7
|
const Tools = cli.Tools;
|
|
8
8
|
const chalk = cli.chalk;
|
|
9
9
|
|
|
10
|
+
// Settings consumed by the CLI, MCP server, or SDK. Keep this inventory
|
|
11
|
+
// explicit so a typo already saved in a config file cannot become a valid key.
|
|
12
|
+
const CONFIG_KEYS = [
|
|
13
|
+
'api_key', 'base_url', 'temp_dir', 'color', 'suggest', 'items_per_page',
|
|
14
|
+
'cache_ttl', 'raw', 'invisible', 'tz', 'log_columns', 'new_event_template',
|
|
15
|
+
'sync', 'mcp', 'user_agent', 'timeout', 'connect_timeout', 'idle_timeout',
|
|
16
|
+
'retries', 'retry_delay', 'retry_delay_max', 'allow_unauthorized',
|
|
17
|
+
'mcp_host', 'mcp_port', 'mcp_read_only', 'mcp_max_page_size',
|
|
18
|
+
'mcp_max_result_bytes', 'mcp_max_request_bytes', 'mcp_tls_cert', 'mcp_tls_key',
|
|
19
|
+
'ui', 'default_user_privileges', 'max_servers_per_group', 'quick_monitors',
|
|
20
|
+
'job_universal_actions', 'job_universal_limits'
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// Structured settings also support the existing dot and slash path syntax.
|
|
24
|
+
// Their contents may include arbitrary plugin parameters or server UI data.
|
|
25
|
+
const CONFIG_PATH_KEYS = [
|
|
26
|
+
'log_columns', 'new_event_template', 'sync', 'mcp', 'ui',
|
|
27
|
+
'default_user_privileges', 'quick_monitors', 'job_universal_actions',
|
|
28
|
+
'job_universal_limits'
|
|
29
|
+
];
|
|
30
|
+
|
|
10
31
|
function getConfigFiles(platform, env, home_dir) {
|
|
11
32
|
// Keep the existing Unix paths, but use Windows's shared application-data
|
|
12
33
|
// directory instead of resolving /etc against whichever drive is current.
|
|
@@ -33,9 +54,11 @@ var config_layer = module.exports = {
|
|
|
33
54
|
var config = {};
|
|
34
55
|
var config_files = this.configFiles = getConfigFiles(process.platform, process.env, os.homedir());
|
|
35
56
|
|
|
57
|
+
// Settings may come from external files or deployment environments.
|
|
58
|
+
// Reject prototype properties before merging or exporting parsed values.
|
|
36
59
|
config_files.forEach( function(file) {
|
|
37
60
|
if (!fs.existsSync(file)) return;
|
|
38
|
-
Tools.mergeHashInto( config,
|
|
61
|
+
Tools.mergeHashInto( config, Tools.sjson.parse(fs.readFileSync(file, 'utf8')) );
|
|
39
62
|
} );
|
|
40
63
|
|
|
41
64
|
for (var ekey in process.env) {
|
|
@@ -44,7 +67,7 @@ var config_layer = module.exports = {
|
|
|
44
67
|
var value = process.env[ekey];
|
|
45
68
|
// Parse object and array values just like JSON-looking CLI arguments.
|
|
46
69
|
if (value.trim().match(/^\{[\s\S]*\}$/) || value.trim().match(/^\[[\s\S]*\]$/)) {
|
|
47
|
-
try { value =
|
|
70
|
+
try { value = Tools.sjson.parse(value); }
|
|
48
71
|
catch (err) { throw new Error('Failed to parse JSON from environment variable: ' + ekey); }
|
|
49
72
|
}
|
|
50
73
|
else if (value === "true") value = true;
|
|
@@ -66,6 +89,9 @@ var config_layer = module.exports = {
|
|
|
66
89
|
// allow user to view config, and also modify it
|
|
67
90
|
delete this.args.other;
|
|
68
91
|
|
|
92
|
+
// These flags control this invocation, rather than saved preferences.
|
|
93
|
+
for (var key of ['debug', 'echo', 'quiet', 'verbose']) delete this.args[key];
|
|
94
|
+
|
|
69
95
|
if (!Tools.firstKey(this.args)) {
|
|
70
96
|
// just print config and exit
|
|
71
97
|
println( "\n " + this.color('theme').bold( 'CONFIGURATION SOURCES:' ) + "\n" );
|
|
@@ -81,11 +107,23 @@ var config_layer = module.exports = {
|
|
|
81
107
|
return;
|
|
82
108
|
}
|
|
83
109
|
|
|
110
|
+
// Validate the entire update before printing any values or touching the
|
|
111
|
+
// file. In particular, a misspelled --api-key must never echo its secret.
|
|
112
|
+
for (var key of Object.keys(this.args)) {
|
|
113
|
+
var root = key.split(/[.\/]/)[0];
|
|
114
|
+
if (CONFIG_KEYS.includes(key) || ((root != key) && CONFIG_PATH_KEYS.includes(root))) continue;
|
|
115
|
+
|
|
116
|
+
var suggestion = this.findClosestString(root, (root == key) ? CONFIG_KEYS : CONFIG_PATH_KEYS);
|
|
117
|
+
var message = 'Unknown configuration key "' + key + '".';
|
|
118
|
+
if (suggestion) message += ' Did you mean "' + suggestion + ((root != key) ? key.slice(root.length) : '') + '"?';
|
|
119
|
+
return this.die(message);
|
|
120
|
+
}
|
|
121
|
+
|
|
84
122
|
// Reload only the user's settings before applying changes. The effective
|
|
85
123
|
// configuration also contains system settings and environment overrides,
|
|
86
124
|
// which must not be copied into the user's file when saving preferences.
|
|
87
125
|
var dest_file = this.configFiles[this.configFiles.length - 1];
|
|
88
|
-
var user_config = fs.existsSync(dest_file) ?
|
|
126
|
+
var user_config = fs.existsSync(dest_file) ? Tools.sjson.parse(fs.readFileSync(dest_file, 'utf8')) : {};
|
|
89
127
|
|
|
90
128
|
// Apply only the supplied arguments, preserving other user settings.
|
|
91
129
|
print("\n");
|
package/lib/groups.js
CHANGED
|
@@ -429,7 +429,7 @@ module.exports = {
|
|
|
429
429
|
if (!Array.isArray(params.alert_actions)) this.die('Server Group alert_actions must be a JSON array.');
|
|
430
430
|
Tools.alwaysArray(params.action).forEach( action => {
|
|
431
431
|
if (typeof(action) == 'string') {
|
|
432
|
-
try { action =
|
|
432
|
+
try { action = Tools.sjson.parse(action); }
|
|
433
433
|
catch (err) { this.die('Server Group --action must contain a JSON object.'); }
|
|
434
434
|
}
|
|
435
435
|
if (!Tools.isaHash(action)) this.die('Server Group --action must contain a JSON object.');
|
package/lib/plugins.js
CHANGED
|
@@ -403,7 +403,7 @@ module.exports = {
|
|
|
403
403
|
// parsed object and repeated objects both become a clean object array here.
|
|
404
404
|
return Tools.alwaysArray(value).map( item => {
|
|
405
405
|
if (typeof(item) == 'string') {
|
|
406
|
-
try { item =
|
|
406
|
+
try { item = Tools.sjson.parse(item); }
|
|
407
407
|
catch (err) { this.die("Plugin --" + name + " must contain a JSON object."); }
|
|
408
408
|
}
|
|
409
409
|
if (!Tools.isaHash(item)) this.die("Plugin --" + name + " must contain a JSON object.");
|
package/lib/sync-buckets.js
CHANGED
|
@@ -69,7 +69,7 @@ module.exports = {
|
|
|
69
69
|
var paths = this.getSyncBucketPaths(item);
|
|
70
70
|
var stat = fs.lstatSync(paths.data);
|
|
71
71
|
if (!stat.isFile() || stat.isSymbolicLink()) throw new Error("Invalid bucket data file: " + paths.data);
|
|
72
|
-
var data =
|
|
72
|
+
var data = Tools.sjson.parse(fs.readFileSync(paths.data, 'utf8'));
|
|
73
73
|
if (!Tools.isaHash(data)) throw new Error("Bucket data must be a JSON object: " + paths.data);
|
|
74
74
|
|
|
75
75
|
var dir_stat = fs.lstatSync(paths.files);
|
|
@@ -233,7 +233,7 @@ module.exports = {
|
|
|
233
233
|
if (Tools.stableStringify(updated.data) !== Tools.stableStringify(local.data)) {
|
|
234
234
|
throw new Error("Bucket data changed during upload: " + id);
|
|
235
235
|
}
|
|
236
|
-
if (Tools.stableStringify(
|
|
236
|
+
if (Tools.stableStringify(Tools.sjson.parse(fs.readFileSync(local.paths.data, 'utf8'))) !== Tools.stableStringify(local.data)) {
|
|
237
237
|
throw new Error("Local bucket data changed during upload: " + local.paths.data);
|
|
238
238
|
}
|
|
239
239
|
this.stampSyncBucketFile(local.paths.data, updated.meta.mod);
|
package/lib/sync-syshook.js
CHANGED
|
@@ -42,7 +42,7 @@ async function readHookPayload() {
|
|
|
42
42
|
|
|
43
43
|
if (!size) throw new Error("System Hook activity payload is empty.");
|
|
44
44
|
|
|
45
|
-
try { return
|
|
45
|
+
try { return Tools.sjson.parse(Buffer.concat(chunks).toString('utf8')); }
|
|
46
46
|
catch (err) { throw new Error("Invalid System Hook activity JSON: " + err.message); }
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -76,7 +76,7 @@ function scanSources(files) {
|
|
|
76
76
|
catch (err) { throw new Error("Failed to read JSON file: " + file + ": " + err.message); }
|
|
77
77
|
|
|
78
78
|
var xypdf = null;
|
|
79
|
-
try { xypdf =
|
|
79
|
+
try { xypdf = Tools.sjson.parse(raw); }
|
|
80
80
|
catch (err) {
|
|
81
81
|
parse_errors.push({ file, err });
|
|
82
82
|
continue;
|
package/lib/sync.js
CHANGED
|
@@ -119,9 +119,14 @@ module.exports = {
|
|
|
119
119
|
// source basename instead of also being claimed by every shorter prefix.
|
|
120
120
|
var source_stems_by_dir = new Map();
|
|
121
121
|
var bucket_extra_dirs = [];
|
|
122
|
+
// Keep parseJSON's line-number diagnostics, then scan each parsed value
|
|
123
|
+
// before using it. Null is valid JSON and has no properties to inspect.
|
|
122
124
|
files.filter( file => !!file.path.match(/\.json$/i) ).forEach( file => {
|
|
123
125
|
var xypdf = null;
|
|
124
|
-
try {
|
|
126
|
+
try {
|
|
127
|
+
xypdf = Tools.parseJSON( fs.readFileSync(file.path, 'utf8') );
|
|
128
|
+
if (xypdf) Tools.sjson.scan(xypdf);
|
|
129
|
+
}
|
|
125
130
|
catch (err) { return; } // the normal scan below reports malformed JSON
|
|
126
131
|
if (!xypdf || !Tools.isaHash(xypdf) || (xypdf.type !== 'xypdf')) return;
|
|
127
132
|
if (Array.isArray(xypdf.items) && xypdf.items.length == 1 && xypdf.items[0].type == 'bucket') {
|
|
@@ -154,7 +159,8 @@ module.exports = {
|
|
|
154
159
|
// try to parse JSON
|
|
155
160
|
var xypdf = null;
|
|
156
161
|
try {
|
|
157
|
-
xypdf = Tools.parseJSON( fs.readFileSync(file.path, 'utf8') );
|
|
162
|
+
xypdf = Tools.parseJSON( fs.readFileSync(file.path, 'utf8') );
|
|
163
|
+
if (xypdf) Tools.sjson.scan(xypdf);
|
|
158
164
|
}
|
|
159
165
|
catch (err) {
|
|
160
166
|
this.logSyncWarning("Failed to parse JSON file: " + file.path + ": " + err);
|
|
@@ -263,6 +269,7 @@ module.exports = {
|
|
|
263
269
|
if (neighbor.path.match(/\.json$/i)) {
|
|
264
270
|
try {
|
|
265
271
|
var neighbor_json = Tools.parseJSON(content);
|
|
272
|
+
if (neighbor_json) Tools.sjson.scan(neighbor_json);
|
|
266
273
|
if (neighbor_json && Tools.isaHash(neighbor_json) && (neighbor_json.type === 'xypdf')) return;
|
|
267
274
|
}
|
|
268
275
|
catch (err) {;} // leave non-JSON content for normal neighbor handling
|
|
@@ -494,6 +501,7 @@ module.exports = {
|
|
|
494
501
|
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("Local deletion target is not a regular directory: " + dir);
|
|
495
502
|
}
|
|
496
503
|
var source = Tools.parseJSON(fs.readFileSync(item.file, 'utf8'));
|
|
504
|
+
if (source) Tools.sjson.scan(source);
|
|
497
505
|
var source_item = source && Array.isArray(source.items) && (source.items.length === 1) ? source.items[0] : null;
|
|
498
506
|
if (!source || (source.type !== 'xypdf') || (source.version !== '1.0') || !source_item ||
|
|
499
507
|
(source_item.type !== item.type) || !source_item.data || (source_item.data.id !== item.data.id)) {
|
|
@@ -612,7 +620,7 @@ module.exports = {
|
|
|
612
620
|
}
|
|
613
621
|
|
|
614
622
|
var old_lock = null;
|
|
615
|
-
try { old_lock = raw.match(/^\d+$/) ? { pid: parseInt(raw) } :
|
|
623
|
+
try { old_lock = raw.match(/^\d+$/) ? { pid: parseInt(raw) } : Tools.sjson.parse(raw); }
|
|
616
624
|
catch (err) { this.die("Invalid sync lock file: " + lock_file + ". Verify no sync is running before removing it."); }
|
|
617
625
|
|
|
618
626
|
var old_pid = old_lock && Number(old_lock.pid);
|
|
@@ -693,7 +701,7 @@ module.exports = {
|
|
|
693
701
|
}
|
|
694
702
|
|
|
695
703
|
try {
|
|
696
|
-
var current =
|
|
704
|
+
var current = Tools.sjson.parse(fs.readFileSync(lock.file, 'utf8'));
|
|
697
705
|
if (current.token === lock.token) fs.unlinkSync(lock.file);
|
|
698
706
|
}
|
|
699
707
|
catch (err) {
|
|
@@ -1027,6 +1035,7 @@ module.exports = {
|
|
|
1027
1035
|
files.filter( file => !!file.path.match(/\.json$/i) ).forEach( file => {
|
|
1028
1036
|
try {
|
|
1029
1037
|
var xypdf = Tools.parseJSON( fs.readFileSync(file.path, 'utf8') );
|
|
1038
|
+
if (xypdf) Tools.sjson.scan(xypdf);
|
|
1030
1039
|
if (xypdf && xypdf.type == 'xypdf' && Array.isArray(xypdf.items) &&
|
|
1031
1040
|
xypdf.items.length == 1 && xypdf.items[0].type == 'bucket') {
|
|
1032
1041
|
bucket_extra_dirs.push(file.path.replace(/\.json$/i, ''));
|
|
@@ -1036,7 +1045,10 @@ module.exports = {
|
|
|
1036
1045
|
});
|
|
1037
1046
|
files.filter( file => !!file.path.match(/\.json$/i) && !this.isSyncBucketExtraFile(file.path, bucket_extra_dirs) ).forEach( file => {
|
|
1038
1047
|
var xypdf = null;
|
|
1039
|
-
try {
|
|
1048
|
+
try {
|
|
1049
|
+
xypdf = Tools.parseJSON( fs.readFileSync(file.path, 'utf8') );
|
|
1050
|
+
if (xypdf) Tools.sjson.scan(xypdf);
|
|
1051
|
+
}
|
|
1040
1052
|
catch (err) { this.die("Failed to parse JSON file: " + file.path + ": " + err); }
|
|
1041
1053
|
|
|
1042
1054
|
// Ordinary JSON files are unrelated and may coexist in the tree.
|
package/lib/transfer.js
CHANGED
|
@@ -185,6 +185,7 @@ module.exports = {
|
|
|
185
185
|
|
|
186
186
|
cleanTransferData(data) {
|
|
187
187
|
// Strip server-managed metadata without mutating cached or parsed objects.
|
|
188
|
+
// This JSON round trip only clones data already validated at its boundary.
|
|
188
189
|
var clean = JSON.parse(JSON.stringify(data));
|
|
189
190
|
AUDIT_FIELDS.forEach( key => delete clean[key] );
|
|
190
191
|
if (clean.id === '') delete clean.id;
|
|
@@ -235,7 +236,7 @@ module.exports = {
|
|
|
235
236
|
// Accept gzip by signature as well as extension, including UI .json.gz.
|
|
236
237
|
if (/\.gz$/i.test(filename) || (bytes[0] == 0x1f && bytes[1] == 0x8b)) bytes = zlib.gunzipSync(bytes);
|
|
237
238
|
|
|
238
|
-
payload =
|
|
239
|
+
payload = Tools.sjson.parse(bytes.toString('utf8').replace(/^\uFEFF/, ''));
|
|
239
240
|
}
|
|
240
241
|
catch (err) { return this.die("Failed to read XYPDF file: " + err.message); }
|
|
241
242
|
|
package/lib/upgrade.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const cp = require('node:child_process');
|
|
4
4
|
|
|
5
5
|
const cli = require('pixl-cli');
|
|
6
|
+
const Tools = cli.Tools;
|
|
6
7
|
const chalk = cli.chalk;
|
|
7
8
|
|
|
8
9
|
const PACKAGE_NAME = '@pixlcore/xycli';
|
|
@@ -98,7 +99,12 @@ module.exports = {
|
|
|
98
99
|
if (!response.ok) this.die("npm registry request failed with HTTP status: " + response.status);
|
|
99
100
|
|
|
100
101
|
var data;
|
|
101
|
-
try {
|
|
102
|
+
try {
|
|
103
|
+
data = await response.json();
|
|
104
|
+
|
|
105
|
+
// Fetch owns JSON decoding, so scan the registry's object before use.
|
|
106
|
+
Tools.sjson.scan(data);
|
|
107
|
+
}
|
|
102
108
|
catch (err) { this.die("Could not parse the npm registry response: " + err.message); }
|
|
103
109
|
|
|
104
110
|
if (!data || (typeof(data.version) != 'string') || !data.version.length) {
|
package/lib/utils.js
CHANGED
|
@@ -1017,6 +1017,10 @@ module.exports = {
|
|
|
1017
1017
|
|
|
1018
1018
|
// merge, but do not clobber keys already in local config
|
|
1019
1019
|
for (var key in data.config) {
|
|
1020
|
+
// Sync settings can execute local commands and must only come from
|
|
1021
|
+
// local config or CLI arguments, never the server's client config.
|
|
1022
|
+
if (key == 'sync') continue;
|
|
1023
|
+
|
|
1020
1024
|
if (!(key in this.config)) this.config[key] = data.config[key];
|
|
1021
1025
|
}
|
|
1022
1026
|
|
|
@@ -1039,8 +1043,9 @@ module.exports = {
|
|
|
1039
1043
|
catch (err) { stats = null; }
|
|
1040
1044
|
|
|
1041
1045
|
if (stats && (stats.mtimeMs / 1000 > Tools.timeNow() - ttl)) {
|
|
1042
|
-
//
|
|
1043
|
-
|
|
1046
|
+
// Cache files can be modified outside this process. Validate their JSON
|
|
1047
|
+
// just like the original API response before returning a fresh object.
|
|
1048
|
+
return { data: Tools.sjson.parse( fs.readFileSync(cache_file, 'utf8') ) };
|
|
1044
1049
|
}
|
|
1045
1050
|
|
|
1046
1051
|
// fetch from origin
|
package/lib/webhook.js
CHANGED
|
@@ -315,7 +315,7 @@ module.exports = {
|
|
|
315
315
|
if (!Array.isArray(params.headers)) this.die("Web Hook headers must be a JSON array.");
|
|
316
316
|
Tools.alwaysArray(params.header).forEach( header => {
|
|
317
317
|
if (typeof(header) == 'string') {
|
|
318
|
-
try { header =
|
|
318
|
+
try { header = Tools.sjson.parse(header); }
|
|
319
319
|
catch (err) { this.die("Web Hook --header must contain a JSON object."); }
|
|
320
320
|
}
|
|
321
321
|
if (!Tools.isaHash(header)) this.die("Web Hook --header must contain a JSON object.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixlcore/xycli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "A complete command-line interface for the xyOps workflow automation system.",
|
|
5
5
|
"author": "Joseph Huckaby <jhuckaby@pixlcore.com>",
|
|
6
6
|
"homepage": "https://github.com/pixlcore/xycli",
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "node test.js",
|
|
24
|
-
"test:offline": "node --test test/config.test.js test/help.test.js test/jobs-follow-unit.test.js test/markdown.test.js test/sync-buckets-unit.test.js test/sync-syshook-unit.test.js test/sync-unit.test.js test/toast.test.js test/upgrade.test.js test/utils-unit.test.js test/mcp-tools-unit.test.js test/mcp-stdio-unit.test.js test/mcp-http-unit.test.js",
|
|
24
|
+
"test:offline": "node --test test/config.test.js test/help.test.js test/jobs-follow-unit.test.js test/markdown.test.js test/secure-json-unit.test.js test/sync-buckets-unit.test.js test/sync-syshook-unit.test.js test/sync-unit.test.js test/toast.test.js test/upgrade.test.js test/utils-unit.test.js test/mcp-tools-unit.test.js test/mcp-stdio-unit.test.js test/mcp-http-unit.test.js",
|
|
25
25
|
"changelog": "node tools/changelog.js"
|
|
26
26
|
},
|
|
27
27
|
"overrides": {
|
|
28
28
|
"basic-ftp": "6.2.1"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pixlcore/xyops-sdk": "^1.0.
|
|
31
|
+
"@pixlcore/xyops-sdk": "^1.0.9",
|
|
32
32
|
"cli-highlight": "2.1.11",
|
|
33
33
|
"diff": "9.0.0",
|
|
34
|
-
"pixl-cli": "^1.1.
|
|
34
|
+
"pixl-cli": "^1.1.7",
|
|
35
35
|
"html-to-text": "10.0.1",
|
|
36
36
|
"marked": "15.0.12",
|
|
37
37
|
"marked-terminal": "7.3.0",
|
package/test/config.test.js
CHANGED
|
@@ -32,7 +32,7 @@ function createConfigFixture(t, initial) {
|
|
|
32
32
|
|
|
33
33
|
return {
|
|
34
34
|
file,
|
|
35
|
-
run(args) {
|
|
35
|
+
run(args, expected_status = 0) {
|
|
36
36
|
const env = {
|
|
37
37
|
...process.env,
|
|
38
38
|
HOME: home_dir,
|
|
@@ -58,8 +58,8 @@ function createConfigFixture(t, initial) {
|
|
|
58
58
|
// Keep captured CLI output out of assertion messages, since a config
|
|
59
59
|
// command may display settings inherited from the real system file.
|
|
60
60
|
assert.ifError(result.error);
|
|
61
|
-
assert.equal(result.status,
|
|
62
|
-
return result.stdout;
|
|
61
|
+
assert.equal(result.status, expected_status, 'Config command should exit with the expected status');
|
|
62
|
+
return result.stdout + result.stderr;
|
|
63
63
|
},
|
|
64
64
|
read() { return JSON.parse(fs.readFileSync(file, 'utf8')); }
|
|
65
65
|
};
|
|
@@ -112,6 +112,65 @@ test('config creates a missing user file with only supplied settings', t => {
|
|
|
112
112
|
assertPrivateMode(fixture.file);
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
+
test('config rejects misspelled keys without creating a file or exposing secrets', t => {
|
|
116
|
+
const fixture = createConfigFixture(t);
|
|
117
|
+
|
|
118
|
+
for (const [key, suggestion] of [['base-url', 'base_url'], ['api-key', 'api_key'], ['items_per_pag', 'items_per_page']]) {
|
|
119
|
+
const output = fixture.run(['--' + key, 'private-fixture-value'], 1);
|
|
120
|
+
assert.ok(output.includes('Unknown configuration key "' + key + '".'));
|
|
121
|
+
assert.ok(output.includes('Did you mean "' + suggestion + '"?'));
|
|
122
|
+
assert.doesNotMatch(output, /private-fixture-value|Setting key:|Writing to:/);
|
|
123
|
+
assert.equal(fs.existsSync(fixture.file), false);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('config rejects mixed valid and unknown updates without changing the user file', t => {
|
|
128
|
+
// Previously saved typos must not be accepted as supported config keys.
|
|
129
|
+
const fixture = createConfigFixture(t, { items_per_page: 10, 'api-key': 'old-value' });
|
|
130
|
+
const original = fs.readFileSync(fixture.file, 'utf8');
|
|
131
|
+
const output = fixture.run(['--items_per_page', '25', '--api-key', 'private-fixture-value'], 1);
|
|
132
|
+
|
|
133
|
+
assert.match(output, /Unknown configuration key "api-key"/);
|
|
134
|
+
assert.doesNotMatch(output, /private-fixture-value|Setting key:|Writing to:/);
|
|
135
|
+
assert.equal(fs.readFileSync(fixture.file, 'utf8'), original);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('config rejects unrelated keys and nested paths under scalar settings', t => {
|
|
139
|
+
const fixture = createConfigFixture(t);
|
|
140
|
+
|
|
141
|
+
for (const key of ['unrelated_option', 'api_key.child', 'base_url/child']) {
|
|
142
|
+
const output = fixture.run(['--' + key, 'private-fixture-value'], 1);
|
|
143
|
+
assert.match(output, /Unknown configuration key/);
|
|
144
|
+
assert.doesNotMatch(output, /private-fixture-value|Setting key:|Writing to:/);
|
|
145
|
+
assert.equal(fs.existsSync(fixture.file), false);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('config saves supported connection, SDK, MCP, and structured settings', t => {
|
|
150
|
+
const fixture = createConfigFixture(t);
|
|
151
|
+
const output = fixture.run([
|
|
152
|
+
'--base_url', 'https://saved.invalid', '--api_key', 'private-fixture-value',
|
|
153
|
+
'--timeout', '5000', '--mcp_port', '8080', '--mcp.read_only', 'true',
|
|
154
|
+
'--new_event_template/params/custom', 'value', '--raw', 'false'
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
assert.doesNotMatch(output, /private-fixture-value/);
|
|
158
|
+
assert.deepEqual(fixture.read(), {
|
|
159
|
+
base_url: 'https://saved.invalid', api_key: 'private-fixture-value',
|
|
160
|
+
timeout: 5000, mcp_port: 8080, mcp: { read_only: true },
|
|
161
|
+
new_event_template: { params: { custom: 'value' } }, raw: false
|
|
162
|
+
});
|
|
163
|
+
assertPrivateMode(fixture.file);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('config ignores invocation flags when displaying and saving settings', t => {
|
|
167
|
+
const fixture = createConfigFixture(t);
|
|
168
|
+
fixture.run(['--quiet']);
|
|
169
|
+
assert.equal(fs.existsSync(fixture.file), false);
|
|
170
|
+
fixture.run(['--verbose', '--items_per_page', '25']);
|
|
171
|
+
assert.deepEqual(fixture.read(), { items_per_page: 25 });
|
|
172
|
+
});
|
|
173
|
+
|
|
115
174
|
test('config dotted updates preserve sibling user settings and explicit false or zero values', t => {
|
|
116
175
|
const fixture = createConfigFixture(t, {
|
|
117
176
|
sync: { up: ['events'], down: ['plugins'], error_email: 'ops@example.com' },
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const Path = require('node:path');
|
|
6
|
+
const zlib = require('node:zlib');
|
|
7
|
+
const { spawnSync } = require('node:child_process');
|
|
8
|
+
const cli = require('pixl-cli');
|
|
9
|
+
const Tools = cli.Tools;
|
|
10
|
+
const utils = require('../lib/utils.js');
|
|
11
|
+
const transfer = require('../lib/transfer.js');
|
|
12
|
+
const upgrade = require('../lib/upgrade.js');
|
|
13
|
+
|
|
14
|
+
// Keep these as JSON text so JavaScript's object literal syntax cannot consume
|
|
15
|
+
// __proto__ before the input reaches the actual CLI boundary under test.
|
|
16
|
+
const unsafe = [
|
|
17
|
+
'{"nested":[{"__proto__":{"polluted":true}}]}',
|
|
18
|
+
'{"nested":[{"constructor":{"prototype":{"polluted":true}}}]}',
|
|
19
|
+
'{"nested":[{"\\u005f_proto__":{"polluted":true}}]}'
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function fixture(t) {
|
|
23
|
+
// Each subprocess gets a private config, cache and SDK stub. Any attempted
|
|
24
|
+
// API call leaves a marker, without contacting a real xyOps server.
|
|
25
|
+
const dir = fs.mkdtempSync(Path.join(os.tmpdir(), 'xycli-secure-json-'));
|
|
26
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
27
|
+
const marker = Path.join(dir, 'api-called');
|
|
28
|
+
const preload = Path.join(dir, 'preload.js');
|
|
29
|
+
fs.writeFileSync(preload, `
|
|
30
|
+
const fs = require('node:fs');
|
|
31
|
+
const sdk = require(${JSON.stringify(require.resolve('@pixlcore/xyops-sdk'))});
|
|
32
|
+
sdk.api = new Proxy({}, {
|
|
33
|
+
get() { return async function() {
|
|
34
|
+
fs.writeFileSync(${JSON.stringify(marker)}, 'called');
|
|
35
|
+
return { data: { config: {}, masters: [], version: '99.0.0' } };
|
|
36
|
+
}; }
|
|
37
|
+
});
|
|
38
|
+
`);
|
|
39
|
+
const env = { ...process.env, HOME: dir, USERPROFILE: dir, ProgramData: dir };
|
|
40
|
+
for (const key of Object.keys(env)) {
|
|
41
|
+
if (key.startsWith('XYOPS_')) delete env[key];
|
|
42
|
+
}
|
|
43
|
+
Object.assign(env, {
|
|
44
|
+
XYOPS_API_KEY: 'fixture-key', XYOPS_BASE_URL: 'https://fixture.invalid',
|
|
45
|
+
XYOPS_TEMP_DIR: dir, XYOPS_COLOR: 'false'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
dir, marker, env,
|
|
50
|
+
run(args, input) {
|
|
51
|
+
const result = spawnSync(process.execPath, [
|
|
52
|
+
'--require', preload, Path.join(__dirname, '..', 'index.js'), ...args
|
|
53
|
+
], { env, input, encoding: 'utf8', timeout: 10000 });
|
|
54
|
+
assert.ifError(result.error);
|
|
55
|
+
assert.equal(result.signal, null);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
test('untrusted argument JSON is rejected before API access', t => {
|
|
62
|
+
const env = fixture(t);
|
|
63
|
+
const file = Path.join(env.dir, 'input.json');
|
|
64
|
+
for (const payload of unsafe) {
|
|
65
|
+
fs.writeFileSync(file, payload);
|
|
66
|
+
for (const [args, input] of [
|
|
67
|
+
[['--params', payload]],
|
|
68
|
+
[['--json', '@-'], payload],
|
|
69
|
+
[['--json', '@' + file]]
|
|
70
|
+
]) {
|
|
71
|
+
const result = env.run(['api', 'run_event', ...args], input);
|
|
72
|
+
assert.equal(result.status, 1);
|
|
73
|
+
assert.match(result.stderr, /forbidden prototype property/);
|
|
74
|
+
assert.equal(fs.existsSync(env.marker), false);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('config files and environment JSON reject forbidden properties', t => {
|
|
80
|
+
const env = fixture(t);
|
|
81
|
+
const file = Path.join(env.dir, '.config', 'xyops', 'cli.json');
|
|
82
|
+
fs.mkdirSync(Path.dirname(file), { recursive: true });
|
|
83
|
+
for (const payload of unsafe) {
|
|
84
|
+
fs.writeFileSync(file, payload);
|
|
85
|
+
assert.equal(env.run(['config']).status, 1);
|
|
86
|
+
assert.equal(fs.readFileSync(file, 'utf8'), payload);
|
|
87
|
+
fs.unlinkSync(file);
|
|
88
|
+
|
|
89
|
+
env.env.XYOPS_SYNC = payload;
|
|
90
|
+
const result = env.run(['config']);
|
|
91
|
+
assert.equal(result.status, 1);
|
|
92
|
+
assert.match(result.stderr, /Failed to parse JSON from environment variable: XYOPS_SYNC/);
|
|
93
|
+
delete env.env.XYOPS_SYNC;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('cached API JSON rejects forbidden properties before returning data', async t => {
|
|
98
|
+
const env = fixture(t);
|
|
99
|
+
const config = { base_url: 'https://fixture.invalid' };
|
|
100
|
+
const file = Path.join(env.dir, 'config-' + Tools.digestHex(config.base_url, 'sha256', 16) + '.json');
|
|
101
|
+
const context = { config, tempDir: env.dir };
|
|
102
|
+
for (const payload of unsafe) {
|
|
103
|
+
fs.writeFileSync(file, payload);
|
|
104
|
+
await assert.rejects(utils.cacheAPI.call(context, 'config', {}), /forbidden prototype property/);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('plain and gzip imports reject forbidden properties before planning API calls', async t => {
|
|
109
|
+
const env = fixture(t);
|
|
110
|
+
for (const payload of unsafe) {
|
|
111
|
+
const text = '{"type":"xypdf","version":"1.0","items":[{"type":"event","data":' + payload + '}]}';
|
|
112
|
+
for (const gzip of [false, true]) {
|
|
113
|
+
const file = Path.join(env.dir, gzip ? 'input.json.gz' : 'input.json');
|
|
114
|
+
fs.writeFileSync(file, gzip ? zlib.gzipSync(text) : text);
|
|
115
|
+
const context = {
|
|
116
|
+
args: { other: [file] },
|
|
117
|
+
requireTransferFilename: transfer.requireTransferFilename,
|
|
118
|
+
die(message) { throw new Error(message); },
|
|
119
|
+
async getMultiple() { assert.fail('Import must reject JSON before loading resources'); }
|
|
120
|
+
};
|
|
121
|
+
await assert.rejects(transfer.cmd_import.call(context), /Failed to read XYPDF file: .*forbidden prototype property/);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('npm registry objects are scanned before accepting a version', async t => {
|
|
127
|
+
const fetch = global.fetch;
|
|
128
|
+
t.after(() => { global.fetch = fetch; });
|
|
129
|
+
const context = {
|
|
130
|
+
cli: { progress: { start() {}, end() {} } },
|
|
131
|
+
color() { return text => text; },
|
|
132
|
+
die(message) { throw new Error(message); }
|
|
133
|
+
};
|
|
134
|
+
for (const payload of unsafe) {
|
|
135
|
+
global.fetch = async () => ({ ok: true, async json() {
|
|
136
|
+
return { version: '99.0.0', extra: JSON.parse(payload) };
|
|
137
|
+
} });
|
|
138
|
+
await assert.rejects(upgrade.getLatestXYCLIVersion.call(context), /Could not parse the npm registry response: .*forbidden prototype property/);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
@@ -45,6 +45,27 @@ function markerCommand(name) {
|
|
|
45
45
|
return `${JSON.stringify(process.execPath)} -e ${JSON.stringify(code)}`;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
test('syshook rejects forbidden payload and source properties before deleting files', t => {
|
|
49
|
+
for (const property of ['"__proto__":{"polluted":true}', '"constructor":{"prototype":{"polluted":true}}']) {
|
|
50
|
+
var dir = makeTree(t);
|
|
51
|
+
var target = writeSource(dir, 'Event.json', 'event', { id: 'evt_one' });
|
|
52
|
+
var payload = { xy: 1, action: 'event_delete', event: { id: 'evt_one' } };
|
|
53
|
+
// Native parsing here deliberately preserves the unsafe own property so
|
|
54
|
+
// runHook sends the exact attack text through the real STDIN reader.
|
|
55
|
+
var bad_payload = JSON.parse('{"xy":1,"action":"event_delete","event":{"id":"evt_one"},' + property + '}');
|
|
56
|
+
var result = runHook(dir, 'event_delete', bad_payload);
|
|
57
|
+
assert.equal(result.status, 1);
|
|
58
|
+
assert.match(result.stderr, /Invalid System Hook activity JSON: .*forbidden prototype property/);
|
|
59
|
+
assert.equal(fs.existsSync(target), true);
|
|
60
|
+
|
|
61
|
+
fs.writeFileSync(target, '{"type":"xypdf","version":"1.0","items":[{"type":"event","data":{"id":"evt_one",' + property + '}}]}');
|
|
62
|
+
result = runHook(dir, 'event_delete', payload);
|
|
63
|
+
assert.equal(result.status, 1);
|
|
64
|
+
assert.match(result.stderr, /Failed to parse JSON file: .*forbidden prototype property/);
|
|
65
|
+
assert.equal(fs.existsSync(target), true);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
48
69
|
test('syshook deletes only the exact Event and its owned neighbors', t => {
|
|
49
70
|
var dir = makeTree(t);
|
|
50
71
|
var event = writeSource(dir, 'events/Ops/Nightly.json', 'event', {
|
package/test/sync-unit.test.js
CHANGED
|
@@ -135,6 +135,32 @@ function getSetupMarkerCommand(filename) {
|
|
|
135
135
|
return `${JSON.stringify(process.execPath)} -e ${JSON.stringify(code)}`;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
test('sync rejects forbidden JSON properties before updating managed objects', t => {
|
|
139
|
+
for (const property of ['"__proto__":{"polluted":true}', '"constructor":{"prototype":{"polluted":true}}']) {
|
|
140
|
+
const contents = '{"type":"xypdf","version":"1.0","items":[{"type":"category","data":{"id":"cat_one","title":"Unsafe",' + property + '}}]}';
|
|
141
|
+
const result = runSync(t, {
|
|
142
|
+
args: { up: 'categories' },
|
|
143
|
+
existingSources: [{ path: 'Unsafe.json', contents }],
|
|
144
|
+
categories: [{ id: 'cat_one', title: 'Original' }]
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
assert.equal(result.status, 1);
|
|
148
|
+
assert.match(result.report.warnings.join('\n'), /forbidden prototype property/);
|
|
149
|
+
assert.deepEqual(result.report.calls, []);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('sync still ignores unrelated null JSON after security scanning', t => {
|
|
154
|
+
const result = runSync(t, {
|
|
155
|
+
args: { up: 'categories' },
|
|
156
|
+
existingSources: [{ path: 'Unrelated.json', contents: 'null' }]
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
assert.equal(result.status, 0);
|
|
160
|
+
assert.deepEqual(result.report.warnings, []);
|
|
161
|
+
assert.deepEqual(result.report.calls, []);
|
|
162
|
+
});
|
|
163
|
+
|
|
138
164
|
test('sync update guard requires confirmation only for the exact managed object', async () => {
|
|
139
165
|
var warnings = [];
|
|
140
166
|
var loads = 0;
|
package/test/utils-unit.test.js
CHANGED
|
@@ -5,6 +5,31 @@ const utils = require('../lib/utils.js');
|
|
|
5
5
|
|
|
6
6
|
cli.global();
|
|
7
7
|
|
|
8
|
+
test('server client config cannot supply sync settings or overwrite local settings', async () => {
|
|
9
|
+
const remote = {
|
|
10
|
+
config: { sync: { down_cmd: 'untrusted-command' }, items_per_page: 50, suggest: true },
|
|
11
|
+
masters: ['fixture-master'],
|
|
12
|
+
version: '1.2.3'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Cover an absent setting, an explicitly disabled setting and a configured
|
|
16
|
+
// local command. The server must never introduce or extend sync settings.
|
|
17
|
+
for (const local of [{}, { sync: false }, { sync: { up: ['events'], down_cmd: 'local-command' } }]) {
|
|
18
|
+
const config = { items_per_page: 10, ...local };
|
|
19
|
+
const context = {
|
|
20
|
+
config,
|
|
21
|
+
async cacheAPI() { return { data: remote }; }
|
|
22
|
+
};
|
|
23
|
+
await utils.cacheConfig.call(context);
|
|
24
|
+
|
|
25
|
+
assert.deepEqual(config, { items_per_page: 10, ...local, suggest: true });
|
|
26
|
+
assert.equal(Object.hasOwn(config, 'sync'), Object.hasOwn(local, 'sync'));
|
|
27
|
+
if (Object.hasOwn(local, 'sync')) assert.equal(config.sync, local.sync);
|
|
28
|
+
assert.deepEqual(context.masters, remote.masters);
|
|
29
|
+
assert.equal(context.xyopsVersion, remote.version);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
8
33
|
test('executable language detection accepts Unix and Windows command forms', () => {
|
|
9
34
|
// Plugin definitions are portable, so exercise both path styles regardless of
|
|
10
35
|
// the operating system running this test.
|
package/tools/changelog.js
CHANGED