@fusionkit/model-gateway 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +12 -2
- package/package.json +3 -3
package/dist/server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
1
2
|
import { once } from "node:events";
|
|
2
3
|
import { createServer } from "node:http";
|
|
3
4
|
import { anthropicModelsResponse, handleAnthropicMessages, handleCountTokens } from "./adapters/anthropic.js";
|
|
@@ -224,10 +225,19 @@ async function pipeUpstream(res, upstream) {
|
|
|
224
225
|
}
|
|
225
226
|
function authorized(req, token) {
|
|
226
227
|
const auth = req.headers.authorization;
|
|
227
|
-
if (typeof auth === "string" && auth
|
|
228
|
+
if (typeof auth === "string" && constantTimeEquals(auth, `Bearer ${token}`)) {
|
|
228
229
|
return true;
|
|
230
|
+
}
|
|
229
231
|
const apiKey = req.headers["x-api-key"];
|
|
230
|
-
return typeof apiKey === "string" && apiKey
|
|
232
|
+
return typeof apiKey === "string" && constantTimeEquals(apiKey, token);
|
|
233
|
+
}
|
|
234
|
+
/** Length-independent constant-time string comparison (avoids timing leaks). */
|
|
235
|
+
function constantTimeEquals(a, b) {
|
|
236
|
+
const aBuf = Buffer.from(a);
|
|
237
|
+
const bBuf = Buffer.from(b);
|
|
238
|
+
if (aBuf.length !== bBuf.length)
|
|
239
|
+
return false;
|
|
240
|
+
return timingSafeEqual(aBuf, bBuf);
|
|
231
241
|
}
|
|
232
242
|
function errorMessage(error) {
|
|
233
243
|
return error instanceof Error ? error.message : String(error);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusionkit/model-gateway",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/velum-labs/handoffkit.git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"provenance": true
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@fusionkit/adapter-ai-sdk": "0.1.
|
|
29
|
-
"@fusionkit/protocol": "0.1.
|
|
28
|
+
"@fusionkit/adapter-ai-sdk": "0.1.6",
|
|
29
|
+
"@fusionkit/protocol": "0.1.6"
|
|
30
30
|
}
|
|
31
31
|
}
|