CVSS Score (v3.1 Vector String) Regex for Java
/^CVSS:3\.[01]/AV:[NALP]/AC:[LH]/PR:[NLH]/UI:[NR]/S:[UC]/C:[NLH]/I:[NLH]/A:[NLH]$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching cvss score (v3.1 vector string), 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
// CVSS Score (v3.1 Vector String)
// ReDoS-safe | RegexVault — Security > Network Security
import java.util.regex.Pattern;
public class CvssScoreV31VectorStringValidator {
private static final Pattern PATTERN =
Pattern.compile("^CVSS:3\\.[01]/AV:[NALP]/AC:[LH]/PR:[NLH]/UI:[NR]/S:[UC]/C:[NLH]/I:[NLH]/A:[NLH]$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H")); // true
}
}Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H | CVSS:2.0/AV:N/AC:L/Au:N/C:C/I:C/A:C |
CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:U/C:L/I:N/A:L | CVSS:3.1/AV:X/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H |
| — | AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H |
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
CVSS scores without temporal and environmental adjustments are theoretical. A 9.8 Critical in the NVD may be 3.0 Low in your environment if not internet-facing or if mitigating controls are in place.
Technical Notes
CVSS v3.1 base metrics: AV (Attack Vector: N/A/L/P), AC (Attack Complexity: L/H), PR (Privileges Required: N/L/H), UI (User Interaction: N/R), S (Scope: U/C), C/I/A (Impact: N/L/H). Log4Shell = CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H = 10.0 Critical.
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