REGEXVAULTv2.0
Security/Network Security
Verified Safe

User-Agent String (Suspicious Patterns) Regex for Java

/(?: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 Java. 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 Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

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

import java.util.regex.Pattern;

public class UseragentStringSuspiciousPatternsValidator {
    private static final Pattern PATTERN =
        Pattern.compile("(?: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]|$)");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("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 Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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