From ad6621fce9c3e1893f0b78572d2dc11f1c71e484 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 19 Jul 2026 12:54:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(waf):=20=E6=94=B6=E7=B4=A7=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=98=B2=E6=8A=A4=E7=89=B9=E5=BE=81=EF=BC=8C=E9=99=8D?= =?UTF-8?q?=E4=BD=8E=E5=B8=B8=E8=A7=81=E6=AD=A3=E5=B8=B8=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=AF=AF=E4=BC=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SSRF 仅匹配 URL 形态,避免 Chrome/x.0.0.0 误中 - 命令注入去掉裸 &&/|| 与裸 shell 名 - SQL sleep/benchmark 要求数字参数 - XSS javascript:/eval 要求更像代码的上下文 - 路径穿越去掉过宽的 c:\windows;CRLF 去掉单独 %0a/%0d --- internal/apps/agent/nginx/waf_runtime.lua | 116 ++++++++++++++---- .../apps/agent/nginx/waf_runtime_spec.lua | 71 +++++++++++ 2 files changed, 165 insertions(+), 22 deletions(-) diff --git a/internal/apps/agent/nginx/waf_runtime.lua b/internal/apps/agent/nginx/waf_runtime.lua index e5586891..cee05b80 100644 --- a/internal/apps/agent/nginx/waf_runtime.lua +++ b/internal/apps/agent/nginx/waf_runtime.lua @@ -439,6 +439,72 @@ local function security_match_any(haystacks, patterns) return false end +-- SQL sleep/benchmark: require digit arg to avoid product names like sleep(better). +local function security_match_sql_timed(haystacks) + for _, hay in ipairs(haystacks) do + if type(hay) == "string" and hay ~= "" then + if string.find(hay, "sleep(%d", 1, true) or string.find(hay, "benchmark(%d", 1, true) then + return true + end + -- Also accept sleep( 1 ) with optional spaces: sleep( + digit + local i = 1 + while true do + local s, e = string.find(hay, "sleep(", i, true) + if not s then break end + local rest = string.sub(hay, e + 1) + if string.match(rest, "^%s*%d") then return true end + i = e + 1 + end + i = 1 + while true do + local s, e = string.find(hay, "benchmark(", i, true) + if not s then break end + local rest = string.sub(hay, e + 1) + if string.match(rest, "^%s*%d") then return true end + i = e + 1 + end + end + end + return false +end + +-- XSS: tag/event handlers and URI schemes; skip prose like "javascript: the good parts". +local function security_match_xss(haystacks) + local tag_like = { "