Skip to content

Commit d228a5b

Browse files
Replace categories with CWEs
1 parent 2693e66 commit d228a5b

File tree

4 files changed

+17
-27
lines changed

4 files changed

+17
-27
lines changed

proposals/advisory-db.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ The TOML frontmatter must contain a table called `advisory` and a table called `
9292
* `package`, a string, the name of the affected Hackage package
9393
* `date`, a TOML local date, which is the disclosure date.
9494
* `url`, an optional string, which is a link to a resource such as release notes or a blog post that describes the issue in detail
95-
* `categories`, an optional array of strings, each of which one of `...` TODO
96-
* `cvss`, an optional string, which is a CVSS 3.1 vector
95+
* `cwe`, an optional array of integers, each of which is a [CWE identifier](https://cwe.mitre.org/index.html)
96+
* `cvss`, an optional string, which is a [CVSS 3.1 vector](https://www.first.org/cvss/)
9797
* `keywords`, an optional array of strings, which may be any string that the submitter finds relevant. By convention, they are written in lowercase.
9898
* `aliases`, an optional array of strings, each of which is another identifier such as a CVE
9999
* `related`, an optional array of strings, each of which is an identifier for a related advisory (such as for a wrapped C library)

proposals/advisory-db/advisory-proposal.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ executable advisory-proposal
2929

3030
-- LANGUAGE extensions used by modules in this package.
3131
-- other-extensions:
32-
build-depends: base ^>=4.14.3.0,
32+
build-depends: base >=4.14 && < 4.17,
3333
commonmark ^>= 0.2.2,
3434
text ^>= 1.2,
3535
time ^>= 1.9,

proposals/advisory-db/app/Main.hs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ main = do
6868

6969
exitSuccess
7070

71-
data Category = CodeExecution | CryptoFailure | PrivilegeEscalation | DOS | FileDisclosure | FormatInjection | MemoryCorruption | MemoryExposure
71+
newtype CWE = CWE { unCWE :: Integer }
7272
deriving (Show)
7373

7474
data Architecture = AArch64 | Alpha | Arm | HPPA | HPPA1_1 | I386 | IA64 | M68K | MIPS | MIPSEB | MIPSEL | NIOS2 | PowerPC | PowerPC64 | PowerPC64LE | RISCV32 | RISCV64 | RS6000 | S390 | S390X | SH4 | SPARC | SPARC64 | VAX | X86_64
@@ -89,7 +89,7 @@ data Advisory = Advisory
8989
advisoryPackage :: Text,
9090
advisoryDate :: Date,
9191
advisoryUrl :: Text,
92-
advisoryCategories :: [Category],
92+
advisoryCWEs :: [CWE],
9393
advisoryKeywords :: [Keyword],
9494
advisoryAliases :: [Text],
9595
advisoryCVSS :: Maybe Text,
@@ -112,7 +112,7 @@ renderAdvisory adv =
112112
row "Package" advisoryPackage,
113113
row "Date" (date . advisoryDate),
114114
row "URL" advisoryUrl,
115-
row "Categories" (T.intercalate ", " . map (T.pack . show) . advisoryCategories),
115+
row "CWEs" (T.intercalate ", " . map (T.pack . show . unCWE) . advisoryCWEs),
116116
row "Keywords" (T.intercalate ", " . map (T.pack . show) . advisoryKeywords),
117117
row "Aliases" (T.intercalate ", " . advisoryAliases),
118118
row "CVSS" (fromMaybe "" . advisoryCVSS),
@@ -139,7 +139,7 @@ parseAdvisory table = runTableParser $ do
139139
package <- mandatory advisory "package" isString
140140
date <- mandatory advisory "date" isDate <&> uncurry3 Date . toGregorian
141141
url <- mandatory advisory "url" isString
142-
cats <- fromMaybe [] <$> optional advisory "categories" (isArrayOf (isString >=> category))
142+
cats <- fromMaybe [] <$> optional advisory "cwe" (isArrayOf (fmap CWE . isInt))
143143
kwds <- fromMaybe [] <$> optional advisory "keywords" (isArrayOf (fmap Keyword . isString))
144144
aliases <- fromMaybe [] <$> optional advisory "aliases" (isArrayOf isString)
145145
cvss <- optional advisory "cvss" isString
@@ -162,7 +162,7 @@ parseAdvisory table = runTableParser $ do
162162
advisoryPackage = package,
163163
advisoryDate = date,
164164
advisoryUrl = url,
165-
advisoryCategories = cats,
165+
advisoryCWEs = cats,
166166
advisoryKeywords = kwds,
167167
advisoryAliases = aliases,
168168
advisoryCVSS = cvss,
@@ -176,17 +176,6 @@ parseAdvisory table = runTableParser $ do
176176
uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d
177177
uncurry3 f (x, y, z) = f x y z
178178

179-
category :: Text -> TableParser Category
180-
category "code-execution" = pure CodeExecution
181-
category "crypto-failure" = pure CryptoFailure
182-
category "denial-of-service" = pure DOS
183-
category "file-disclosure" = pure FileDisclosure
184-
category "format-injection" = pure FormatInjection
185-
category "memory-corruption" = pure MemoryCorruption
186-
category "memory-exposure" = pure MemoryExposure
187-
category "privilege-escalation" = pure PrivilegeEscalation
188-
category other = throwError $ InvalidCategory other
189-
190179
operatingSystem :: Text -> TableParser OS
191180
operatingSystem "darwin" = pure MacOS
192181
operatingSystem "freebsd" = pure FreeBSD
@@ -236,7 +225,6 @@ data TableParseErr
236225
= UnexpectedKeys (NonEmpty Text)
237226
| MissingKey Text
238227
| InvalidFormat Text Text
239-
| InvalidCategory Text
240228
| InvalidOS Text
241229
| InvalidArchitecture Text
242230
| UnderlyingParserError Text
@@ -263,6 +251,10 @@ mandatory tbl k act = onKey tbl k (throwError $ MissingKey k) act
263251
onKey :: TOML.Table -> Text -> TableParser a -> (TOML.Value -> TableParser a) -> TableParser a
264252
onKey tbl k absent present = maybe absent present $ Map.lookup k tbl
265253

254+
isInt :: TOML.Value -> TableParser Integer
255+
isInt (TOML.Integer i) = pure i
256+
isInt other = throwError $ InvalidFormat "Integer" (describeValue other)
257+
266258
isString :: TOML.Value -> TableParser Text
267259
isString (TOML.String txt) = pure txt
268260
isString other = throwError $ InvalidFormat "String" (describeValue other)

proposals/advisory-db/example.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66
id = "HSEC-0000-0000"
77

88
# Name of the affected package on Hackage (mandatory)
9-
package = "mycrate"
9+
package = "acme-broken"
1010

1111
# Disclosure date of the advisory as an RFC 3339 date (mandatory)
1212
date = 2021-01-31
1313

1414
# URL to a long-form description of this issue, e.g. a GitHub issue/PR,
1515
# a change log entry, or a blogpost announcing the release (optional)
16-
url = "https://github.com/mystuff/package/issues/123"
16+
url = "https://github.com/username/package/issues/123"
1717

18-
# Optional: Categories this advisory falls under. Valid categories are:
19-
# "code-execution", "crypto-failure", "denial-of-service", "file-disclosure"
20-
# "format-injection", "memory-corruption", "memory-exposure", "privilege-escalation"
21-
categories = ["crypto-failure"]
18+
# Optional: Classification of the advisory with respect to the Common Weakness Enumeration.
19+
cwe = [820]
2220

2321
# Optional: a Common Vulnerability Scoring System score. More information
2422
# can be found on the CVSS website, https://www.first.org/cvss/.
@@ -56,7 +54,7 @@ keywords = ["ssl", "mitm"]
5654
# name (e.g. if an affected function or datatype was renamed between versions).
5755
# The path syntax is the module import path, without any type signatures or
5856
# additional information, followed by the affected versions.
59-
#declarations = { "Acme.Broken.function" = ">= 1.1.0 && < 1.2.0", "Acme.Broken.renamedFunction = ">= 1.2.0 && < 1.2.0.5"}
57+
#declarations = { "Acme.Broken.function" = ">= 1.1.0 && < 1.2.0", "Acme.Broken.renamedFunction" = ">= 1.2.0 && < 1.2.0.5"}
6058

6159
# Versions affected by the vulnerability
6260
[versions]

0 commit comments

Comments
 (0)