CVSS Score (v3.1 Vector String) Regex for PHP
/^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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.
Php Implementation
<?php
// CVSS Score (v3.1 Vector String)
// ReDoS-safe | RegexVault — Security > Network Security
define('CVSS_SCORE_V31_VECTOR_STRING_PATTERN', '/^CVSS:3\.[01]\/AV:[NALP]\/AC:[LH]\/PR:[NLH]\/UI:[NR]\/S:[UC]\/C:[NLH]\/I:[NLH]\/A:[NLH]$/');
function validate_cvss_score_v31_vector_string(string $input): bool {
return (bool) preg_match(CVSS_SCORE_V31_VECTOR_STRING_PATTERN, $input);
}
// Example
var_dump(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")); // bool(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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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