koishi-plugin-spawn-modified 1.2.5 → 1.2.6
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/lib/index.js +28 -1
- package/package.json +1 -1
- package/src/index.ts +25 -1
package/lib/index.js
CHANGED
|
@@ -226,6 +226,33 @@ function validateCdCommand(command, currentDir, rootDir, restrictDirectory) {
|
|
|
226
226
|
}
|
|
227
227
|
return { valid: true };
|
|
228
228
|
}
|
|
229
|
+
function maskCurlOutput(command, output) {
|
|
230
|
+
if (!output)
|
|
231
|
+
return output;
|
|
232
|
+
if (!/\bcurl\b/i.test(command))
|
|
233
|
+
return output;
|
|
234
|
+
var ipv4Regex = /\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g;
|
|
235
|
+
return output.replace(ipv4Regex, function (ip) { return (isPrivateIpv4(ip) ? ip : '*.*.*.*'); });
|
|
236
|
+
}
|
|
237
|
+
function isPrivateIpv4(ip) {
|
|
238
|
+
var octets = ip.split('.').map(Number);
|
|
239
|
+
if (octets.length !== 4)
|
|
240
|
+
return false;
|
|
241
|
+
if (octets.some(function (octet) { return Number.isNaN(octet) || octet < 0 || octet > 255; }))
|
|
242
|
+
return false;
|
|
243
|
+
var a = octets[0], b = octets[1];
|
|
244
|
+
if (a === 10)
|
|
245
|
+
return true;
|
|
246
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
247
|
+
return true;
|
|
248
|
+
if (a === 192 && b === 168)
|
|
249
|
+
return true;
|
|
250
|
+
if (a === 127)
|
|
251
|
+
return true;
|
|
252
|
+
if (a === 169 && b === 254)
|
|
253
|
+
return true;
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
229
256
|
// 渲染终端输出为图片
|
|
230
257
|
function renderTerminalImage(ctx, workingDir, command, output) {
|
|
231
258
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -358,7 +385,7 @@ function apply(ctx, config) {
|
|
|
358
385
|
state.code = code;
|
|
359
386
|
state.signal = signal;
|
|
360
387
|
state.timeUsed = Date.now() - start;
|
|
361
|
-
state.output = state.output.trim();
|
|
388
|
+
state.output = maskCurlOutput(command, state.output.trim());
|
|
362
389
|
// 更新当前目录(如果是 cd 命令且执行成功)
|
|
363
390
|
if (cdValidation.newDir && code === 0) {
|
|
364
391
|
sessionDirs.set(sessionId, cdValidation.newDir);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -227,6 +227,30 @@ function validateCdCommand(command: string, currentDir: string, rootDir: string,
|
|
|
227
227
|
return { valid: true }
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
function maskCurlOutput(command: string, output: string): string {
|
|
231
|
+
if (!output) return output
|
|
232
|
+
if (!/\bcurl\b/i.test(command)) return output
|
|
233
|
+
|
|
234
|
+
const ipv4Regex = /\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g
|
|
235
|
+
return output.replace(ipv4Regex, (ip) => (isPrivateIpv4(ip) ? ip : '*.*.*.*'))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function isPrivateIpv4(ip: string): boolean {
|
|
239
|
+
const octets = ip.split('.').map(Number)
|
|
240
|
+
if (octets.length !== 4) return false
|
|
241
|
+
if (octets.some(octet => Number.isNaN(octet) || octet < 0 || octet > 255)) return false
|
|
242
|
+
|
|
243
|
+
const [a, b] = octets
|
|
244
|
+
|
|
245
|
+
if (a === 10) return true
|
|
246
|
+
if (a === 172 && b >= 16 && b <= 31) return true
|
|
247
|
+
if (a === 192 && b === 168) return true
|
|
248
|
+
if (a === 127) return true
|
|
249
|
+
if (a === 169 && b === 254) return true
|
|
250
|
+
|
|
251
|
+
return false
|
|
252
|
+
}
|
|
253
|
+
|
|
230
254
|
// 渲染终端输出为图片
|
|
231
255
|
async function renderTerminalImage(ctx: Context, workingDir: string, command: string, output: string): Promise<h> {
|
|
232
256
|
if (!ctx.puppeteer) {
|
|
@@ -459,7 +483,7 @@ export function apply(ctx: Context, config: Config) {
|
|
|
459
483
|
state.code = code
|
|
460
484
|
state.signal = signal
|
|
461
485
|
state.timeUsed = Date.now() - start
|
|
462
|
-
state.output = state.output.trim()
|
|
486
|
+
state.output = maskCurlOutput(command, state.output.trim())
|
|
463
487
|
// 更新当前目录(如果是 cd 命令且执行成功)
|
|
464
488
|
if (cdValidation.newDir && code === 0) {
|
|
465
489
|
sessionDirs.set(sessionId, cdValidation.newDir)
|