Skip to content

Commit

Permalink
Auto-parse cvss vectors and present in gql (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Dec 13, 2024
1 parent 345190a commit c7b54be
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/src/generated/graphql-kubernetes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
/* prettier-ignore */
import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client';
Expand Down
2 changes: 1 addition & 1 deletion assets/src/generated/graphql-plural.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
/* prettier-ignore */
import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client';
Expand Down
2 changes: 1 addition & 1 deletion assets/src/generated/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
/* prettier-ignore */
import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client';
Expand Down
37 changes: 37 additions & 0 deletions lib/console/utils/vuln.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule Console.Utils.Vuln do
def grade("LOW"), do: :low
def grade("MEDIUM"), do: :medium
def grade("HIGH"), do: :high
def grade("CRITICAL"), do: :critical
def grade("L"), do: :low
def grade("M"), do: :medium
def grade("H"), do: :high
def grade(_), do: :none

def vector("N"), do: :network
def vector("A"), do: :adjacent
def vector("L"), do: :local
def vector("P"), do: :physical

def requirement("N"), do: :none
def requirement("R"), do: :required

def parse_v3_vector("CVSS:" <> rest) do
[_ | parts] = String.split(rest, "/")
Enum.map(parts, fn part ->
case String.split(part, ":") do
["AV", v] -> {:attack_vector, vector(v)}
["AC", c] -> {:attack_complexity, grade(c)}
["PR", p] -> {:privileges_required, grade(p)}
["UI", ui] -> {:user_interaction, requirement(ui)}
["C", c] -> {:confidentiality, grade(c)}
["I", i] -> {:integrity, grade(i)}
["A", a] -> {:availability, grade(a)}
_ -> nil
end
end)
|> Enum.filter(& &1)
|> Enum.into(%{})
end
def parse_v3_vector(_), do: %{}
end

0 comments on commit c7b54be

Please sign in to comment.