(content: string)
| 206 | } |
| 207 | |
| 208 | function detectByRules(content: string): Detection | null { |
| 209 | const normalized = normalizeText(content); |
| 210 | |
| 211 | for (const regex of EXPLICIT_ATTACK_PATTERNS) { |
| 212 | if (regex.test(normalized)) { |
| 213 | return { |
| 214 | blocked: true, |
| 215 | reason: `Explicit attack pattern matched: ${regex.source}`, |
| 216 | }; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | for (const regex of SUSPICIOUS_PAYLOAD_REGEX) { |
| 221 | if (regex.test(normalized)) { |
| 222 | return { |
| 223 | blocked: true, |
| 224 | reason: `Suspicious payload pattern matched: ${regex.source}`, |
| 225 | }; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | let bypassMatches = 0; |
| 230 | for (const regex of BYPASS_REGEX_PATTERNS) { |
| 231 | if (regex.test(normalized)) { |
| 232 | bypassMatches++; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if (bypassMatches >= 2) { |
| 237 | return { |
| 238 | blocked: true, |
| 239 | reason: `Multiple bypass patterns detected (${bypassMatches} matches)` |
| 240 | }; |
| 241 | } |
| 242 | |
| 243 | for (const regex of HIGH_RISK_REGEX_PATTERNS) { |
| 244 | if (regex.test(normalized)) { |
| 245 | return { |
| 246 | blocked: true, |
| 247 | reason: `High-risk pattern matched: ${regex.source}` |
| 248 | }; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | return null; |
| 253 | } |
| 254 | |
| 255 | function createMaliciousWarning(details: string): Warning { |
| 256 | return new Warning( |
no test coverage detected