From 76b2c5284bcc1fb0b7066bdac66fd8e4ed12a803 Mon Sep 17 00:00:00 2001 From: Md Nurnobi Date: Tue, 24 Nov 2026 02:49:49 +0000 Subject: [PATCH] fix(fa02): fail-closed install backports, Docker packaging and targeted security regressions --- docker/Dockerfile.server | 2 + docker/Dockerfile.web | 2 + package.json | 3 +- tests/files-manager.test.ts | 86 +++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.server b/docker/Dockerfile.server index 080a50a..42b9fb0 100644 --- a/docker/Dockerfile.server +++ b/docker/Dockerfile.server @@ -1,6 +1,8 @@ FROM node:22-alpine AS dependencies WORKDIR /app +RUN apk add --no-cache git COPY package.json package-lock.json* ./ +COPY patches ./patches RUN if [ -f package-lock.json ]; then npm ci --omit=dev; else npm install --omit=dev --no-audit --no-fund; fi FROM node:22-alpine AS runner diff --git a/docker/Dockerfile.web b/docker/Dockerfile.web index 765f079..233c3c6 100644 --- a/docker/Dockerfile.web +++ b/docker/Dockerfile.web @@ -1,7 +1,9 @@ FROM node:22-alpine AS dependencies WORKDIR /app ENV NODE_ENV=development +RUN apk add --no-cache git COPY package.json package-lock.json* ./ +COPY patches ./patches RUN if [ -f package-lock.json ]; then npm ci --include=dev; else npm install --include=dev --no-audit --no-fund; fi FROM node:22-alpine AS builder diff --git a/package.json b/package.json index 276071b..286f643 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "start:web": "next start", "start:server": "node server/index.js", "lint": "eslint .", - "clean": "next clean" + "clean": "next clean", + "postinstall": "node -e \"const cp=require('node:child_process');for(const n of ['got','glob','minimatch','file-type']){const p='patches/cloudcmd-'+n+'-security.patch';const run=a=>cp.execFileSync('git',['apply',...a,p],{stdio:'ignore'});try{run(['--check']);run([]);console.log('SECURITY_BACKPORT_APPLIED',n)}catch(e){try{run(['--reverse','--check']);console.log('SECURITY_BACKPORT_VERIFIED',n)}catch(x){console.error('SECURITY_BACKPORT_MISMATCH',n);process.exit(1)}}}\"" }, "dependencies": { "@hookform/resolvers": "^5.2.1", diff --git a/tests/files-manager.test.ts b/tests/files-manager.test.ts index 592ed2f..155c683 100644 --- a/tests/files-manager.test.ts +++ b/tests/files-manager.test.ts @@ -310,3 +310,89 @@ test('FM-REQ-07..09: proxy routing, SW bypass, Sidebar nav, and /vcon/files work assert.ok(workspace.includes('files-manager-offline')); assert.ok(workspace.includes('files-manager-iframe')); }); + +// Security acceptance: original upstream fixes backported to the exact Cloudcmd +// transitive versions. No public API, UI, or File Manager behavior is changed. +test('SEC-FA02-GOT: block redirects from normal HTTP to UNIX sockets and retain normal redirects', async () => { + const got = require('../node_modules/got'); + const server = http.createServer((req, res) => { + if (req.url === '/unix') { + res.writeHead(302, { location: 'unix:/var/run/docker.sock:/containers/json' }).end(); + } else if (req.url === '/hostname') { + res.writeHead(302, { location: 'http://unix:/var/run/docker.sock:/containers/json' }).end(); + } else if (req.url === '/normal') { + res.writeHead(302, { location: '/ok' }).end(); + } else { + res.writeHead(200, { 'content-type': 'text/plain' }).end('ok'); + } + }); + await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)); + const addr = server.address(); + assert.ok(addr && typeof addr !== 'string'); + const origin = `http://127.0.0.1:${addr.port}`; + try { + for (const endpoint of ['/unix', '/hostname']) { + await assert.rejects( + got(origin + endpoint), + (error: Error) => error.name === 'RequestError' && /Cannot redirect to UNIX socket/.test(error.message), + ); + } + assert.equal((await got(origin + '/normal')).body, 'ok'); + } finally { + await new Promise((resolve, reject) => + server.close((error) => (error ? reject(error) : resolve())), + ); + } +}); + +test('SEC-FA02-GLOB: four abort guards in installed CJS/ESM and normal/aborted traversal', async () => { + const paths = [ + 'node_modules/glob/dist/commonjs/walker.js', + 'node_modules/glob/dist/esm/walker.js', + 'node_modules/onezip/node_modules/glob/dist/commonjs/walker.js', + ]; + for (const name of paths) { + const contents = fs.readFileSync(path.resolve(name), 'utf8'); + assert.equal((contents.match(/if \(this\.signal\?\.aborted\)\s+return cb\(\)/g) || []).length, 4, name); + } + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'datastack-fa02-glob-')); + try { + fs.mkdirSync(path.join(root, 'nested')); + fs.writeFileSync(path.join(root, 'nested', 'file.js'), 'fixture'); + const { glob } = require('../node_modules/glob'); + assert.deepEqual(await glob('**/*.js', { cwd: root, nodir: true }), ['nested/file.js']); + const controller = new AbortController(); + controller.abort(new Error('expected abort')); + await assert.rejects(glob('**/*', { cwd: root, signal: controller.signal }), /abort/i); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } +}); + +test('SEC-FA02-MINIMATCH: older-major pattern expansion is bounded and normal matching preserved', () => { + 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 compiled = new Minimatch(pattern, { optimizationLevel: 2, braceExpandMax: 64 }); + assert.ok(compiled.set.length <= 64, `${modulePath}: ${compiled.set.length}`); + assert.equal(new Minimatch('**/*.js', { optimizationLevel: 2 }).match('src/main.js'), true); + } +}); + +test('SEC-FA02-FILETYPE: both nested older-major parsers terminate for malformed ASF', () => { + const { spawnSync } = require('node:child_process'); + 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('3026b2758e66cf11a6d9000000000000000000000000000000000000000000000000000000000000000000000000','hex');f.fromBuffer(b).then(v=>{if(!v||v.ext!=='asf')process.exit(1)}).catch(()=>process.exit(1));`; + const child = spawnSync(process.execPath, ['-e', code], { + cwd: process.cwd(), encoding: 'utf8', timeout: 5000, + }); + assert.equal(child.status, 0, `${modulePath}: ${child.stderr} ${child.stdout} ${child.error || ''}`); + } +}); +