From 32cce8f6587f84a126a8be898022f9699af71a31 Mon Sep 17 00:00:00 2001 From: Md Nurnobi Date: Tue, 24 Nov 2026 02:46:18 +0000 Subject: [PATCH] ci(fa02): focused isolated backport integrity, applicability and behavior proof [skip ci] --- .gitea/workflows/datastack-docker-ci.yml | 105 ++++++++++++++++++----- 1 file changed, 83 insertions(+), 22 deletions(-) diff --git a/.gitea/workflows/datastack-docker-ci.yml b/.gitea/workflows/datastack-docker-ci.yml index 69b61d6..1dde364 100644 --- a/.gitea/workflows/datastack-docker-ci.yml +++ b/.gitea/workflows/datastack-docker-ci.yml @@ -59,31 +59,92 @@ jobs: with: github-server-url: https://dev.ivib.cc persist-credentials: false - - name: Inspect locked production package sources in disposable checkout + - name: Security backport applicability and behavioral proof run: | set -eu npm ci --omit=dev --ignore-scripts --no-audit --no-fund node <<'NODE' - const fs = require('node:fs'); - const crypto = require('node:crypto'); - const targets = [ - ['got10', 'node_modules/got/dist/source/request-as-event-emitter.js', /redirectUrl|headers\.location|unix/i], - ['glob10', 'node_modules/glob/dist/commonjs/walker.js', /this\.signal.*aborted|walkCB\(/], - ['glob13', 'node_modules/onezip/node_modules/glob/dist/commonjs/walker.js', /this\.signal.*aborted|walkCB\(/], - ['minimatch9', 'node_modules/glob/node_modules/minimatch/dist/commonjs/index.js', /firstPhasePreProcess|secondPhasePreProcess|globParts\.length|didSomething/], - ['minimatch10', 'node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js', /firstPhasePreProcess|secondPhasePreProcess|globParts\.length|didSomething/], - ['filetype16-join', 'node_modules/join-io/node_modules/ponse/node_modules/file-type/core.js', /tokenizer\.position \+ 24|readHeader\(|await tokenizer\.ignore\(payload\)/], - ['filetype16-rest', 'node_modules/restbox/node_modules/ponse/node_modules/file-type/core.js', /tokenizer\.position \+ 24|readHeader\(|await tokenizer\.ignore\(payload\)/], - ]; - for (const [name,path,re] of targets) { - if (!fs.existsSync(path)) {console.log('PROBE_MISSING', name, path);continue} - const src=fs.readFileSync(path,'utf8'),lines=src.split('\n'); - const indices=[]; - for(let i=0;i{ + if(req.url==='/unix')return res.writeHead(302,{location:'unix:/var/run/docker.sock:/containers/json'}).end(); + if(req.url==='/hostname')return res.writeHead(302,{location:'http://unix:/var/run/docker.sock:/containers/json'}).end(); + if(req.url==='/normal')return res.writeHead(302,{location:'/ok'}).end(); + res.writeHead(200,{'content-type':'text/plain'}).end('ok'); + }); + await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve)); + const origin='http://127.0.0.1:'+server.address().port; + try { + for(const endpoint of ['/unix','/hostname']){ + await assert.rejects(got(origin+endpoint),e=>e.name==='RequestError' && /Cannot redirect to UNIX socket/.test(e.message),endpoint); + } + assert.equal((await got(origin+'/normal')).body,'ok'); + console.log('SECURITY_GOT_REDIRECT_BLOCK_AND_NORMAL_REDIRECT_PASS'); + }finally{await new Promise(r=>server.close(r))} + for(const modulePath of ['./node_modules/glob/node_modules/minimatch','./node_modules/onezip/node_modules/glob/node_modules/minimatch']){ + const {Minimatch}=require(modulePath); + const pattern=Array(12).fill('**/../a/b').join('/'); + const m=new Minimatch(pattern,{optimizationLevel:2,braceExpandMax:64}); + assert.ok(m.set.length<=64,'minimatch amplification exceeded cap: '+m.set.length); + assert.equal(new Minimatch('**/*.js',{optimizationLevel:2}).match('src/main.js'),true); + console.log('SECURITY_MINIMATCH_BOUNDED_AND_NORMAL_PASS',modulePath,m.set.length); + } + const glob10c=fs.readFileSync('node_modules/glob/dist/commonjs/walker.js','utf8'); + const glob10e=fs.readFileSync('node_modules/glob/dist/esm/walker.js','utf8'); + const glob13c=fs.readFileSync('node_modules/onezip/node_modules/glob/dist/commonjs/walker.js','utf8'); + const count=s=>(s.match(/if \(this\.signal\?\.aborted\)\s+return cb\(\)/g)||[]).length; + assert.equal(count(glob10c),4);assert.equal(count(glob10e),4);assert.equal(count(glob13c),4); + const dir=fs.mkdtempSync(path.join(os.tmpdir(),'datastack-glob-sec-')); + try { + fs.mkdirSync(path.join(dir,'nested'));fs.writeFileSync(path.join(dir,'nested','file.js'),'fixture'); + const {glob}=require('./node_modules/glob'); + const found=await glob('**/*.js',{cwd:dir,nodir:true}); + assert.deepEqual(found,['nested/file.js']); + const ac=new AbortController();ac.abort(new Error('expected abort')); + await assert.rejects(glob('**/*',{cwd:dir,signal:ac.signal}),/abort/i); + }finally{fs.rmSync(dir,{recursive:true,force:true})} + console.log('SECURITY_GLOB_ABORT_AND_NORMAL_WALK_PASS'); + for(const modulePath of ['./node_modules/join-io/node_modules/ponse/node_modules/file-type','./node_modules/restbox/node_modules/ponse/node_modules/file-type']){ + const code="const f=require("+JSON.stringify(modulePath)+"); const b=Buffer.from('3026b2758e66cf11a6d9000000000000000000000000000000000000000000000000000000000000000000000000000000','hex');f.fromBuffer(b).then(r=>{if(!r||r.ext!=='asf')process.exit(1);console.log('ASF_FIX_PASS')}).catch(()=>process.exit(1));"; + const child=cp.spawnSync(process.execPath,['-e',code],{cwd:process.cwd(),encoding:'utf8',timeout:5000}); + assert.equal(child.status,0,'file-type ASF probe: '+child.stderr+' '+child.stdout+' '+child.error); + } + console.log('SECURITY_NESTED_FILE_TYPE_ASF_PROGRESS_PASS'); + console.log('SECURITY_ALL_TARGETED_PROBES_PASS'); + } + main().catch(error=>{console.error('SECURITY_BACKPORT_PROOF_FAILED',error);process.exitCode=1}); NODE