diff --git a/package-lock.json b/package-lock.json index 58e74bd2..b6c3e4f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2590,6 +2590,140 @@ "win32" ] }, + "node_modules/@next/env": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/env/-/env-15.5.24.tgz", + "integrity": "sha512-mBDF7T0XKZjs9SpUAl0buizVO+O02ULjOvWX8o/AZo/5AGw/UAS1Zzcylmd4pqbftzmKQi+L/nB4jgBYKEAl5Q==", + "license": "MIT" + }, + "node_modules/@next/swc-darwin-arm64": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.5.24.tgz", + "integrity": "sha512-AGdNLvxZNY6eR2iSnV+6wUa8CiHTMr4F7g3uHH7fT4ICIJBE00R9u4tzN/Vuwsw0cOi8MTD2HJcTCb6siMH88Q==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.5.24.tgz", + "integrity": "sha512-9HrQajBMmGcrrrvDfRimiCrbAPh3E6uHJmwBovYr6Yrmi9p9PZqI876BrXX280wICh3o2XwUlp4blkB0NNBqFg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.5.24.tgz", + "integrity": "sha512-rl9LSfE75si0WT3cDgdUC1XYCKS+TgxC+/IjitmeycrAG18X/plIP1/vy8dd/HPycYcIvE688PD7FuvEAiEAew==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.5.24.tgz", + "integrity": "sha512-TlNAnpsjxSF3aAUtqnfmtXXf8m9sIDBlmF3c7bTAlnshUYu2U0OxN2uf5d0gcFwqHVEdivJNBcCaqNOwPGNimw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.5.24.tgz", + "integrity": "sha512-7dwtlhr0SLndqTG1z9ncRkbJswDZiKWlxzFyXDvJ2RDZRDRHp8zyMJ4D9UH/FgnQeXxxB6gZy2pMcIUoNKQ4pA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.5.24.tgz", + "integrity": "sha512-kGZxM+WhkYs0276lFrMkj7PRtXT3Btp6cwvfSO/cCVLxJJttB5Ccnl2niaCgUja8HgSbEVnMHpg3FJWoOJ9e/g==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.5.24.tgz", + "integrity": "sha512-jBDDkZ/qKAqkWivWDMkJSXUzbzV0QKRBKJjEHUAvSB97Hzw7NLzJ6yV56Lts/wjir7s4P31GYgpbS6ZL+hasAA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "15.5.24", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.5.24.tgz", + "integrity": "sha512-JqtwjvvorjacQ0spgjmUJoxySoYgPwdT1sFdQ0/zmW4iMlP2hjYlCoJIyS7o6Epb4Fug8eco3HXFoBDUCDeH7Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@noble/hashes": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.8.0.tgz", @@ -4485,9 +4619,9 @@ } }, "node_modules/body-parser": { - "version": "1.20.6", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.6.tgz", - "integrity": "sha512-p5tAzS57i5MV9fZFDj9LeIiTZEufbSe2eDozP+ElheSUq1m74CRq1jI4mYNDdVs9vQztXFLuk/Gd6BWTdwRJ5g==", + "version": "1.20.9", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.9.tgz", + "integrity": "sha512-FISIQxV5u91Y9gvuFq3q/tA/qTqLJn3AhRcEvyozyhJTh5OBFFtv827AdHU7Rbyct4r+Ba1/99oFa1Y3yuFsdw==", "license": "MIT", "dependencies": { "bytes": "~3.1.2", @@ -12426,15 +12560,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/zod": { - "version": "3.25.76", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", - "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } - }, "packages/bot": { "name": "@gitwire/bot", "version": "0.23.1", @@ -12467,140 +12592,6 @@ "typescript": "^5.8.0" } }, - "packages/demo-dashboard/node_modules/@next/env": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/env/-/env-15.5.24.tgz", - "integrity": "sha512-mBDF7T0XKZjs9SpUAl0buizVO+O02ULjOvWX8o/AZo/5AGw/UAS1Zzcylmd4pqbftzmKQi+L/nB4jgBYKEAl5Q==", - "license": "MIT" - }, - "packages/demo-dashboard/node_modules/@next/swc-darwin-arm64": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.5.24.tgz", - "integrity": "sha512-AGdNLvxZNY6eR2iSnV+6wUa8CiHTMr4F7g3uHH7fT4ICIJBE00R9u4tzN/Vuwsw0cOi8MTD2HJcTCb6siMH88Q==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "packages/demo-dashboard/node_modules/@next/swc-darwin-x64": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.5.24.tgz", - "integrity": "sha512-9HrQajBMmGcrrrvDfRimiCrbAPh3E6uHJmwBovYr6Yrmi9p9PZqI876BrXX280wICh3o2XwUlp4blkB0NNBqFg==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "packages/demo-dashboard/node_modules/@next/swc-linux-arm64-gnu": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.5.24.tgz", - "integrity": "sha512-rl9LSfE75si0WT3cDgdUC1XYCKS+TgxC+/IjitmeycrAG18X/plIP1/vy8dd/HPycYcIvE688PD7FuvEAiEAew==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "packages/demo-dashboard/node_modules/@next/swc-linux-arm64-musl": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.5.24.tgz", - "integrity": "sha512-TlNAnpsjxSF3aAUtqnfmtXXf8m9sIDBlmF3c7bTAlnshUYu2U0OxN2uf5d0gcFwqHVEdivJNBcCaqNOwPGNimw==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "packages/demo-dashboard/node_modules/@next/swc-linux-x64-gnu": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.5.24.tgz", - "integrity": "sha512-7dwtlhr0SLndqTG1z9ncRkbJswDZiKWlxzFyXDvJ2RDZRDRHp8zyMJ4D9UH/FgnQeXxxB6gZy2pMcIUoNKQ4pA==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "packages/demo-dashboard/node_modules/@next/swc-linux-x64-musl": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.5.24.tgz", - "integrity": "sha512-kGZxM+WhkYs0276lFrMkj7PRtXT3Btp6cwvfSO/cCVLxJJttB5Ccnl2niaCgUja8HgSbEVnMHpg3FJWoOJ9e/g==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "packages/demo-dashboard/node_modules/@next/swc-win32-arm64-msvc": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.5.24.tgz", - "integrity": "sha512-jBDDkZ/qKAqkWivWDMkJSXUzbzV0QKRBKJjEHUAvSB97Hzw7NLzJ6yV56Lts/wjir7s4P31GYgpbS6ZL+hasAA==", - "cpu": [ - "arm64" - ], - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "packages/demo-dashboard/node_modules/@next/swc-win32-x64-msvc": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.5.24.tgz", - "integrity": "sha512-JqtwjvvorjacQ0spgjmUJoxySoYgPwdT1sFdQ0/zmW4iMlP2hjYlCoJIyS7o6Epb4Fug8eco3HXFoBDUCDeH7Q==", - "cpu": [ - "x64" - ], - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, "packages/demo-dashboard/node_modules/@types/node": { "version": "22.20.1", "dev": true, @@ -12610,9 +12601,9 @@ } }, "packages/demo-dashboard/node_modules/next": { - "version": "15.5.24", - "resolved": "https://registry.npmjs.org/next/-/next-15.5.24.tgz", - "integrity": "sha512-Y+xn8EQCoC3ZbsFPyzE+tE8XOdrWeUdUF7NeXbmg9DsgAxl5UYxlsrvgVESHTyTGigoTa1bCUrxn70F5bqt0Gw==", + "version": "15.5.28", + "resolved": "https://registry.npmjs.org/next/-/next-15.5.28.tgz", + "integrity": "sha512-JjhLBBY1PNnuwPtcZ7t8yxVeJVYvD2Jyp633J+gRCNbzSt7N0E+xqCf6uQiff3+3qmUkwcF/ksfSsK1xsZ76Tw==", "license": "MIT", "dependencies": { "@next/env": "15.5.24", @@ -12715,7 +12706,7 @@ "pino": "^8.0.0", "pino-pretty": "^10.0.0", "yaml": "^2.9.0", - "zod": "^3.22.0" + "zod": "^4.6.6" }, "devDependencies": { "eslint": "^8.0.0", @@ -12734,7 +12725,7 @@ "clsx": "^2.1.1", "date-fns": "^3.6.0", "lucide-react": "^1.16.0", - "next": "16.3.8", + "next": "16.4.6", "react": "19.2.4", "react-dom": "19.2.4", "recharts": "^2.15.4", @@ -12798,9 +12789,9 @@ "license": "MIT" }, "packages/web-dashboard/node_modules/@next/swc-darwin-arm64": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.3.3.tgz", - "integrity": "sha512-8Hiv32QJPwdV6KYJ8meR9SBA061tQqnIKTJDocvOXlEQqib0xMFpzArosuffFUUc0sslbh7QQ8a3Yey1QV8EIw==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.4.6.tgz", + "integrity": "sha512-kJ4VVZkley17xKaJx72QN2IBqjrj7zenCQZaUF0l9ShS/1Mt2kW4+Z5KGG6vgr3L/J562xTOizVyM1iA/u5nlg==", "cpu": [ "arm64" ], @@ -12814,9 +12805,9 @@ } }, "packages/web-dashboard/node_modules/@next/swc-darwin-x64": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.3.3.tgz", - "integrity": "sha512-A1lgKgwVchRYmSe467zdwhxT9040dd8lH+o65sL5Jet8fjB4kegw/rDyPIpYVRb6jAqwXFOJpjIXJLxQKLiE3A==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.4.6.tgz", + "integrity": "sha512-eIPGZIqC+8JKaeZmvnCANJQF4xWkkHqSnAAajtFxgwDMAOnCgxNvP52SeWZ41PyVwoe+Le/NQuZSaQ8j7YshSA==", "cpu": [ "x64" ], @@ -12830,9 +12821,9 @@ } }, "packages/web-dashboard/node_modules/@next/swc-linux-arm64-gnu": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.3.3.tgz", - "integrity": "sha512-bf0FIssMFueU2dm7vQEWWxk0c8UjKTdW0yzuh0sQsD8pf1+KCLDdaqhYZNMYGmXwEOiHAUzgBKudovIlcvvBjg==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.4.6.tgz", + "integrity": "sha512-9nI6O8vvczH2D9ZNdMGqb/3NuT15T9ksOZnAmx9/gjF2cOi74+xxyf1Hk96uIMfm14c9y6wHeBq6SH8g6udvcA==", "cpu": [ "arm64" ], @@ -12846,9 +12837,9 @@ } }, "packages/web-dashboard/node_modules/@next/swc-linux-arm64-musl": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.3.3.tgz", - "integrity": "sha512-W7viwCk9JY/cAkdz/A273rd5bb3RgT/IHwR7Upv90tunjBWNtAAhGhoecHh+teRNRSinuAFmE+l7fwZ4YKkrXg==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.4.6.tgz", + "integrity": "sha512-7/qPhTxDp2ScluOJOhLuhWmlA17o1yZ0SIgpISBCpBxXgtnK4+KGywBpFkfLPiU1rnSM1faFGzYkH6i7JdTrqA==", "cpu": [ "arm64" ], @@ -12862,9 +12853,9 @@ } }, "packages/web-dashboard/node_modules/@next/swc-linux-x64-gnu": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.3.3.tgz", - "integrity": "sha512-0W46zw1N3ODpI6n0GeivHvvob1pooozgZVqy65k0mh4/7vr+FbY9+WpHzNVXjHipJf/A3FDheBG19H1s5A25rA==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.4.6.tgz", + "integrity": "sha512-oOpbNa8XOW1qCGd9VvzC4fbkkRxEls7/WI6tz+YHC0xRA7KpV1U7DrAnCPjzVyOk/karzWEepCOcTIDmwK8FwQ==", "cpu": [ "x64" ], @@ -12878,9 +12869,9 @@ } }, "packages/web-dashboard/node_modules/@next/swc-linux-x64-musl": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.3.3.tgz", - "integrity": "sha512-H4mBso8ZTMBPtdT0PN0pBx2ayTvQuTuvS6qT13d77yVFJXAPCxkyIhLTmdMaGTJs0krQYI/qpzdHijCeihXhbg==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.4.6.tgz", + "integrity": "sha512-aM8CZ+OR2EwXaAYw7KGkW2GDmNDsLBIRe1MMRZCJPTdw/xhTD0IMUVO4sf3KqrzuRouGzwwLZn34+gFeVXiUQA==", "cpu": [ "x64" ], @@ -12894,9 +12885,9 @@ } }, "packages/web-dashboard/node_modules/@next/swc-win32-arm64-msvc": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.3.3.tgz", - "integrity": "sha512-cTMUJpcEGmeywofCUfhR+rSsoE33+rVPnPEYNTNdLNlsOeEg/vktOsKUSTb28vUGqD2jkm4Zaskcwn7OCI6FQg==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.4.6.tgz", + "integrity": "sha512-U0p7/tEtqvHX2crhd841CDwKtp5CFkKXVjOhmfccR3Pvp64sj8KBwRqsvltqLOwVBbj0NtkxwXSDpEHYGbxeXQ==", "cpu": [ "arm64" ], @@ -12910,9 +12901,9 @@ } }, "packages/web-dashboard/node_modules/@next/swc-win32-x64-msvc": { - "version": "16.3.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.3.3.tgz", - "integrity": "sha512-2VR4cTBzHXaBjnGsuH6GyJjENzQOmHeAh11uY1iUhjm3j5dEUrVJuUj+VL78jaGi/Dik8xS76zEj18BsFhlVZQ==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.4.6.tgz", + "integrity": "sha512-3ZG15/5WIdlTQsIEvc9sPTTSL5XFrlLklIKmfF4fwsDnoAhu6NcBDXsk3mbGxNyo6aVLEGex+fHCv2MahY7a9g==", "cpu": [ "x64" ], @@ -13376,9 +13367,9 @@ } }, "packages/web-dashboard/node_modules/next": { - "version": "16.3.8", - "resolved": "https://registry.npmjs.org/next/-/next-16.3.8.tgz", - "integrity": "sha512-U7QEZaTini6wKrb8A8hqLLqYQyCetegKjCpJOyxk642vWoMoU1x5PyZCJFvgYgiptA8xc5j/9xYlZFO7w9Sjmw==", + "version": "16.4.6", + "resolved": "https://registry.npmjs.org/next/-/next-16.4.6.tgz", + "integrity": "sha512-QZJiYhaZLJMo2KpkQGQIwvmd79WVsAWeYIU554a8d7zArS3si/IRy3lBNV/rtYhE70oLwdLYhPAXLPx8HwcwtA==", "license": "MIT", "dependencies": { "@next/env": "16.3.3", @@ -13503,6 +13494,15 @@ "funding": { "url": "https://github.com/sponsors/isaacs" } + }, + "packages/web/node_modules/zod": { + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index 14e2f38e..ed179c80 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "postcss": "8.5.22", "sharp": "0.35.5", "proxy-addr": "2.0.8", - "source-map-js": "1.2.2" + "source-map-js": "1.2.2", + "body-parser": "1.20.9" }, "optionalDependencies": { "sharp": "0.35.5" diff --git a/packages/demo-dashboard/package.json b/packages/demo-dashboard/package.json index 37b94f86..2af9156d 100644 --- a/packages/demo-dashboard/package.json +++ b/packages/demo-dashboard/package.json @@ -8,7 +8,7 @@ "start": "npx serve out" }, "dependencies": { - "next": "15.5.24", + "next": "15.5.28", "react": "^19.1.0", "react-dom": "^19.1.0", "clsx": "^2.1.0", diff --git a/packages/web-dashboard/package.json b/packages/web-dashboard/package.json index b0d40fec..6cd0c5cd 100644 --- a/packages/web-dashboard/package.json +++ b/packages/web-dashboard/package.json @@ -14,7 +14,7 @@ "clsx": "^2.1.1", "date-fns": "^3.6.0", "lucide-react": "^1.16.0", - "next": "16.3.8", + "next": "16.4.6", "react": "19.2.4", "react-dom": "19.2.4", "recharts": "^2.15.4", diff --git a/packages/web-dashboard/src/middleware.ts b/packages/web-dashboard/src/proxy.ts similarity index 90% rename from packages/web-dashboard/src/middleware.ts rename to packages/web-dashboard/src/proxy.ts index dd742c69..3a04a785 100644 --- a/packages/web-dashboard/src/middleware.ts +++ b/packages/web-dashboard/src/proxy.ts @@ -1,5 +1,5 @@ -// src/middleware.ts -// Next.js middleware — redirects unauthenticated users to /login. +// src/proxy.ts (renamed from middleware.ts for Next.js 16.4+) +// Next.js proxy (formerly middleware) — redirects unauthenticated users to /login. // Checks for the gitwire-session cookie on all page routes. // Allows /login, /_next/*, and static assets without auth. @@ -21,7 +21,7 @@ function isPublicAsset(pathname: string): boolean { ); } -export function middleware(request: NextRequest) { +export function proxy(request: NextRequest) { const { pathname } = request.nextUrl; // Allow public paths and static assets diff --git a/packages/web/package.json b/packages/web/package.json index 9bff6e6a..b847caea 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -35,7 +35,7 @@ "pino": "^8.0.0", "pino-pretty": "^10.0.0", "yaml": "^2.9.0", - "zod": "^3.22.0" + "zod": "^4.6.6" }, "devDependencies": { "eslint": "^8.0.0", diff --git a/packages/web/src/middleware/auth.js b/packages/web/src/middleware/auth.js index a4a479f1..fc3bc223 100644 --- a/packages/web/src/middleware/auth.js +++ b/packages/web/src/middleware/auth.js @@ -8,6 +8,7 @@ import { config } from "../../config/index.js"; import { logger } from "../lib/logger.js"; import { redis } from "../lib/queue.js"; +import { extractBearerToken } from "./bearerToken.js"; const SESSION_PREFIX = "gitwire:session:"; @@ -71,13 +72,12 @@ export async function apiKeyAuth(req, res, next) { return next(); } - // Extract key from header or query param - let providedKey = null; - - const authHeader = req.headers.authorization; - if (authHeader?.startsWith("Bearer ")) { - providedKey = authHeader.slice(7).trim(); - } + // Extract the key from the Authorization header (the only in-header + // channel; there is no query-parameter key path). Recognition lives in + // the shared bearerToken.js helper so apiKeyAuth and the rate limiter + // cannot drift apart (the limiter derives its identity from the exact + // same forms auth accepts). + const providedKey = extractBearerToken(req.headers.authorization) || null; // Check session cookie if no Bearer token if (!providedKey) { diff --git a/packages/web/src/middleware/bearerToken.js b/packages/web/src/middleware/bearerToken.js new file mode 100644 index 00000000..61b2ff55 --- /dev/null +++ b/packages/web/src/middleware/bearerToken.js @@ -0,0 +1,28 @@ +// src/middleware/bearerToken.js +// Bearer-token extraction shared by apiKeyAuth (auth.js) and the rate limiter +// (rateLimiter.js). Both MUST recognize exactly the same Authorization forms: +// a case-sensitive "Bearer " scheme prefix with a single literal space. A +// looser recognizer on the limiter side re-opens the bucket-rotation bypass +// (rotating non-Bearer headers to mint fresh buckets); a stricter one would +// throttle callers apiKeyAuth accepts. Before this module existed the two +// implementations were unlinked copies kept in sync by comments — the corpus +// contract test in rate-limiter-identity.test.js now pins this one function +// for both callers. + +/** + * Extract the Bearer token from an Authorization header value. + * + * Recognition is apiKeyAuth-EXACT: case-sensitive "Bearer " prefix (single + * literal space), then slice(7).trim(). Returns "" for every other form — + * wrong case ("bearer x"), tab separator ("Bearer\tx"), bare "Bearer", + * whitespace-only token, or a missing/non-string header. + * + * @param {string | undefined} authHeader + * @returns {string} the token, or "" when the header is not a well-formed + * Bearer credential. + */ +export function extractBearerToken(authHeader) { + return typeof authHeader === "string" && authHeader.slice(0, 7) === "Bearer " + ? authHeader.slice(7).trim() + : ""; +} diff --git a/packages/web/src/middleware/rateLimiter.js b/packages/web/src/middleware/rateLimiter.js index a70d78c5..c68d7652 100644 --- a/packages/web/src/middleware/rateLimiter.js +++ b/packages/web/src/middleware/rateLimiter.js @@ -4,10 +4,43 @@ import { redis } from "../lib/queue.js"; import { logger } from "../lib/logger.js"; +import { extractBearerToken } from "./bearerToken.js"; const WINDOW_MS = 60_000; // 1 minute window const MAX_REQUESTS = 120; // 120 req/min per identity (~2 req/sec) +// Identity derivation, isolated from the handler so the middleware reads +// like the throttle it is (CodeQL's missing-rate-limiting model pairs +// credential reads inside a route handler with recognized limiter sinks; +// the derivation here IS the limiter's own identity selection). +// +// Contract: +// - A properly formed Bearer token is the identity on ordinary paths. The +// recognition is apiKeyAuth-EXACT because both callers share one +// implementation: extractBearerToken() in bearerToken.js (case-sensitive +// "Bearer " prefix, single space, slice(7).trim()). Anything looser +// re-opens the rotation bypass ("Bearer\t" / "bearer " are NOT +// Bearer for auth, so they must not mint buckets either) — reproduced in +// rate-limiter-behavior.test.js, pinned by the corpus contract test in +// rate-limiter-identity.test.js. +// - PRE-AUTHENTICATION route families ALWAYS key on the request IP: the +// limiter runs before authentication, so an unverified token must never +// become their throttle identity. Two families mount before apiKeyAuth +// (app.js): /api/auth/* (login authenticates by body password; check +// authenticates by session cookie via Redis; logout) and /api/bootstrap/* +// (state runs a DB query anonymously; first is bootstrap-gated). Every +// path under both prefixes matches, with trailing-slash and case +// tolerance (Express's default non-strict, case-insensitive-to-route +// routing serves those variants to the same handlers). +// - Everything else falls back to the request IP. +export function deriveLimiterIdentity(req) { + const isPreAuthPath = typeof req.path === "string" + && (/^\/api\/auth(\/.*)?\/?$/i.test(req.path) + || /^\/api\/bootstrap(\/.*)?\/?$/i.test(req.path)); + const bearerToken = isPreAuthPath ? "" : extractBearerToken(req.headers.authorization); + return bearerToken || req.ip || "unknown"; +} + /** * Rate limiter middleware using Redis INCR + EXPIRE. * Falls back to allowing all requests if Redis is unavailable. @@ -18,11 +51,7 @@ export function rateLimiter(req, res, next) { return next(); } - // Identity: prefer API key, fall back to IP - const identity = req.headers.authorization?.slice(7)?.trim() - || req.ip - || "unknown"; - + const identity = deriveLimiterIdentity(req); const key = `ratelimit:${identity}`; redis diff --git a/packages/web/tests/unit/rate-limiter-behavior.test.js b/packages/web/tests/unit/rate-limiter-behavior.test.js index e58d76bb..51d96167 100644 --- a/packages/web/tests/unit/rate-limiter-behavior.test.js +++ b/packages/web/tests/unit/rate-limiter-behavior.test.js @@ -157,67 +157,33 @@ describe("rate limiter behavior (Unit C — existing semantics pinned)", () => { }); }); -describe("REPRODUCER (known defect, recorded not fixed): non-Bearer Authorization headers split rate buckets under session auth", () => { - // The limiter identity is `req.headers.authorization?.slice(7)?.trim() || req.ip` - // — the scheme is never checked. apiKeyAuth accepts a VALID SESSION COOKIE - // when the Authorization header is absent or not Bearer. Chained as in - // production (limiter before auth), a session-authenticated caller rotates - // arbitrary non-Bearer Authorization values to get a fresh bucket per - // request. This documents the bypass end-to-end with the REAL apiKeyAuth; - // the fix is a separate production decision per the #425 review. - +describe('REPRODUCER HISTORY (bypass FIXED by rate-limiter-identity remediation on this branch)', () => { + // The original end-to-end reproducer (130 rotating Basic headers from one + // session, all passing, 130 distinct buckets) documented the identity + // defect that the Bearer-only derivation now closes. Full fixed-scenario + // coverage lives in rate-limiter-identity.test.js; here we assert the + // original attack no longer reproduces against the CURRENT middleware. function buildApp() { const app = express(); app.use(rateLimiter); app.use(apiKeyAuth); - app.get("/api/anything", (req, res) => res.json({ ok: true })); + app.get('/api/anything', (req, res) => res.json({ ok: true })); return app; } - it("END-TO-END: 130 requests from ONE session, rotating Basic headers, all pass — the per-IP fallback they should have shared never applies", async () => { + it('the original rotation attack now throttles: 121st request is 429 on ONE shared bucket', async () => { const app = buildApp(); - const sessionCookie = "gitwire-session=valid-session"; + const sessionCookie = 'gitwire-session=valid-session'; + let last = 200; for (let i = 0; i < 130; i += 1) { const res = await supertest(app) - .get("/api/anything") - .set("Authorization", `Basic rotating-value-${i}`) // arbitrary non-Bearer - .set("Cookie", sessionCookie); - expect(res.status).toBe(200); + .get('/api/anything') + .set('Authorization', "Basic rotating-value-" + i) + .set('Cookie', sessionCookie); + last = res.status; + if (res.status === 429) break; } - // 130 DISTINCT buckets were created — one per rotated header value — - // while the SAME session authenticated every request. Without the - // rotating header, all 130 would share the IP bucket and the last 10 - // would have been 429'd. - expect(redisState.counts.size).toBe(130); - expect([...redisState.counts.values()].every((n) => n === 1)).toBe(true); - }); - - it("CONTROL: the SAME session WITHOUT the header trick throttles at 120/min on the shared IP bucket", async () => { - const app = buildApp(); - const sessionCookie = "gitwire-session=valid-session"; - for (let i = 0; i < 120; i += 1) { - const res = await supertest(app) - .get("/api/anything") - .set("Cookie", sessionCookie); - expect(res.status).toBe(200); - } - // The 121st request on the shared IP bucket is the exact boundary the - // rotation bypasses — pinned, not "somewhere within 130". - const boundary = await supertest(app) - .get("/api/anything") - .set("Cookie", sessionCookie); - expect(boundary.status).toBe(429); - }); - - it("MECHANISM: the limiter bucket key derives from the raw sliced header, scheme unchecked", async () => { - const a = await runMiddleware({ headers: { authorization: "Basic value-1" }, ip: "10.9.9.9" }); - const b = await runMiddleware({ headers: { authorization: "Basic value-2" }, ip: "10.9.9.9" }); - expect(a.passed).toBe(true); - expect(b.passed).toBe(true); - // Two buckets for one IP — the sliced values differ even though neither - // is a credential. - expect(redisState.counts.size).toBe(2); - expect([...redisState.counts.keys()].join("|")).toContain("alue-1"); // slice(7) of "Basic value-1" - expect([...redisState.counts.keys()].join("|")).toContain("alue-2"); + expect(last).toBe(429); + expect(redisState.counts.size).toBe(1); // the IP bucket, not per-header buckets }); }); diff --git a/packages/web/tests/unit/rate-limiter-identity.test.js b/packages/web/tests/unit/rate-limiter-identity.test.js new file mode 100644 index 00000000..8126f236 --- /dev/null +++ b/packages/web/tests/unit/rate-limiter-identity.test.js @@ -0,0 +1,360 @@ +// tests/unit/rate-limiter-identity.test.js +// Production remediation for the identity bypass reproduced in +// rate-limiter-behavior.test.js: limiter identity now recognizes ONLY a +// properly formed Bearer scheme; every other Authorization form (and its +// absence) falls back to the request IP — so rotating non-Bearer headers can +// no longer mint fresh buckets for a session-authenticated caller. +// +// The behavior pins (threshold, exclusions, fail-open) live in the behavior +// suite against the same middleware; this suite proves the identity contract +// change end-to-end and in the middleware directly. + +import { jest } from "@jest/globals"; + +const redisState = { counts: new Map(), failWith: null }; + +jest.unstable_mockModule("../../src/lib/queue.js", () => ({ + redis: { + incr: jest.fn(async (key) => { + if (redisState.failWith) throw redisState.failWith; + const next = (redisState.counts.get(key) ?? 0) + 1; + redisState.counts.set(key, next); + return next; + }), + pexpire: jest.fn(async () => 1), + get: jest.fn(async (key) => { + if (key.startsWith("gitwire:session:")) { + return key.endsWith(":valid-session") ? JSON.stringify({ principal: "session-user" }) : null; + } + return null; + }), + expire: jest.fn(async () => 1), + }, +})); +jest.unstable_mockModule("../../src/lib/logger.js", () => ({ + logger: { info: jest.fn(), warn: jest.fn(), error: jest.fn(), debug: jest.fn() }, +})); +jest.unstable_mockModule("../../config/index.js", () => ({ + config: { anthropic: { apiKey: "test" }, github: { appId: "1", privateKey: "k", clientId: "x", clientSecret: "x", webhookSecret: "s" }, server: { baseUrl: "x" } }, +})); + +process.env.API_KEY = "unit-test-api-key"; + +const { rateLimiter, deriveLimiterIdentity } = await import("../../src/middleware/rateLimiter.js"); +const { apiKeyAuth } = await import("../../src/middleware/auth.js"); +const { extractBearerToken } = await import("../../src/middleware/bearerToken.js"); + +const express = (await import("express")).default; +const supertest = (await import("supertest")).default; + +function buildApp() { + // Production mount order: limiter BEFORE authentication. + const app = express(); + app.use(rateLimiter); + app.use(apiKeyAuth); + app.get("/api/anything", (req, res) => res.json({ ok: true })); + return app; +} + +beforeEach(() => { + redisState.counts.clear(); + redisState.failWith = null; + jest.clearAllMocks(); +}); + +describe("REMEDIATION: rotating non-Bearer headers can no longer split buckets", () => { + it("THE REPRODUCER SCENARIO, FIXED: 130 requests from one session with rotating Basic headers hit 429 at request 121", async () => { + const app = buildApp(); + const sessionCookie = "gitwire-session=valid-session"; + let last = 200; + for (let i = 0; i < 130; i += 1) { + const res = await supertest(app) + .get("/api/anything") + .set("Authorization", `Basic rotating-value-${i}`) + .set("Cookie", sessionCookie); + if (i < 120) { + expect(res.status).toBe(200); + } + last = res.status; + if (res.status === 429) break; + } + expect(last).toBe(429); + // ONE shared bucket (the request IP), not 130. + expect(redisState.counts.size).toBe(1); + expect([...redisState.counts.values()][0]).toBe(121); + }); + + it("header-absent session traffic shares the same IP bucket (unchanged semantics)", async () => { + const app = buildApp(); + const sessionCookie = "gitwire-session=valid-session"; + let saw429 = false; + for (let i = 0; i < 121; i += 1) { + const res = await supertest(app).get("/api/anything").set("Cookie", sessionCookie); + if (res.status === 429) { saw429 = true; break; } + expect(res.status).toBe(200); + } + expect(saw429).toBe(true); + expect(redisState.counts.size).toBe(1); + }); +}); + +describe('PRE-AUTH FIX: rotating invalid Bearer tokens on /api/auth/login shares ONE IP bucket', () => { + // The limiter runs before authentication, so it cannot know a Bearer token + // is invalid. The login route authenticates by request-body password — an + // unauthenticated caller rotating syntactically-valid-but-random Bearer + // values would otherwise mint a fresh bucket per password guess. + function buildLoginApp() { + const app = express(); + app.use(rateLimiter); + app.use(express.json()); + // Minimal login route mirroring auth.js: 401 on wrong password. + app.post('/api/auth/login', (req, res) => res.status(401).json({ error: 'Invalid password' })); + return app; + } + + it('END-TO-END: 130 login attempts with ROTATING random Bearer tokens hit 429 at request 121 on ONE shared bucket', async () => { + const app = buildLoginApp(); + let last = 200; + for (let i = 0; i < 130; i += 1) { + const res = await supertest(app) + .post('/api/auth/login') + .set('Authorization', "Bearer random-guess-token-" + i) + .send({ password: 'wrong-' + i }); + if (i < 120) { + expect(res.status).toBe(401); // still reaches the route and fails auth + } + last = res.status; + if (res.status === 429) break; + } + expect(last).toBe(429); + expect(redisState.counts.size).toBe(1); // ONE shared IP bucket + expect([...redisState.counts.values()][0]).toBe(121); + }); + + it('login attempts WITHOUT Bearer headers share the same single bucket (unchanged semantics)', async () => { + const app = buildLoginApp(); + let saw429 = false; + for (let i = 0; i < 121; i += 1) { + const res = await supertest(app) + .post('/api/auth/login') + .send({ password: 'wrong' }); + if (res.status === 429) { saw429 = true; break; } + expect(res.status).toBe(401); + } + expect(saw429).toBe(true); + expect(redisState.counts.size).toBe(1); + }); + + it('TRAILING-SLASH and case variants of the login path are ALSO IP-keyed (no mint on /api/auth/login/)', async () => { + const app = buildLoginApp(); + const variants = ["/api/auth/login/", "/API/AUTH/LOGIN", "/api/auth/Login/"]; + for (const path of variants) { + redisState.counts.clear(); + await supertest(app) + .post(path) + .set("Authorization", "Bearer slash-variant-token") + .send({ password: "wrong" }); + // Whatever the route did with the variant (401 or 404), the limiter + // bucket must be the IP — never the token. + const keys = [...redisState.counts.keys()]; + expect(keys.length).toBe(1); + expect(keys[0]).not.toContain("slash-variant-token"); + } + }); + + it('AUTH-CHECK: rotating Bearer tokens with a valid session cookie shares ONE IP bucket (429 at 121)', async () => { + const app = buildLoginApp(); + // /api/auth/check accepts session cookies via Redis — mounted before + // apiKeyAuth, so rotating Bearer headers would mint buckets per request. + app.get('/api/auth/check', (req, res) => res.json({ authenticated: true })); + const sessionCookie = 'gitwire-session=valid-session'; + let last = 200; + for (let i = 0; i < 130; i += 1) { + const res = await supertest(app) + .get('/api/auth/check') + .set('Authorization', 'Bearer check-rotating-' + i) + .set('Cookie', sessionCookie); + if (i < 120) { + expect(res.status).toBe(200); + } + last = res.status; + if (res.status === 429) break; + } + expect(last).toBe(429); + expect(redisState.counts.size).toBe(1); + expect([...redisState.counts.values()][0]).toBe(121); + }); + + it('BOOTSTRAP-STATE: anonymous rotating Bearer headers share ONE IP bucket (429 at 121)', async () => { + const app = buildLoginApp(); + // /api/bootstrap/state runs a DB query anonymously — mounted before + // apiKeyAuth. + app.get('/api/bootstrap/state', (_req, res) => res.json({ bootstrapped: true })); + let last = 200; + for (let i = 0; i < 130; i += 1) { + const res = await supertest(app) + .get('/api/bootstrap/state') + .set('Authorization', 'Bearer bootstrap-rotating-' + i); + if (i < 120) { + expect(res.status).toBe(200); + } + last = res.status; + if (res.status === 429) break; + } + expect(last).toBe(429); + expect(redisState.counts.size).toBe(1); + expect([...redisState.counts.values()][0]).toBe(121); + }); + + it('FAMILY VARIANTS: every /api/auth/* and /api/bootstrap/* path (case, trailing slash, subpaths) keys on the IP', async () => { + const paths = [ + '/api/auth/logout', '/API/AUTH/LOGIN/', '/api/auth/Check', + '/api/bootstrap/first', '/API/BOOTSTRAP/state/', '/api/bootstrap', + '/api/auth', '/api/auth/', + ]; + const app = buildLoginApp(); + for (const path of paths) { + redisState.counts.clear(); + await supertest(app) + .get(path) + .set('Authorization', 'Bearer family-variant-token'); + const keys = [...redisState.counts.keys()]; + expect(keys.length).toBe(1); + expect(keys[0]).not.toContain('family-variant-token'); + } + }); + + it('NON-login /api paths still derive identity from a well-formed Bearer token', async () => { + const app = buildLoginApp(); + app.get('/api/anything', (req, res) => res.json({ ok: true })); + const res = await supertest(app) + .get('/api/anything') + .set('Authorization', 'Bearer some-token'); + expect(res.status).toBe(200); + expect([...redisState.counts.keys()].join('|')).toContain('some-token'); + }); +}); + +describe("identity derivation contract (middleware-level)", () => { + function runMiddleware({ headers = {}, ip } = {}) { + return new Promise((resolve) => { + const req = { path: "/api/anything", headers, ip, get: (h) => headers[h.toLowerCase()] }; + const res = { + statusCode: 200, + headers: {}, + setHeader(k, v) { this.headers[k] = v; }, + status(code) { this.statusCode = code; return this; }, + json(body) { this.body = body; resolve({ res, passed: false }); return this; }, + }; + rateLimiter(req, res, () => resolve({ res, passed: true })); + }); + } + + it('a well-formed case-sensitive "Bearer " scheme token IS the identity (exactly apiKeyAuth recognition)', async () => { + await runMiddleware({ headers: { authorization: "Bearer key-one" }, ip: "10.0.0.1" }); + await runMiddleware({ headers: { authorization: "Bearer key-two" }, ip: "10.0.0.1" }); + // Two distinct buckets for two distinct tokens from one IP. + expect(redisState.counts.size).toBe(2); + expect([...redisState.counts.keys()].join("|")).toContain("key-one"); + expect([...redisState.counts.keys()].join("|")).toContain("key-two"); + // A LOWERCASE scheme is not Bearer for apiKeyAuth (starts-with "Bearer "), + // so it must not be Bearer for the limiter either — it falls to the IP. + redisState.counts.clear(); + await runMiddleware({ headers: { authorization: "bearer key-lower" }, ip: "10.0.0.2" }); + expect([...redisState.counts.keys()]).toEqual(["ratelimit:10.0.0.2"]); + }); + + it.each([ + ["Basic value-1"], + ["basic value-2"], + ["Bearer"], // malformed: no token after scheme + ["Bearer "], // malformed: whitespace only + ["Bearer\tgap-token"], // malformed: tab is not the literal-space separator of the shared + // recognizer ("Bearer " via extractBearerToken) — apiKeyAuth rejects + // it with 401, so the limiter must bucket it as anonymous IP too + [""], // empty header value + ])("non-Bearer or malformed header %j falls back to the IP bucket", async (authorization) => { + redisState.counts.clear(); + const first = await runMiddleware({ headers: { authorization }, ip: "10.1.1.1" }); + expect(first.passed).toBe(true); + // Whatever the header said, the bucket is the IP. + expect([...redisState.counts.keys()]).toEqual(["ratelimit:10.1.1.1"]); + }); + + it("Bearer-key separation still works at the threshold: key A saturates, key B unaffected, IP unaffected", async () => { + for (let i = 0; i < 120; i += 1) { + await runMiddleware({ headers: { authorization: "Bearer key-sat" }, ip: "10.2.2.2" }); + } + const saturated = await runMiddleware({ headers: { authorization: "Bearer key-sat" }, ip: "10.2.2.2" }); + expect(saturated.passed).toBe(false); + const otherKey = await runMiddleware({ headers: { authorization: "Bearer key-other" }, ip: "10.2.2.2" }); + expect(otherKey.passed).toBe(true); + const plainIp = await runMiddleware({ ip: "10.2.2.2" }); + expect(plainIp.passed).toBe(true); + }); +}); + +describe("CONTRACT: apiKeyAuth and deriveLimiterIdentity share one Bearer recognizer (bearerToken.js)", () => { + // The two mechanisms were previously unlinked copies kept in sync only by + // comments. Both now call extractBearerToken(), so this corpus pins the + // ONE recognition rule both depend on: a header authenticates (given a + // valid key) exactly when the shared recognizer extracts a token, and the + // limiter keys on that token exactly when the same recognizer extracts + // one. Divergence in either direction is a test failure, not a silent + // bucket-rotation regression. + + const VALID_KEY = "unit-test-api-key"; // process.env.API_KEY set at module load (auth.js keys Set) + + async function authAccepts(authorization) { + let accepted = false; + const req = { + path: "/api/repos", // not auth-skipped, not pre-auth-family + headers: authorization === undefined ? {} : { authorization }, + ip: "10.9.9.9", + }; + const res = { status() { return this; }, json() { return this; } }; + await apiKeyAuth(req, res, () => { accepted = true; }); + return accepted; + } + + it.each([ + ["Bearer unit-test-api-key", "unit-test-api-key", true], + ["Bearer unit-test-api-key ", "unit-test-api-key", true], // trim() tolerates surrounding whitespace AFTER the scheme + ["Bearer not-the-key", "not-the-key", false], // recognized form, invalid key → 401, identity still the token + ["bearer unit-test-api-key", "", false], // lowercase scheme is not Bearer for EITHER mechanism + ["BEARER unit-test-api-key", "", false], // case-sensitive scheme + ["Bearer\tunit-test-api-key", "", false], // tab is not the literal-space separator + ["Basic unit-test-api-key", "", false], + ["Bearer", "", false], + ["Bearer ", "", false], // whitespace-only token + ["", "", false], + [undefined, "", false], + ])("corpus %j → token %j, apiKeyAuth accepts: %s", async (authorization, expectedToken, expectedAccept) => { + // The shared recognizer decides both behaviors from one input. + expect(extractBearerToken(authorization)).toBe(expectedToken); + await expect(authAccepts(authorization)).resolves.toBe(expectedAccept); + + // Limiter identity (ordinary path): the token when the recognizer found + // one, otherwise the IP. A recognized-but-invalid token ("Bearer + // not-the-key") still mints its own bucket — authentication and throttle + // identity are intentionally coupled ONLY on pre-auth families, where + // the override below forces the IP. + const identity = deriveLimiterIdentity({ + path: "/api/repos", + headers: authorization === undefined ? {} : { authorization }, + ip: "10.9.9.9", + }); + expect(identity).toBe(expectedToken || "10.9.9.9"); + }); + + it("PRE-AUTH OVERRIDE: even a well-formed valid Bearer keys the IP on /api/auth/* and /api/bootstrap/*", () => { + for (const path of ["/api/auth/login", "/api/auth/check", "/api/bootstrap/state", "/api/bootstrap/first"]) { + const identity = deriveLimiterIdentity({ + path, + headers: { authorization: `Bearer ${VALID_KEY}` }, + ip: "10.9.9.9", + }); + expect(identity).toBe("10.9.9.9"); + } + }); +});