CVSS Score (v3.1 Vector String) Regex for Python
/^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 Python. 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 Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.
Python Implementation
# CVSS Score (v3.1 Vector String)
# ReDoS-safe | RegexVault — Security > Network Security
import re
cvss_score_v31_vector_string_pattern = re.compile(r'^CVSS:3\.[01]/AV:[NALP]/AC:[LH]/PR:[NLH]/UI:[NR]/S:[UC]/C:[NLH]/I:[NLH]/A:[NLH]$')
def validate_cvss_score_v31_vector_string(value: str) -> bool:
return bool(cvss_score_v31_vector_string_pattern.fullmatch(value))
# Example
print(validate_cvss_score_v31_vector_string("CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H")) # TrueTest 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 Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. 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