From 42bc5a15d08a969e0d5fe40669d891ae3b8d3c49 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 8 Dec 2025 23:08:38 +0100 Subject: [PATCH] sanitize nosql Signed-off-by: ale --- app/api/search/route.ts | 101 +++++++++++++++++++++++++++++++++++----- 1 file changed, 90 insertions(+), 11 deletions(-) diff --git a/app/api/search/route.ts b/app/api/search/route.ts index e53d805..18a986c 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -11,13 +11,101 @@ interface HashDocument { created_at?: string; } +// Maximum allowed query length +const MAX_QUERY_LENGTH = 1000; + +// Characters that could be used in NoSQL/Elasticsearch injection attacks +const DANGEROUS_PATTERNS = [ + /[{}\[\]]/g, // JSON structure characters + /\$[a-zA-Z]/g, // MongoDB-style operators + /\\u[0-9a-fA-F]{4}/g, // Unicode escapes + /