REGEXVAULTv2.0
Security/Network Security
Verified Safe

User-Agent String (Suspicious Patterns) Regex for Go

/(?: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

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching user-agent string (suspicious patterns), ported and verified for Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// User-Agent String (Suspicious Patterns)
// ReDoS-safe | RegexVault — Security > Network Security

package validation

import "regexp"

var useragentStringSuspiciousPatternsRe = regexp.MustCompile(`(?: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]|$)`)

func ValidateUseragentStringSuspiciousPatterns(s string) bool {
    return useragentStringSuspiciousPatternsRe.MatchString(s)
}

// Example
// fmt.Println(ValidateUseragentStringSuspiciousPatterns("sqlmap/1.4.12")) // true

Test Cases

Matches (Valid)
Rejects (Invalid)
sqlmap/1.4.12Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
python-requests/2.28.0Safari/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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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