-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Another Improper Input Validation in CVSS v2 parsing #28
Comments
metric.Environmental type of CVSSv2 requires Base, Temporal, and Environmental metrics (issue #26). package main
import (
"fmt"
"github.com/goark/go-cvss/v2/metric"
)
func main() {
raw := "AV:N/AC:L/Au:N/C:N/I:N/A:C/E:F/RL:OF/RC:C"
vec, err := metric.NewTemporal().Decode(raw)
fmt.Printf("vec: %v\n", vec)
fmt.Printf("err: %v\n", err)
fmt.Printf("Severity: %v (%v)\n", vec.Severity(), vec.Score())
} (see https://go.dev/play/p/FI9sWSuGw85) Or supplement the environmental metrics explicitly. package main
import (
"fmt"
"github.com/goark/go-cvss/v2/metric"
)
func main() {
raw := "AV:N/AC:L/Au:N/C:N/I:N/A:C/E:F/RL:OF/RC:C/CDP:ND/TD:ND/CR:ND/IR:ND/AR:ND"
vec, err := metric.NewEnvironmental().Decode(raw)
fmt.Printf("vec: %v\n", vec)
fmt.Printf("err: %v\n", err)
fmt.Printf("Severity: %v (%v)\n", vec.Severity(), vec.Score())
} |
another code: package main
import (
"fmt"
"github.com/goark/go-cvss/v2/metric"
)
func main() {
raw := "AV:N/AC:L/Au:N/C:N/I:N/A:C/E:F/RL:OF/RC:C"
vec, err := metric.NewEnvironmental().Decode(raw)
if err == nil {
fmt.Printf("vector (Environmental): %v\n", vec)
fmt.Printf("Severity (Environmental): %v (%v)\n", vec.Severity(), vec.Score())
} else if vec.Temporal.GetError() == nil {
fmt.Printf("vector (Temporal): %v\n", vec.Temporal)
fmt.Printf("Severity (Temporal): %v (%v)\n", vec.Temporal.Severity(), vec.Temporal.Score())
} else if vec.Base.GetError() == nil {
fmt.Printf("vec (Base): %v\n", vec.Base)
fmt.Printf("Severity (Base): %v (%v)\n", vec.Base.Severity(), vec.Base.Score())
} else {
fmt.Printf("err: %v\n", vec.Base.GetError())
}
} |
Ok, thanks for the code snippets and answer. Nevertheless, let's suppose I have an untrusted input data source (worst case). How could I validate the vectors ? The fact is that I don't know if there will be only Base group defined, Base/Temporal, Base/Environmental or Base/Temporal/Environmental combinations.
|
Fixed error code if metric.*.Encode method is error (issue #28)
Release v1.6.1: package main
import (
"errors"
"fmt"
"github.com/goark/go-cvss/cvsserr"
"github.com/goark/go-cvss/v2/metric"
)
func main() {
raw := "AV:N/AC:L/Au:N/C:N/I:N/A:C/E:F/RL:OF/RC:C"
vec, err := metric.NewEnvironmental().Decode(raw)
fmt.Printf("err: %v\n", err)
fmt.Printf("vector: %v\n", vec)
switch true {
case errors.Is(err, cvsserr.ErrNoEnvironmentalMetrics):
fmt.Printf("Severity (Temporal): %v (%v)\n", vec.Temporal.Severity(), vec.Temporal.Score())
case errors.Is(err, cvsserr.ErrNoTemporalMetrics):
fmt.Printf("Severity (Base): %v (%v)\n", vec.Base.Severity(), vec.Base.Score())
default:
fmt.Printf("Severity (Environmental): %v (%v)\n", vec.Severity(), vec.Score())
}
} |
This behavior differs between your implementation of CVSS v2 and v3. For instance, the following Go code shows in the same conditions (no environmental metrics defined in the vector despite using an environmental object to decode) you don't raise an issue. package main
import (
"fmt"
"github.com/goark/go-cvss/v3/metric"
)
func main() {
raw := "CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N/E:F/RL:O/RC:C"
vec, err := metric.NewEnvironmental().Decode(raw)
fmt.Printf("vec: %v\n", vec)
fmt.Printf("err: %v\n", err)
} produces ->
|
Elements for Temporal and Environmental metrics are optional in CVSSv3 vector string, so if an element is omitted it will be completed with an This is the intended behavior. |
As specified in the first.org specification :
CVSS v2 vectors does not require all metrics, they require all of a group as soon as one metric of this group is specified (see Table 13). Subsequently, this is not the intended behavior. |
Fix encode CVSSv2 vector string when skip Temporal or Environmental (issue #28)
During differential fuzzing with
github.com/pandatix/go-cvss
I discovered that your implementation does not properly handle the case of a CVSS v2 environmental parsing for vectors that does not have environmental metrics defined.This could be categorized as CWE-20.
In order to be compliant with the first.org specification you must validate vectors that does not have environmental metrics defined.
The following Go code illustrates this issue.
Notice the input vector comes from the specification section 3.3.1 for the CVE-2002-0392.
produces ->
The text was updated successfully, but these errors were encountered: