User-Agent String (Suspicious Patterns) Regex for JavaScript
/(?:sqlmap|nmap|masscan|nikto|nessus|openvas|nuclei|burpsuite|zap|dirbuster|gobuster|ffuf|wfuzz|hydra|metasploit|msfconsole|python-requests|curl|wget|libwww-perl|scrapy|mechanize|go-http-client|[Bb]ot|[Cc]rawler|[Ss]pider|[Ss]craper|PhantomJS|HeadlessChrome)(?:[/\s]|$)/iWhat this pattern does
This page provides a comprehensive, battle-tested regular expression for matching user-agent string (suspicious patterns), ported and verified for JavaScript. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// User-Agent String (Suspicious Patterns)
// ReDoS-safe | RegexVault — Security > Network Security
const useragentStringSuspiciousPatternsRegex = /(?:sqlmap|nmap|masscan|nikto|nessus|openvas|nuclei|burpsuite|zap|dirbuster|gobuster|ffuf|wfuzz|hydra|metasploit|msfconsole|python-requests|curl|wget|libwww-perl|scrapy|mechanize|go-http-client|[Bb]ot|[Cc]rawler|[Ss]pider|[Ss]craper|PhantomJS|HeadlessChrome)(?:[\/\s]|$)/i;
function validateUseragentStringSuspiciousPatterns(input: string): boolean {
return useragentStringSuspiciousPatternsRegex.test(input);
}
// Example
console.log(validateUseragentStringSuspiciousPatterns("sqlmap/1.4.12")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
sqlmap/1.4.12 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 |
python-requests/2.28.0 | Safari/537.36 |
Nessus 6.5 | — |
Mozilla/5.0 HeadlessChrome/119 | — |
When to use this pattern
This pattern is drawn from the Security > Network Security category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
Sophisticated attackers spoof User-Agent strings. UA-based blocking is a deterrent, not a security control. Complement with behavioral analysis (request rate, URL patterns) for meaningful bot detection.
Technical Notes
Detection pattern for WAF (Web Application Firewall) rules. Matches known scanner, pentesting tool, and automation library user agents. False positives: legitimate bots (Googlebot, Bingbot) are not included. Extend the list based on observed attack patterns in your logs.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern