From 008be228d4d1ebb2e679c73b5b802b8336a75733 Mon Sep 17 00:00:00 2001 From: mmmsssttt404 <931121963@qq.com> Date: Wed, 3 Sep 2025 10:47:35 +0800 Subject: [PATCH 1/4] Create redos.mocha.js --- test/interface/redos.mocha.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/interface/redos.mocha.js diff --git a/test/interface/redos.mocha.js b/test/interface/redos.mocha.js new file mode 100644 index 000000000..b4621c910 --- /dev/null +++ b/test/interface/redos.mocha.js @@ -0,0 +1,33 @@ +process.chdir(__dirname) + +const config = require('../../lib/tools/Config') +const { performance } = require('perf_hooks') +let expect; +before(async () => { + const chai = await import('chai') + expect = chai.expect +}) + + +describe('ReDos Test', function () { + it('should done in 1 s', function () { + // 构造 schema,期望值为数组或者字符串 + const schemaEntry = { + type: ['array', 'string'] + } + // 构造测试用的长字符串 + const value = "a".repeat(100000) + "=" + + const startTime = performance.now() + const result = config._valid('dummyKey', value, schemaEntry) + const endTime = performance.now() + const timeTaken = endTime - startTime + + // 输出匹配结果和耗时(调试用) + console.log(`Time taken: ${timeTaken.toFixed(3)} ms`) + + + // 并断言耗时在合理范围内(比如小于1000毫秒) + expect(timeTaken).to.be.lessThan(1000) + }) +}) From 1bb8236fce741dff04b4c22909766b6c99b84f9d Mon Sep 17 00:00:00 2001 From: mmmsssttt404 <931121963@qq.com> Date: Wed, 3 Sep 2025 10:47:53 +0800 Subject: [PATCH 2/4] Update unit.sh --- test/unit.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit.sh b/test/unit.sh index 127b4b277..9612dc202 100644 --- a/test/unit.sh +++ b/test/unit.sh @@ -99,6 +99,7 @@ D=test/interface runUnitTest $D/bus.spec.mocha.js runUnitTest $D/bus.fork.spec.mocha.js runUnitTest $D/utility.mocha.js +runUnitTest $D/redos.mocha.js echo "============== unit test finished ==============" cat unit_time From 1e0e96c5257041bc19b1fd796ea455c4085bec6e Mon Sep 17 00:00:00 2001 From: mmmsssttt404 <931121963@qq.com> Date: Wed, 3 Sep 2025 10:48:39 +0800 Subject: [PATCH 3/4] Update Config.js --- lib/tools/Config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tools/Config.js b/lib/tools/Config.js index a3da91c4c..0a0b8ba36 100644 --- a/lib/tools/Config.js +++ b/lib/tools/Config.js @@ -200,7 +200,7 @@ Config._valid = function(key, value, sch){ // If first type is Array, but current is String, try to split them. if(scht.length > 1 && type != scht[0] && type == '[object String]'){ if(scht[0] == '[object Array]') { - value = value.split(/([\w\-]+\="[^"]*")|([\w\-]+\='[^']*')|"([^"]*)"|'([^']*)'|\s/) + value = value.split(/(? Date: Wed, 3 Sep 2025 11:50:10 +0800 Subject: [PATCH 4/4] Update json_validation.mocha.js --- test/programmatic/json_validation.mocha.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/programmatic/json_validation.mocha.js b/test/programmatic/json_validation.mocha.js index 496cd9971..2349503b8 100644 --- a/test/programmatic/json_validation.mocha.js +++ b/test/programmatic/json_validation.mocha.js @@ -71,5 +71,21 @@ describe('JSON validation tests', function() { Object.keys(ret.config).should.containDeep(default_values); done(); }); + + it('should split node_args string into array', function () { + const cli = '--max-old-space-size=4096 --use-openssl-ca'; + const expected = ['--max-old-space-size=4096', '--use-openssl-ca']; + + const ret = Config.validateJSON({ + script: 'child.js', + name: 'split-test', + node_args: cli + }); + + ret.errors.length.should.eql(0); + + ret.config.node_args.should.eql(expected); + }); + });