diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22a0eb07..c39caf27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -297,6 +297,11 @@ jobs: - name: Build service run: bun run build + - name: Verify patched dependency compatibility under Node and Bun + run: | + node --test scripts/dependency-compat.test.cjs + bun test scripts/dependency-compat.test.cjs + - name: Bun tests run: bun run test diff --git a/docker/Dockerfile.worker-sandbox b/docker/Dockerfile.worker-sandbox index 824039ec..fc2e88cd 100644 --- a/docker/Dockerfile.worker-sandbox +++ b/docker/Dockerfile.worker-sandbox @@ -94,6 +94,7 @@ RUN chmod +x /package-init.sh && FORCE_REBUILD=true /package-init.sh FROM oven/bun:1.4.4 AS worker-builder WORKDIR /app COPY service/package.json service/bun.lock ./ +COPY service/patches ./patches RUN bun install --frozen-lockfile COPY service/src ./src COPY packages/code/src /packages/code/src @@ -263,6 +264,7 @@ RUN chmod +x /usr/local/bin/launcher-entrypoint.sh /usr/local/bin/start-direct-s # --- Worker --- WORKDIR /worker COPY service/package.json service/bun.lock ./ +COPY service/patches ./patches RUN bun install --frozen-lockfile --production COPY --from=worker-builder /app/.build ./.build COPY --from=worker-builder /app/src ./src diff --git a/service/Dockerfile b/service/Dockerfile index 805d6c5c..f36b111e 100644 --- a/service/Dockerfile +++ b/service/Dockerfile @@ -6,10 +6,12 @@ WORKDIR /app FROM base AS install RUN mkdir -p /temp/dev COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile RUN mkdir -p /temp/prod COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production # Build all entry points diff --git a/service/Dockerfile.api b/service/Dockerfile.api index 6a571db8..41210bc9 100644 --- a/service/Dockerfile.api +++ b/service/Dockerfile.api @@ -8,10 +8,12 @@ WORKDIR /app FROM base AS install RUN mkdir -p /temp/dev COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile RUN mkdir -p /temp/prod COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production # Build the API server diff --git a/service/Dockerfile.bun b/service/Dockerfile.bun index 941c7183..3e70ecf2 100644 --- a/service/Dockerfile.bun +++ b/service/Dockerfile.bun @@ -5,12 +5,14 @@ WORKDIR /usr/src/app # Install dependencies FROM base AS install RUN mkdir -p /temp/dev -COPY service/package.json /temp/dev/ +COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile # Install production dependencies RUN mkdir -p /temp/prod -COPY service/package.json /temp/prod/ +COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production # Build stage diff --git a/service/Dockerfile.egress-gateway b/service/Dockerfile.egress-gateway index cde97938..832bec10 100644 --- a/service/Dockerfile.egress-gateway +++ b/service/Dockerfile.egress-gateway @@ -5,10 +5,12 @@ WORKDIR /app FROM base AS install RUN mkdir -p /temp/dev COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile RUN mkdir -p /temp/prod COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production FROM oven/bun:1.4.4 AS production diff --git a/service/Dockerfile.local b/service/Dockerfile.local index 216e9c31..2c124728 100644 --- a/service/Dockerfile.local +++ b/service/Dockerfile.local @@ -6,10 +6,12 @@ WORKDIR /app FROM base AS install RUN mkdir -p /temp/dev COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile RUN mkdir -p /temp/prod COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production # Build the local API diff --git a/service/Dockerfile.node b/service/Dockerfile.node index dc964fce..45b56d5d 100644 --- a/service/Dockerfile.node +++ b/service/Dockerfile.node @@ -1,8 +1,11 @@ # Base stage for shared steps +FROM oven/bun:1.4.4 AS dependency-tool FROM node:22.23.4-slim AS base +COPY --from=dependency-tool /usr/local/bin/bun /usr/local/bin/bun WORKDIR /app -COPY service/package*.json ./ -RUN npm ci +COPY service/package.json service/bun.lock ./ +COPY service/patches ./patches +RUN bun install --frozen-lockfile # Build stage FROM base AS builder @@ -14,10 +17,12 @@ RUN npx tsc -p tsconfig.json # Production stage FROM node:22.23.4-slim AS production +COPY --from=dependency-tool /usr/local/bin/bun /usr/local/bin/bun ENV NODE_ENV=production WORKDIR /app -COPY service/package*.json ./ -RUN npm ci --only=production +COPY service/package.json service/bun.lock ./ +COPY service/patches ./patches +RUN bun install --frozen-lockfile --production COPY --from=builder /app/.build ./.build EXPOSE 3000 CMD ["node", ".build/file-server.js"] diff --git a/service/Dockerfile.service b/service/Dockerfile.service index dea1cea3..fc691031 100644 --- a/service/Dockerfile.service +++ b/service/Dockerfile.service @@ -6,10 +6,12 @@ WORKDIR /usr/src/app FROM base AS install RUN mkdir -p /temp/dev COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile RUN mkdir -p /temp/prod COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production # Build stage diff --git a/service/Dockerfile.tool-call-server b/service/Dockerfile.tool-call-server index 95543ee7..04036197 100644 --- a/service/Dockerfile.tool-call-server +++ b/service/Dockerfile.tool-call-server @@ -6,10 +6,12 @@ WORKDIR /app FROM base AS install RUN mkdir -p /temp/dev COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile RUN mkdir -p /temp/prod COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production # Production stage diff --git a/service/Dockerfile.worker b/service/Dockerfile.worker index 059ce2aa..be68e16e 100644 --- a/service/Dockerfile.worker +++ b/service/Dockerfile.worker @@ -9,10 +9,12 @@ WORKDIR /app FROM base AS install RUN mkdir -p /temp/dev COPY service/package.json service/bun.lock /temp/dev/ +COPY service/patches /temp/dev/patches RUN cd /temp/dev && bun install --frozen-lockfile RUN mkdir -p /temp/prod COPY service/package.json service/bun.lock /temp/prod/ +COPY service/patches /temp/prod/patches RUN cd /temp/prod && bun install --frozen-lockfile --production # Build the worker server diff --git a/service/bun.lock b/service/bun.lock index ad84c9e7..c33f7061 100644 --- a/service/bun.lock +++ b/service/bun.lock @@ -1,5 +1,5 @@ { - "lockfileVersion": 1, + "lockfileVersion": 3, "configVersion": 1, "workspaces": { "": { @@ -50,8 +50,19 @@ }, }, }, + "patchedDependencies": { + "minio@8.0.7": "patches/minio@8.0.7.patch", + "deepmerge@4.3.1": "patches/deepmerge@4.3.1.patch", + }, "overrides": { + "@types/minimatch": "5.1.2", + "@typescript-eslint/typescript-estree": { + "minimatch": "11.0.1", + }, "decode-uri-component": "0.5.1", + "minio": { + "stream-json": "3.9.0", + }, "proxy-addr": "2.0.8", "qs": "6.16.1", "uuid": "11.1.1", @@ -125,6 +136,8 @@ "@ioredis/commands": ["@ioredis/commands@1.4.0", "", {}, "sha512-aFT2yemJJo+TZCmieA7qnYGQooOS7QfNmYrzGtsYd3g9j5iDP8AimYYAesf79ohjbLG12XxC4nG5DyEnC88AsQ=="], + "@isaacs/nonrecursive-glob-match": ["@isaacs/nonrecursive-glob-match@1.1.0", "", {}, "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw=="], + "@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.2", "", {}, "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw=="], "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.5.5", "", {}, "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og=="], @@ -241,7 +254,7 @@ "@types/mime": ["@types/mime@1.3.5", "", {}, "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w=="], - "@types/minimatch": ["@types/minimatch@6.0.0", "", { "dependencies": { "minimatch": "*" } }, "sha512-zmPitbQ8+6zNutpwgcQuLcsEpn/Cj54Kbn7L5pX0Os5kdWplB7xPgEh/g+SWOB/qmows2gpuCaPyduq8ZZRnxA=="], + "@types/minimatch": ["@types/minimatch@5.1.2", "", {}, "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA=="], "@types/node": ["@types/node@22.19.3", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-1N9SBnWYOJTrNZCdh/yJE+t910Y128BoyY+zBLWhL3r0TYzlTmFdXrPwHL9DyFZmlEXNQQolTZh3KHV31QDhyA=="], @@ -959,9 +972,9 @@ "stop-iteration-iterator": ["stop-iteration-iterator@1.1.0", "", { "dependencies": { "es-errors": "^1.3.0", "internal-slot": "^1.1.0" } }, "sha512-eLoXW/DHyl62zxY4SCaIgnRhuMr6ri4juEYARS8E6sCEqzKpOiE521Ucofdx+KnDZl5xmvGYaaKCk5FEOxJCoQ=="], - "stream-chain": ["stream-chain@2.2.5", "", {}, "sha512-1TJmBx6aSWqZ4tx7aTpBDXK0/e2hhcNSTV8+CbFJtDjbb+I1mZ8lHit0Grw9GRT+6JbIrrDd8esncgBi8aBXGA=="], + "stream-chain": ["stream-chain@4.4.2", "", {}, "sha512-6WQtf7XW70N8/IXV4DfpTswi0VHTahsB0nO5UlLGp5HarJN+Q7VHT5HvBMlH9x0x77e+kJFnQkhkCdvFkwv2Vw=="], - "stream-json": ["stream-json@1.9.1", "", { "dependencies": { "stream-chain": "^2.2.5" } }, "sha512-uWkjJ+2Nt/LO9Z/JyKZbMusL8Dkh97uUBTv3AJQ74y07lVahLY4eEFsPsE97pxYBwr8nnjMAIch5eqI0gPShyw=="], + "stream-json": ["stream-json@3.9.0", "", { "dependencies": { "stream-chain": "^4.4.2" } }, "sha512-kL2w6owYCdzCRApK9/9HI7Vgrd+0iWE5tTGc8P/AS2AdPoHcFTQwUek66sbMpfaX73lgHvDN+u1AoRC/dzB1Hw=="], "streamsearch": ["streamsearch@1.1.0", "", {}, "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg=="], @@ -1099,11 +1112,9 @@ "@eslint/eslintrc/ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], - "@types/minimatch/minimatch": ["minimatch@9.0.7", "", { "dependencies": { "brace-expansion": "^5.0.2" } }, "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg=="], - "@types/serve-static/@types/send": ["@types/send@0.17.6", "", { "dependencies": { "@types/mime": "^1", "@types/node": "*" } }, "sha512-Uqt8rPBE8SY0RK8JB1EzVOIZ32uqy8HwdxCnoCOsYrvnswqmFZ/k+9Ikidlk/ImhsdvBsloHbAlewb2IEBV/Og=="], - "@typescript-eslint/typescript-estree/minimatch": ["minimatch@9.0.7", "", { "dependencies": { "brace-expansion": "^5.0.2" } }, "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg=="], + "@typescript-eslint/typescript-estree/minimatch": ["minimatch@11.0.1", "", { "dependencies": { "@isaacs/nonrecursive-glob-match": "^1.0.1", "brace-expansion": "^5.0.12" } }, "sha512-t+Vn6DX4wPCxS23y03C0uhF7S1jpi1GfqPrnlEipCJaA2ykiNbMkVlDutZtmvLfRcUN6R8AYVlzTsQrT4RZoLQ=="], "@typescript-eslint/typescript-estree/semver": ["semver@7.7.3", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q=="], @@ -1161,8 +1172,6 @@ "@aws-sdk/middleware-sdk-s3/@aws-sdk/signature-v4-multi-region/@smithy/signature-v4": ["@smithy/signature-v4@5.6.9", "", { "dependencies": { "@smithy/core": "^3.29.8", "@smithy/types": "^4.16.1", "tslib": "^2.6.2" } }, "sha512-g5rnEii/mkT0mjVJmlsaOfyNBtHNTecD9Lo4NP8D5HzMUEnZNpz7/FbvBCjNcV4vteHFAxOGiLUYNxPkDZZAPw=="], - "@types/minimatch/minimatch/brace-expansion": ["brace-expansion@5.0.12", "", { "dependencies": { "balanced-match": "^4.0.2" } }, "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ=="], - "@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@5.0.12", "", { "dependencies": { "balanced-match": "^4.0.2" } }, "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ=="], "body-parser/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], @@ -1183,8 +1192,6 @@ "send/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], - "@types/minimatch/minimatch/brace-expansion/balanced-match": ["balanced-match@4.0.4", "", {}, "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA=="], - "@typescript-eslint/typescript-estree/minimatch/brace-expansion/balanced-match": ["balanced-match@4.0.4", "", {}, "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA=="], } } diff --git a/service/package.json b/service/package.json index 5373d10a..bcb25d50 100644 --- a/service/package.json +++ b/service/package.json @@ -74,9 +74,20 @@ "typescript": "^5.5.4" }, "overrides": { + "@types/minimatch": "5.1.2", + "@typescript-eslint/typescript-estree": { + "minimatch": "11.0.1" + }, "decode-uri-component": "0.5.1", "uuid": "11.1.1", "qs": "6.16.1", - "proxy-addr": "2.0.8" + "proxy-addr": "2.0.8", + "minio": { + "stream-json": "3.9.0" + } + }, + "patchedDependencies": { + "deepmerge@4.3.1": "patches/deepmerge@4.3.1.patch", + "minio@8.0.7": "patches/minio@8.0.7.patch" } } diff --git a/service/patches/README.md b/service/patches/README.md new file mode 100644 index 00000000..12f29164 --- /dev/null +++ b/service/patches/README.md @@ -0,0 +1,39 @@ +# Dependency security patches + +Install with Bun 1.4.4 and the committed lockfile. The service Dockerfiles copy +this directory before installing dependencies so development, build, and +production installs apply the same patches. Do not replace these installs with +`npm install`: npm does not apply Bun's `patchedDependencies`. + +## deepmerge 4.3.1 + +[GHSA-gcqx-w48m-w2h4](https://github.com/advisories/GHSA-gcqx-w48m-w2h4) +has no patched release. The Rollup resolver brings in this build dependency. +The patch defines destination keys as own data properties instead of invoking +inherited setters, including `__proto__`. It covers the source and both shipped +CommonJS/UMD builds while retaining normal objects, recursive merges, symbols, +and concatenated arrays. + +`bun audit` still reports the original version. This warning is not suppressed; +remove the patch only after adopting and testing a fixed upstream release. +Regression tests are in `src/dependency-security.test.ts`. + +## MinIO 8.0.7 / stream-json 3.9.0 + +MinIO still requests stream-json 1.x. The scoped override installs patched +stream-json 3.9.0; the MinIO patch adapts its sole parser call site to the new +lowercase module path and Node stream adapter. Both the CommonJS and ESM builds +are patched, together with the TypeScript source. A version override alone would +break MinIO imports and notification parsing. + +`scripts/dependency-compat.test.cjs` checks both MinIO builds under Node and Bun, +including split UTF-8 records and malformed JSON. Existing MinIO upload and +listing tests cover the storage operations used by the service. Remove the +patch and override after MinIO ships a compatible patched parser dependency. + +## minimatch + +Only typescript-estree's minimatch dependency is upgraded to 11.0.1. Older +ESLint/glob callers retain the compatible callable v3 API. The deprecated +`@types/minimatch` stub is replaced with 5.1.2, which provides declarations +without installing an unnecessary runtime minimatch dependency. diff --git a/service/patches/deepmerge@4.3.1.patch b/service/patches/deepmerge@4.3.1.patch new file mode 100644 index 00000000..fa5aff45 --- /dev/null +++ b/service/patches/deepmerge@4.3.1.patch @@ -0,0 +1,99 @@ +diff --git a/dist/cjs.js b/dist/cjs.js +index 7c36cbdd06cc22c92d590be3f87a08a91ca06b40..31c7cd61aba82cda6f22c951da4bcbbf53eb5928 100644 +--- a/dist/cjs.js ++++ b/dist/cjs.js +@@ -77,10 +77,15 @@ function propertyIsUnsafe(target, key) { + } + + function mergeObject(target, source, options) { ++ function setOwn(key, value) { ++ Object.defineProperty(destination, key, { ++ value: value, writable: true, enumerable: true, configurable: true ++ }); ++ } + var destination = {}; + if (options.isMergeableObject(target)) { + getKeys(target).forEach(function(key) { +- destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); ++ setOwn(key, cloneUnlessOtherwiseSpecified(target[key], options)); + }); + } + getKeys(source).forEach(function(key) { +@@ -89,9 +94,9 @@ function mergeObject(target, source, options) { + } + + if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { +- destination[key] = getMergeFunction(key, options)(target[key], source[key], options); ++ setOwn(key, getMergeFunction(key, options)(target[key], source[key], options)); + } else { +- destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); ++ setOwn(key, cloneUnlessOtherwiseSpecified(source[key], options)); + } + }); + return destination +diff --git a/dist/umd.js b/dist/umd.js +index 4071e7c56ec8e5273fe166f6e723ac460fab8b72..da8d43afef6fc2b964d08e2c0b9f2895dac62714 100644 +--- a/dist/umd.js ++++ b/dist/umd.js +@@ -81,10 +81,15 @@ + } + + function mergeObject(target, source, options) { ++ function setOwn(key, value) { ++ Object.defineProperty(destination, key, { ++ value: value, writable: true, enumerable: true, configurable: true ++ }); ++ } + var destination = {}; + if (options.isMergeableObject(target)) { + getKeys(target).forEach(function(key) { +- destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); ++ setOwn(key, cloneUnlessOtherwiseSpecified(target[key], options)); + }); + } + getKeys(source).forEach(function(key) { +@@ -93,9 +98,9 @@ + } + + if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { +- destination[key] = getMergeFunction(key, options)(target[key], source[key], options); ++ setOwn(key, getMergeFunction(key, options)(target[key], source[key], options)); + } else { +- destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); ++ setOwn(key, cloneUnlessOtherwiseSpecified(source[key], options)); + } + }); + return destination +diff --git a/index.js b/index.js +index 77968aed5d456cccc294f60912ef381fa1e52a7b..30a63b65af6860a591c959d1a8f2bc5c4ee169fd 100644 +--- a/index.js ++++ b/index.js +@@ -52,10 +52,15 @@ function propertyIsUnsafe(target, key) { + } + + function mergeObject(target, source, options) { ++ function setOwn(key, value) { ++ Object.defineProperty(destination, key, { ++ value: value, writable: true, enumerable: true, configurable: true ++ }) ++ } + var destination = {} + if (options.isMergeableObject(target)) { + getKeys(target).forEach(function(key) { +- destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) ++ setOwn(key, cloneUnlessOtherwiseSpecified(target[key], options)) + }) + } + getKeys(source).forEach(function(key) { +@@ -64,9 +69,9 @@ function mergeObject(target, source, options) { + } + + if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { +- destination[key] = getMergeFunction(key, options)(target[key], source[key], options) ++ setOwn(key, getMergeFunction(key, options)(target[key], source[key], options)) + } else { +- destination[key] = cloneUnlessOtherwiseSpecified(source[key], options) ++ setOwn(key, cloneUnlessOtherwiseSpecified(source[key], options)) + } + }) + return destination diff --git a/service/patches/minio@8.0.7.patch b/service/patches/minio@8.0.7.patch new file mode 100644 index 00000000..5b3a5cc6 --- /dev/null +++ b/service/patches/minio@8.0.7.patch @@ -0,0 +1,66 @@ +diff --git a/dist/esm/notification.mjs b/dist/esm/notification.mjs +index 2fe075b73a9f98ece945993ebc151f601e0d52ee..6b315fdde51a8893275324a8a5ed1d7f1c858179 100644 +--- a/dist/esm/notification.mjs ++++ b/dist/esm/notification.mjs +@@ -15,7 +15,7 @@ + */ + + import { EventEmitter } from 'eventemitter3'; +-import jsonLineParser from 'stream-json/jsonl/Parser.js'; ++import jsonLineParser from 'stream-json/jsonl/parser.js'; + import { DEFAULT_REGION } from "./helpers.mjs"; + import { pipesetup, uriEscape } from "./internal/helper.mjs"; + +@@ -176,7 +176,7 @@ export class NotificationPoller extends EventEmitter { + bucketName: this.bucketName, + query + }, '', [200], region).then(response => { +- const asm = jsonLineParser.make(); ++ const asm = jsonLineParser.asStream(); + pipesetup(response, asm).on('data', data => { + // Data is flushed periodically (every 5 seconds), so we should + // handle it after flushing from the JSON parser. +diff --git a/dist/main/notification.js b/dist/main/notification.js +index 8d8e8b389bc313de072c603b302e4c39d373d345..34cea64c9ce2fac01012e12743afb1d7d3878593 100644 +--- a/dist/main/notification.js ++++ b/dist/main/notification.js +@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { + value: true + }); + var _eventemitter = require("eventemitter3"); +-var _Parser = require("stream-json/jsonl/Parser.js"); ++var _Parser = require("stream-json/jsonl/parser.js"); + var _helpers = require("./helpers.js"); + var _helper = require("./internal/helper.js"); + /* +@@ -196,7 +196,7 @@ class NotificationPoller extends _eventemitter.EventEmitter { + bucketName: this.bucketName, + query + }, '', [200], region).then(response => { +- const asm = _Parser.make(); ++ const asm = _Parser.default.asStream(); + (0, _helper.pipesetup)(response, asm).on('data', data => { + // Data is flushed periodically (every 5 seconds), so we should + // handle it after flushing from the JSON parser. +diff --git a/src/notification.ts b/src/notification.ts +index 64c24112d225a234d3b5acf06043020e9fe414af..782ef265f50751101d002b9148800495f992b85c 100644 +--- a/src/notification.ts ++++ b/src/notification.ts +@@ -15,7 +15,7 @@ + */ + + import { EventEmitter } from 'eventemitter3' +-import jsonLineParser from 'stream-json/jsonl/Parser.js' ++import jsonLineParser from 'stream-json/jsonl/parser.js' + + import { DEFAULT_REGION } from './helpers.ts' + import type { TypedClient } from './internal/client.ts' +@@ -216,7 +216,7 @@ export class NotificationPoller extends EventEmitter<{ + + this.client.makeRequestAsync({ method, bucketName: this.bucketName, query }, '', [200], region).then( + (response) => { +- const asm = jsonLineParser.make() ++ const asm = jsonLineParser.asStream() + + pipesetup(response, asm) + .on('data', (data) => { diff --git a/service/scripts/dependency-compat.test.cjs b/service/scripts/dependency-compat.test.cjs new file mode 100644 index 00000000..05894867 --- /dev/null +++ b/service/scripts/dependency-compat.test.cjs @@ -0,0 +1,43 @@ +const assert = require('node:assert/strict'); +const { test } = require('node:test'); +const { Readable } = require('node:stream'); +const { pathToFileURL } = require('node:url'); +const path = require('node:path'); + +// Exercise both published MinIO entry points under Node as well as Bun: Bun's +// ESM/CJS interop can otherwise conceal a broken require() in the Node service. +for (const format of ['main/notification.js', 'esm/notification.mjs']) { + test(`MinIO ${format} decodes chunked UTF-8 JSONL notifications and forwards errors`, { timeout: 5000 }, async () => { + const file = path.join(path.dirname(require.resolve('minio')), '..', format); + const { NotificationPoller } = await import(pathToFileURL(file).href); + const record = { eventName: 's3:ObjectCreated:Put', key: 'café.csv' }; + const bytes = Buffer.from(JSON.stringify({ Records: [record] }) + '\n'); + const split = bytes.indexOf(Buffer.from('é')) + 1; + const poller = new NotificationPoller({ + makeRequestAsync: async () => Readable.from([bytes.subarray(0, split), bytes.subarray(split)]), + }, 'test-bucket'); + await new Promise((resolve, reject) => { + poller.on('error', reject); + poller.on('notification', value => { + poller.stop(); + try { + assert.deepEqual(value, record); + resolve(); + } catch (error) { reject(error); } + }); + poller.start(); + }); + const malformed = new NotificationPoller({ + makeRequestAsync: async () => Readable.from(['{invalid}\n']), + }, 'test-bucket'); + await new Promise((resolve, reject) => { + malformed.on('notification', () => reject(new Error('Invalid JSON must not emit a notification'))); + malformed.on('error', error => { + malformed.stop(); + assert.ok(error instanceof Error); + resolve(); + }); + malformed.start(); + }); + }); +} diff --git a/service/src/dependency-security.test.ts b/service/src/dependency-security.test.ts new file mode 100644 index 00000000..04468518 --- /dev/null +++ b/service/src/dependency-security.test.ts @@ -0,0 +1,45 @@ +import { expect, test } from 'bun:test'; +import { createRequire } from 'node:module'; +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import path from 'node:path'; + +const require = createRequire(import.meta.url); + +test.each(['deepmerge', 'deepmerge/dist/umd.js'])( + '%s preserves own prototype keys as data without poisoning the result', + entry => { + const merge = require(entry); + const payload = JSON.parse('{"__proto__":{"polluted":true},"nested":{"__proto__":{"polluted":true}}}'); + for (const result of [merge(payload, {}), merge(Object.create(null), payload)]) { + expect(Object.getPrototypeOf(result)).toBe(Object.prototype); + expect(result.polluted).toBeUndefined(); + expect(Object.getPrototypeOf(result.nested)).toBe(Object.prototype); + expect(result.nested.polluted).toBeUndefined(); + } + expect(merge({ a: { b: 1 }, list: [1] }, { a: { c: 2 }, list: [2] })) + .toEqual({ a: { b: 1, c: 2 }, list: [1, 2] }); + expect(Object.prototype).not.toHaveProperty('polluted'); + }, +); + +test('ESLint project-service glob matching works with the scoped minimatch upgrade', () => { + const parser = require('@typescript-eslint/parser'); + const dir = mkdtempSync(path.join(tmpdir(), 'codeapi-parser-')); + try { + writeFileSync(path.join(dir, 'tsconfig.json'), '{"compilerOptions":{"strict":true}}'); + const result = parser.parseForESLint('const value: number = 1;', { + filePath: path.join(dir, 'fixture.ts'), + tsconfigRootDir: dir, + projectService: { allowDefaultProject: ['fixture.ts'] }, + }); + expect(result.services.program).toBeDefined(); + expect(result.ast.body).toHaveLength(1); + // The legacy ESLint/glob consumers still require the callable v3 API. + const eslintRequire = createRequire(require.resolve('eslint')); + expect(eslintRequire('minimatch')('fixture.ts', '*.ts')).toBe(true); + } finally { + parser.clearCaches(); + rmSync(dir, { recursive: true, force: true }); + } +});