ci(fa02): focused isolated backport integrity, applicability and behavior proof [skip ci]

This commit is contained in:
victorsteele428 committed 2026-11-24 02:46:18 +00:00
1 parent 0e079f5fa0
commit 32cce8f658
1 file changed
+83 -22
+83 -22
View File
@@ -59,31 +59,92 @@ jobs:
with: with:
github-server-url: https://dev.ivib.cc github-server-url: https://dev.ivib.cc
persist-credentials: false persist-credentials: false
- name: Inspect locked production package sources in disposable checkout - name: Security backport applicability and behavioral proof
run: | run: |
set -eu set -eu
npm ci --omit=dev --ignore-scripts --no-audit --no-fund npm ci --omit=dev --ignore-scripts --no-audit --no-fund
node <<'NODE' node <<'NODE'
const fs = require('node:fs'); const fs = require('node:fs'), crypto = require('node:crypto'), assert = require('node:assert/strict');
const crypto = require('node:crypto'); const targets = {
const targets = [ 'node_modules/got/dist/source/request-as-event-emitter.js': '20056793d1233ae2b503c1f3c63fcd17a595d58cc52ab59ecf751c4b5d3f6e11',
['got10', 'node_modules/got/dist/source/request-as-event-emitter.js', /redirectUrl|headers\.location|unix/i], 'node_modules/glob/dist/commonjs/walker.js': '1138ced9d5429681a1740af32d13391a38184a3376d1d9d56eea64b7a43274a1',
['glob10', 'node_modules/glob/dist/commonjs/walker.js', /this\.signal.*aborted|walkCB\(/], 'node_modules/onezip/node_modules/glob/dist/commonjs/walker.js': '4eca6e1f2fd9c9ef7469977a12c7e9bd6503bc7a9257ccdc8e79b346ec34fccd',
['glob13', 'node_modules/onezip/node_modules/glob/dist/commonjs/walker.js', /this\.signal.*aborted|walkCB\(/], 'node_modules/glob/node_modules/minimatch/dist/commonjs/index.js': 'a958a41536f57484cc427a03a10a6a094eb062a004c58261add4dbb6dd77bbda',
['minimatch9', 'node_modules/glob/node_modules/minimatch/dist/commonjs/index.js', /firstPhasePreProcess|secondPhasePreProcess|globParts\.length|didSomething/], 'node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js': 'd224f71f20d7c206fcc5b7e9f747324c7698345a0b2c28d717dd9cf698306783',
['minimatch10', 'node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js', /firstPhasePreProcess|secondPhasePreProcess|globParts\.length|didSomething/], 'node_modules/join-io/node_modules/ponse/node_modules/file-type/core.js': '34e07cdaeb5c2df273758ba60d8630008571ac350b5fde134ced0bba7948a6d7',
['filetype16-join', 'node_modules/join-io/node_modules/ponse/node_modules/file-type/core.js', /tokenizer\.position \+ 24|readHeader\(|await tokenizer\.ignore\(payload\)/], 'node_modules/restbox/node_modules/ponse/node_modules/file-type/core.js': '34e07cdaeb5c2df273758ba60d8630008571ac350b5fde134ced0bba7948a6d7',
['filetype16-rest', 'node_modules/restbox/node_modules/ponse/node_modules/file-type/core.js', /tokenizer\.position \+ 24|readHeader\(|await tokenizer\.ignore\(payload\)/], };
]; for (const [path, expected] of Object.entries(targets)) {
for (const [name,path,re] of targets) { const current = crypto.createHash('sha256').update(fs.readFileSync(path)).digest('hex');
if (!fs.existsSync(path)) {console.log('PROBE_MISSING', name, path);continue} assert.equal(current, expected, 'locked package integrity mismatch: '+path);
const src=fs.readFileSync(path,'utf8'),lines=src.split('\n');
const indices=[];
for(let i=0;i<lines.length;i++)if(re.test(lines[i]))indices.push(i);
console.log('PROBE_FILE',JSON.stringify({name,path,bytes:Buffer.byteLength(src),sha256:crypto.createHash('sha256').update(src).digest('hex'),hits:indices.length}));
for(const i of indices.slice(0, name.startsWith('minimatch') ? 9 : name.startsWith('filetype')?5:11)){
const lo=Math.max(0,i-3),hi=Math.min(lines.length,i+5);
console.log('PROBE_SNIPPET',JSON.stringify({name,line:i+1,range:[lo+1,hi],text:lines.slice(lo,hi).join('\n')}));
}
} }
console.log('SECURITY_ORIGINAL_INSTALLED_SOURCE_INTEGRITY_PASS',Object.keys(targets).length);
NODE
for p in patches/cloudcmd-got-security.patch patches/cloudcmd-glob-security.patch patches/cloudcmd-minimatch-security.patch patches/cloudcmd-file-type-security.patch; do
git apply --check "$p"
git apply "$p"
git apply --reverse --check "$p"
echo SECURITY_PATCH_APPLIED "$p"
done
node --check node_modules/got/dist/source/request-as-event-emitter.js
node --check node_modules/glob/dist/commonjs/walker.js
node --check node_modules/glob/dist/esm/walker.js
node --check node_modules/glob/node_modules/minimatch/dist/commonjs/index.js
node --check node_modules/glob/node_modules/minimatch/dist/esm/index.js
node --check node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js
node --check node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/esm/index.js
node --check node_modules/join-io/node_modules/ponse/node_modules/file-type/core.js
node --check node_modules/restbox/node_modules/ponse/node_modules/file-type/core.js
node <<'NODE'
const assert = require('node:assert/strict');
const fs=require('node:fs'), os=require('node:os'), path=require('node:path'), http=require('node:http'), cp=require('node:child_process');
async function main(){
const got = require('./node_modules/got');
const server=http.createServer((req,res)=>{
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 NODE