mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 22:14:27 +00:00
🦠 fix: Patch Vulnerable Database and Transport Dependencies (#18124)
Co-authored-by: Lia <lia@librechat.ai>
This commit is contained in:
parent
4a13f26651
commit
59cf1af4b7
6 changed files with 245 additions and 54 deletions
|
|
@ -100,7 +100,7 @@
|
|||
"mime": "^3.0.0",
|
||||
"module-alias": "^2.2.3",
|
||||
"mongodb": "^6.14.2",
|
||||
"mongoose": "^8.24.1",
|
||||
"mongoose": "^8.24.9",
|
||||
"multer": "^2.5.0",
|
||||
"nanoid": "^3.3.18",
|
||||
"node-fetch": "^2.7.0",
|
||||
|
|
|
|||
123
package-lock.json
generated
123
package-lock.json
generated
|
|
@ -130,7 +130,7 @@
|
|||
"mime": "^3.0.0",
|
||||
"module-alias": "^2.2.3",
|
||||
"mongodb": "^6.14.2",
|
||||
"mongoose": "^8.24.1",
|
||||
"mongoose": "^8.24.9",
|
||||
"multer": "^2.5.0",
|
||||
"nanoid": "^3.3.18",
|
||||
"node-fetch": "^2.7.0",
|
||||
|
|
@ -6884,9 +6884,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@hono/node-server": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.5.tgz",
|
||||
"integrity": "sha512-MgP/I06GdvsilDspMk/qmRzpk8LOUStP6jFAbSRi40W09DhoyUn+Mj7eyKICPqeYKybOjVFLVIAQzvu1bfIa7Q==",
|
||||
"version": "2.1.8",
|
||||
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.8.tgz",
|
||||
"integrity": "sha512-jdf7FHh6A1lzjpHHQUgxsg2GeER2vMetnAOfeActzcoli6jamlK+NAwL6Dsr5Fl3BS3tYUQzCdtZjU8Qxv7bEA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
|
|
@ -10551,9 +10551,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@nodable/entities": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@nodable/entities/-/entities-2.1.0.tgz",
|
||||
"integrity": "sha512-nyT7T3nbMyBI/lvr6L5TyWbFJAI9FTgVRakNoBqCD+PmID8DzFrrNdLLtHMwMszOtqZa8PAOV24ZqDnQrhQINA==",
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@nodable/entities/-/entities-3.1.0.tgz",
|
||||
"integrity": "sha512-LsS/DjHr+uDM647Gru/cA8+J3a3HfhttwCKLyuoyN7yXTFCxKBtSgMQBvrW9yNPa2/zDRUNuGPaH5QUFoa4arQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
|
|
@ -25674,16 +25674,17 @@
|
|||
}
|
||||
},
|
||||
"node_modules/eslint-plugin-sonarjs/node_modules/minimatch": {
|
||||
"version": "10.2.6",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz",
|
||||
"integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==",
|
||||
"version": "11.0.8",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.8.tgz",
|
||||
"integrity": "sha512-nFQuYSTVrGvysVBps5Ih+0BdnYFN/Cj3C816r6+p7yK+FHrVLGE4O4N9AFwykrlNlvM2HYt+Rad1Uiro6h88Ig==",
|
||||
"dev": true,
|
||||
"license": "BlueOak-1.0.0",
|
||||
"dependencies": {
|
||||
"brace-expansion": "^5.0.8"
|
||||
"@isaacs/nonrecursive-glob-match": "^1.1.0",
|
||||
"brace-expansion": "^5.0.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": "18 || 20 || >=22"
|
||||
"node": "20 || >=22"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/isaacs"
|
||||
|
|
@ -26354,9 +26355,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/fast-xml-builder": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.2.0.tgz",
|
||||
"integrity": "sha512-00aAWieqff+ZJhsXA4g1g7M8k+7AYoMUUHF+/zFb5U6Uv/P0Vl4QZo84/IcufzYalLuEj9928bXN9PbbFzMF0Q==",
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.3.2.tgz",
|
||||
"integrity": "sha512-OX91VSlShLPDgRZV7tk/YQ4l8tT75QziF5Ixg8g4PFbCVPjuTWwN+yQfAxLJ0dufJpprdOd6HlM74Jhd39TcBQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
|
|
@ -26365,14 +26366,14 @@
|
|||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"path-expression-matcher": "^1.5.0",
|
||||
"xml-naming": "^0.1.0"
|
||||
"path-expression-matcher": "^1.6.2",
|
||||
"xml-naming": "^0.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-xml-parser": {
|
||||
"version": "5.7.2",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.7.2.tgz",
|
||||
"integrity": "sha512-P7oW7tLbYnhOLQk/Gv7cZgzgMPP/XN03K02/Jy6Y/NHzyIAIpxuZIM/YqAkfiXFPxA2CTm7NtCijK9EDu09u2w==",
|
||||
"version": "5.12.1",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.12.1.tgz",
|
||||
"integrity": "sha512-wR8dO/fx+z8C5exuem1e7BKOWvjsuzvjS/tvA/Xu3Z1zQqJGcXrPzXbcAiaMgp2KjreEROcTkmnnisrcmJ2hYQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
|
|
@ -26381,10 +26382,12 @@
|
|||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@nodable/entities": "^2.1.0",
|
||||
"fast-xml-builder": "^1.1.5",
|
||||
"path-expression-matcher": "^1.5.0",
|
||||
"strnum": "^2.2.3"
|
||||
"@nodable/entities": "^3.1.0",
|
||||
"fast-xml-builder": "^1.3.2",
|
||||
"is-unsafe": "^2.0.3",
|
||||
"path-expression-matcher": "^1.6.2",
|
||||
"strnum": "^2.5.1",
|
||||
"xml-naming": "^0.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"fxparser": "src/cli/cli.js"
|
||||
|
|
@ -27719,9 +27722,9 @@
|
|||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
||||
},
|
||||
"node_modules/hono": {
|
||||
"version": "4.13.13",
|
||||
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.13.tgz",
|
||||
"integrity": "sha512-CQ46U0ZkAGmbT/4UxdzzGJpacP2IeKgY4a5/tOI9AABbpOMfK739wfDXmv1usCk+3RkKj1hQy4/fjhiwa2xlrA==",
|
||||
"version": "4.13.18",
|
||||
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.18.tgz",
|
||||
"integrity": "sha512-H9q/E1XizaWstJxUW881dmLxEj+t/TrGGnyxINkm4+sK0qUwsMtFdo2BWI9Vs3cIS19MU6b6iCijoUoEf4f3DA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
|
|
@ -33945,16 +33948,16 @@
|
|||
}
|
||||
},
|
||||
"node_modules/mongoose": {
|
||||
"version": "8.24.1",
|
||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.24.1.tgz",
|
||||
"integrity": "sha512-UpHBA0l5kHyKJQFjmBaFYQFo5sgz1DK0TRqDkOyBLYbqiIbKKhIvBpHWBXqeo0rgW4kGI1UhhAw+kTQZoj1BdA==",
|
||||
"version": "8.24.9",
|
||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.24.9.tgz",
|
||||
"integrity": "sha512-+roDmtsLlBjv42fIlhqX6AmCgSznqK3CDxFcAZZv2fkovgGunZpXGTEEZoL5agz9JbFH4r7i6CGJ8T3p7Ub5Jg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bson": "^6.10.4",
|
||||
"kareem": "2.6.3",
|
||||
"mongodb": "~6.20.0",
|
||||
"mpath": "0.9.0",
|
||||
"mquery": "5.0.0",
|
||||
"mquery": "5.0.1",
|
||||
"ms": "2.1.3",
|
||||
"sift": "17.1.3"
|
||||
},
|
||||
|
|
@ -34029,9 +34032,10 @@
|
|||
}
|
||||
},
|
||||
"node_modules/mquery": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz",
|
||||
"integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==",
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.1.tgz",
|
||||
"integrity": "sha512-C99lWV0TFI34pS008jBsi3JrE2xZPnTgUw5yApQR71nRP0hxLy8D5m1Lbbk83c8AQWJwdJ0329HzFtZ1MRTUIw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "4.x"
|
||||
},
|
||||
|
|
@ -35306,9 +35310,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/path-expression-matcher": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.5.0.tgz",
|
||||
"integrity": "sha512-cbrerZV+6rvdQrrD+iGMcZFEiiSrbv9Tfdkvnusy6y0x0GKBXREFg/Y65GhIfm0tnLntThhzCnfKwp1WRjeCyQ==",
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.6.2.tgz",
|
||||
"integrity": "sha512-enSlaiat05iasnzmgNxRj8reFdj3puY2QpNgP1aPIaVfT6nn9ICuPoFlKHk8EN22HcwewshO+mN2DGbkCEOtqQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
|
|
@ -39290,16 +39294,19 @@
|
|||
}
|
||||
},
|
||||
"node_modules/strnum": {
|
||||
"version": "2.2.3",
|
||||
"resolved": "https://registry.npmjs.org/strnum/-/strnum-2.2.3.tgz",
|
||||
"integrity": "sha512-oKx6RUCuHfT3oyVjtnrmn19H1SiCqgJSg+54XqURKp5aCMbrXrhLjRN9TjuwMjiYstZ0MzDrHqkGZ5dFTKd+zg==",
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/strnum/-/strnum-2.5.1.tgz",
|
||||
"integrity": "sha512-UM4nTLWzQiDBseVxUGxN0wJzIk0UU89Qi7pKXz9qISo+lhviJikTuikBsK/oFRlpvYHvSdz0TVoLyQ+sEpYwxA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/NaturalIntelligence"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"anynum": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/stubborn-fs": {
|
||||
"version": "2.0.0",
|
||||
|
|
@ -42064,9 +42071,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/xml-naming": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.1.0.tgz",
|
||||
"integrity": "sha512-k8KO9hrMyNk6tUWqUfkTEZbezRRpONVOzUTnc97VnCvyj6Tf9lyUR9EDAIeiVLv56jsMcoXEwjW8Kv5yPY52lw==",
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.3.0.tgz",
|
||||
"integrity": "sha512-ghig2TBE/H11aOVgmahA3MhimvkBr6JIYknH/Dhdk10nXwdbIqBJsbfMxpvFPG8bAw77gN29aQWvKpmVoPlvPQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
|
|
@ -42416,7 +42423,7 @@
|
|||
"mathjs": "^15.2.0",
|
||||
"memorystore": "^1.6.7",
|
||||
"mongodb": "^6.14.2",
|
||||
"mongoose": "^8.24.1",
|
||||
"mongoose": "^8.24.9",
|
||||
"nanoid": "^3.3.7",
|
||||
"node-fetch": "2.7.0",
|
||||
"pdfjs-dist": "^5.5.207",
|
||||
|
|
@ -45468,7 +45475,7 @@
|
|||
"librechat-data-provider": "*",
|
||||
"lodash": "^4.17.23",
|
||||
"meilisearch": "^0.38.0",
|
||||
"mongoose": "^8.24.1",
|
||||
"mongoose": "^8.24.9",
|
||||
"nanoid": "^3.3.18",
|
||||
"winston": "^3.17.0",
|
||||
"winston-daily-rotate-file": "^5.0.0"
|
||||
|
|
@ -46435,6 +46442,30 @@
|
|||
"@rolldown/binding-win32-arm64-msvc": "1.1.5",
|
||||
"@rolldown/binding-win32-x64-msvc": "1.1.5"
|
||||
}
|
||||
},
|
||||
"node_modules/anynum": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/anynum/-/anynum-1.0.1.tgz",
|
||||
"integrity": "sha512-N6//FLET/tXYNM/F6ABca1oH6fWB+KlTt909Le28WMDBk8oaT4vY17DCrwg2MvmuqUKt3Ni4N5dGJ/EoBgcO6A==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/NaturalIntelligence"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/is-unsafe": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-unsafe/-/is-unsafe-2.0.3.tgz",
|
||||
"integrity": "sha512-ZBllczCCO267vgdFb6Tq3pv+LhHaCiGMdr+ZsuL+OopruAg7S+3ZDs1vD0RPC0uSrkjzbraxaGjtX1YBxjPeFQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/NaturalIntelligence"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@
|
|||
"postcss-selector-parser@6": "^6.1.3",
|
||||
"postcss-selector-parser@7": "^7.1.3",
|
||||
"tslib": "^2.8.1",
|
||||
"fast-xml-parser": "5.7.2",
|
||||
"fast-xml-parser": "5.12.1",
|
||||
"serialize-javascript": "7.1.4",
|
||||
"mdast-util-gfm-autolink-literal": "2.0.0",
|
||||
"remark-gfm": {
|
||||
|
|
@ -269,8 +269,8 @@
|
|||
"ajv": "6.14.0"
|
||||
},
|
||||
"underscore": "1.13.8",
|
||||
"hono": "^4.13.13",
|
||||
"@hono/node-server": "^2.1.5",
|
||||
"hono": "^4.13.18",
|
||||
"@hono/node-server": "^2.1.8",
|
||||
"monaco-editor": {
|
||||
"dompurify": "3.4.17"
|
||||
},
|
||||
|
|
@ -294,6 +294,9 @@
|
|||
"workbox-build": {
|
||||
"glob": "^14.0.4"
|
||||
},
|
||||
"eslint-plugin-sonarjs": {
|
||||
"minimatch": "^11.0.5"
|
||||
},
|
||||
"@typescript-eslint/typescript-estree@8": {
|
||||
"minimatch": "^11.0.3"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@
|
|||
"mathjs": "^15.2.0",
|
||||
"memorystore": "^1.6.7",
|
||||
"mongodb": "^6.14.2",
|
||||
"mongoose": "^8.24.1",
|
||||
"mongoose": "^8.24.9",
|
||||
"nanoid": "^3.3.7",
|
||||
"node-fetch": "2.7.0",
|
||||
"pdfjs-dist": "^5.5.207",
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@
|
|||
"librechat-data-provider": "*",
|
||||
"lodash": "^4.17.23",
|
||||
"meilisearch": "^0.38.0",
|
||||
"mongoose": "^8.24.1",
|
||||
"mongoose": "^8.24.9",
|
||||
"nanoid": "^3.3.18",
|
||||
"winston": "^3.17.0",
|
||||
"winston-daily-rotate-file": "^5.0.0"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
|
|||
import { test } from 'node:test';
|
||||
import { once } from 'node:events';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import { createServer } from 'node:http';
|
||||
import { createServer, request } from 'node:http';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { createRequire } from 'node:module';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
|
|
@ -48,7 +48,12 @@ function patched(consumer, dependency, major) {
|
|||
|
||||
test('Glob consumers resolve patched majors without changing unrelated matchers', () => {
|
||||
for (const [, consumer] of globConsumers) patched(consumer, 'glob', 14);
|
||||
for (const name of ['test-exclude', '@typescript-eslint/typescript-estree', 'nodemon']) {
|
||||
for (const name of [
|
||||
'test-exclude',
|
||||
'@typescript-eslint/typescript-estree',
|
||||
'nodemon',
|
||||
'eslint-plugin-sonarjs',
|
||||
]) {
|
||||
patched(from(name), 'minimatch', 11);
|
||||
}
|
||||
for (const name of ['eslint-plugin-import', 'eslint-plugin-react', 'eslint-plugin-jsx-a11y']) {
|
||||
|
|
@ -351,3 +356,155 @@ test('Jest retains extension hints for missing modules', (t) => {
|
|||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('the lockfile retains patched database, HTTP, XML, and matcher dependencies', () => {
|
||||
const lock = JSON.parse(readFileSync(new URL('../package-lock.json', import.meta.url), 'utf8'));
|
||||
const { satisfies } = require('semver');
|
||||
const ranges = {
|
||||
mongoose: '^8.24.7',
|
||||
hono: '^4.13.16',
|
||||
'@hono/node-server': '^2.1.6',
|
||||
'fast-xml-parser': '>=5.11.3',
|
||||
minimatch: '<7 || >=11.0.1',
|
||||
};
|
||||
for (const [name, range] of Object.entries(ranges)) {
|
||||
const entries = Object.entries(lock.packages).filter(
|
||||
([path]) => path.endsWith(`/node_modules/${name}`) || path === `node_modules/${name}`,
|
||||
);
|
||||
assert.ok(entries.length, name);
|
||||
for (const [path, { version }] of entries) {
|
||||
assert.ok(satisfies(version, range), `${path}: ${version}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('Mongoose sanitizes countDocuments and connection-level query filters before dispatch', async () => {
|
||||
const { Mongoose } = require('mongoose');
|
||||
for (const level of ['query', 'connection']) {
|
||||
const db = new Mongoose();
|
||||
const connection = db.createConnection();
|
||||
if (level === 'connection') connection.set('sanitizeFilter', true);
|
||||
const Model = connection.model(
|
||||
'Sanitized',
|
||||
new db.Schema(
|
||||
{ password: String },
|
||||
{
|
||||
bufferCommands: false,
|
||||
},
|
||||
),
|
||||
);
|
||||
for (const operation of ['findOne', 'countDocuments']) {
|
||||
const query = Model[operation]({ password: { $ne: null } });
|
||||
if (level === 'query') query.setOptions({ sanitizeFilter: true });
|
||||
await assert.rejects(
|
||||
query.exec(),
|
||||
{ name: 'CastError', path: 'password' },
|
||||
`${level}/${operation}`,
|
||||
);
|
||||
assert.deepEqual(query.getFilter(), { password: { $eq: { $ne: null } } });
|
||||
}
|
||||
await connection.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test('Mongoose keeps inherited discriminator names subject to casting and strict schemas', () => {
|
||||
const { Mongoose } = require('mongoose');
|
||||
const db = new Mongoose();
|
||||
const Base = db.model('Base', new db.Schema({ age: Number }));
|
||||
Base.discriminator('Child', new db.Schema({ extra: String }));
|
||||
for (const name of ['constructor', 'toString', 'hasOwnProperty']) {
|
||||
const doc = new Base({ __t: name, age: '42', notInSchema: true });
|
||||
assert.ok(doc instanceof db.Document, name);
|
||||
assert.equal(doc.age, 42, name);
|
||||
assert.equal(doc.toObject().notInSchema, undefined, name);
|
||||
}
|
||||
});
|
||||
|
||||
test('Mongoose rejects virtual prototype paths and does not mutate inherited functions', (t) => {
|
||||
const { Mongoose } = require('mongoose');
|
||||
const db = new Mongoose();
|
||||
const schema = new db.Schema({ meta: {} });
|
||||
const marker = 'dependencySecurityMarker';
|
||||
t.after(() => {
|
||||
delete Object.prototype[marker];
|
||||
delete Object.prototype.toString[marker];
|
||||
});
|
||||
assert.throws(() => schema.virtual(`__proto__.${marker}`), /Cannot set special property/);
|
||||
assert.equal(Object.hasOwn(Object.prototype, marker), false);
|
||||
const Model = db.model('Inherited', schema);
|
||||
new Model({ [`meta.toString.${marker}`]: true });
|
||||
Model.hydrate({ toString: { [marker]: true } });
|
||||
Model.findOneAndReplace({}, { toString: { [marker]: true } });
|
||||
assert.equal(Object.hasOwn(Object.prototype.toString, marker), false);
|
||||
});
|
||||
|
||||
test('Hono rejects cross-origin hyperlink auditing but permits same-origin pings', async () => {
|
||||
const { Hono } = require('hono');
|
||||
const { csrf } = require('hono/csrf');
|
||||
const app = new Hono();
|
||||
app.use('*', csrf());
|
||||
app.post('/action', (c) => c.text('accepted'));
|
||||
for (const [origin, status] of [
|
||||
['https://attacker.example', 403],
|
||||
['https://app.example', 200],
|
||||
]) {
|
||||
const res = await app.request('https://app.example/action', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'text/ping', Origin: origin },
|
||||
body: 'PING',
|
||||
});
|
||||
assert.equal(res.status, status, origin);
|
||||
}
|
||||
});
|
||||
|
||||
test('Hono validates multipart form fields with additional content-type parameters', async () => {
|
||||
const { Hono } = require('hono');
|
||||
const { validator } = require('hono/validator');
|
||||
const app = new Hono();
|
||||
app.post(
|
||||
'/form',
|
||||
validator('form', (value) => value),
|
||||
(c) => c.json(c.req.valid('form')),
|
||||
);
|
||||
const body =
|
||||
'--boundary\r\nContent-Disposition: form-data; name="role"\r\n\r\nuser\r\n--boundary--\r\n';
|
||||
for (const contentType of [
|
||||
'multipart/form-data; boundary=boundary',
|
||||
'multipart/form-data; charset=utf-8; boundary=boundary',
|
||||
'multipart/form-data; boundary=boundary',
|
||||
]) {
|
||||
const res = await app.request('/form', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': contentType },
|
||||
body,
|
||||
});
|
||||
assert.equal(res.status, 200, contentType);
|
||||
assert.deepEqual(await res.json(), { role: 'user' }, contentType);
|
||||
}
|
||||
});
|
||||
|
||||
test('Hono node-server rejects raw path backslashes without rejecting encoded or query backslashes', async (t) => {
|
||||
const { Hono } = require('hono');
|
||||
const { serve } = require('@hono/node-server');
|
||||
const app = new Hono();
|
||||
app.get('*', (c) => c.text('accepted'));
|
||||
const server = serve({ fetch: app.fetch, port: 0, hostname: '127.0.0.1' });
|
||||
await once(server, 'listening');
|
||||
t.after(() => new Promise((resolve) => server.close(resolve)));
|
||||
for (const [path, status] of [
|
||||
['/public\\..\\admin/secret', 400],
|
||||
['/admin%5csecret', 200],
|
||||
['/?path=\\admin', 200],
|
||||
]) {
|
||||
const actual = await new Promise((resolve, reject) => {
|
||||
const req = request({ hostname: '127.0.0.1', port: server.address().port, path }, (res) => {
|
||||
res.resume();
|
||||
res.on('end', () => resolve(res.statusCode));
|
||||
res.on('error', reject);
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.end();
|
||||
});
|
||||
assert.equal(actual, status, path);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue