zeno.id 0.3.1 → 0.3.2
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/README.md +3 -1
- package/dist/server/index.cjs +18 -1
- package/dist/server/index.js +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -232,7 +232,9 @@ app.all('/zeno', nodeHandler(zeno)) // the path you chose
|
|
|
232
232
|
import { zeno } from '@/lib/zeno'
|
|
233
233
|
|
|
234
234
|
// X-Real-IP: set by Vercel, or by your own proxy (nginx: proxy_set_header X-Real-IP $remote_addr;)
|
|
235
|
-
const handler = (request: Request) =>
|
|
235
|
+
const handler = (request: Request) => {
|
|
236
|
+
return zeno(request, request.headers.get('x-real-ip'))
|
|
237
|
+
}
|
|
236
238
|
|
|
237
239
|
// Next.js calls the export named after the method
|
|
238
240
|
export const GET = handler
|
package/dist/server/index.cjs
CHANGED
|
@@ -43,6 +43,21 @@ const isIpMismatch = (eventIp, ip) => {
|
|
|
43
43
|
const requestIp = ip.trim();
|
|
44
44
|
return eventIp.includes(":") === requestIp.includes(":") && networkOf(eventIp) !== networkOf(requestIp);
|
|
45
45
|
};
|
|
46
|
+
const isNestedDeeperThan = (text, max) => {
|
|
47
|
+
let depth = 0;
|
|
48
|
+
let isInString = false;
|
|
49
|
+
for (let index = 0; index < text.length; index++) {
|
|
50
|
+
const char = text[index];
|
|
51
|
+
if (isInString) {
|
|
52
|
+
if (char === "\\") index++;
|
|
53
|
+
else if (char === "\"") isInString = false;
|
|
54
|
+
} else if (char === "\"") isInString = true;
|
|
55
|
+
else if (char === "{" || char === "[") {
|
|
56
|
+
if (++depth > max) return true;
|
|
57
|
+
} else if (char === "}" || char === "]") depth--;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
46
61
|
//#endregion
|
|
47
62
|
//#region src/server/proxy.ts
|
|
48
63
|
const isStrings = (value) => {
|
|
@@ -54,6 +69,7 @@ const rawHeadersOf = (internal) => {
|
|
|
54
69
|
};
|
|
55
70
|
const COOKIE = "zeno_id";
|
|
56
71
|
const MAX_BODY = 131072;
|
|
72
|
+
const MAX_NESTING = 64;
|
|
57
73
|
const TIMEOUT$1 = 1e4;
|
|
58
74
|
const jsonResponse = (status, body, headers = {}) => {
|
|
59
75
|
return new Response(JSON.stringify(body), {
|
|
@@ -284,9 +300,10 @@ const createProxy = (apiKey, options = {}) => {
|
|
|
284
300
|
};
|
|
285
301
|
const handlePost = async (request, ip, internal) => {
|
|
286
302
|
if (!/^application\/json\s*(;|$)/i.test(request.headers.get("content-type") ?? "")) return invalidRequest("The body must be JSON");
|
|
287
|
-
if (request.headers.get("sec-fetch-site") === "cross-site") return invalidRequest("Cross-site requests are refused");
|
|
303
|
+
if (request.headers.get("sec-fetch-site")?.toLowerCase() === "cross-site") return invalidRequest("Cross-site requests are refused");
|
|
288
304
|
const bodyText = await readCappedBody(request, MAX_BODY);
|
|
289
305
|
if (bodyText === void 0) return invalidRequest("The body is larger than 128 KB");
|
|
306
|
+
if (isNestedDeeperThan(bodyText, MAX_NESTING)) return invalidRequest(`The body nests deeper than ${MAX_NESTING} levels`);
|
|
290
307
|
let payload;
|
|
291
308
|
try {
|
|
292
309
|
payload = JSON.parse(bodyText);
|
package/dist/server/index.js
CHANGED
|
@@ -42,6 +42,21 @@ const isIpMismatch = (eventIp, ip) => {
|
|
|
42
42
|
const requestIp = ip.trim();
|
|
43
43
|
return eventIp.includes(":") === requestIp.includes(":") && networkOf(eventIp) !== networkOf(requestIp);
|
|
44
44
|
};
|
|
45
|
+
const isNestedDeeperThan = (text, max) => {
|
|
46
|
+
let depth = 0;
|
|
47
|
+
let isInString = false;
|
|
48
|
+
for (let index = 0; index < text.length; index++) {
|
|
49
|
+
const char = text[index];
|
|
50
|
+
if (isInString) {
|
|
51
|
+
if (char === "\\") index++;
|
|
52
|
+
else if (char === "\"") isInString = false;
|
|
53
|
+
} else if (char === "\"") isInString = true;
|
|
54
|
+
else if (char === "{" || char === "[") {
|
|
55
|
+
if (++depth > max) return true;
|
|
56
|
+
} else if (char === "}" || char === "]") depth--;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
45
60
|
//#endregion
|
|
46
61
|
//#region src/server/proxy.ts
|
|
47
62
|
const isStrings = (value) => {
|
|
@@ -53,6 +68,7 @@ const rawHeadersOf = (internal) => {
|
|
|
53
68
|
};
|
|
54
69
|
const COOKIE = "zeno_id";
|
|
55
70
|
const MAX_BODY = 131072;
|
|
71
|
+
const MAX_NESTING = 64;
|
|
56
72
|
const TIMEOUT$1 = 1e4;
|
|
57
73
|
const jsonResponse = (status, body, headers = {}) => {
|
|
58
74
|
return new Response(JSON.stringify(body), {
|
|
@@ -283,9 +299,10 @@ const createProxy = (apiKey, options = {}) => {
|
|
|
283
299
|
};
|
|
284
300
|
const handlePost = async (request, ip, internal) => {
|
|
285
301
|
if (!/^application\/json\s*(;|$)/i.test(request.headers.get("content-type") ?? "")) return invalidRequest("The body must be JSON");
|
|
286
|
-
if (request.headers.get("sec-fetch-site") === "cross-site") return invalidRequest("Cross-site requests are refused");
|
|
302
|
+
if (request.headers.get("sec-fetch-site")?.toLowerCase() === "cross-site") return invalidRequest("Cross-site requests are refused");
|
|
287
303
|
const bodyText = await readCappedBody(request, MAX_BODY);
|
|
288
304
|
if (bodyText === void 0) return invalidRequest("The body is larger than 128 KB");
|
|
305
|
+
if (isNestedDeeperThan(bodyText, MAX_NESTING)) return invalidRequest(`The body nests deeper than ${MAX_NESTING} levels`);
|
|
289
306
|
let payload;
|
|
290
307
|
try {
|
|
291
308
|
payload = JSON.parse(bodyText);
|