@ulisesgascon/openjs-cna-tools 1.0.0-alpha.3 → 1.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/record.js CHANGED
@@ -1,8 +1,9 @@
1
1
  // Helpers for the parts of a v5.2 CVE Record that are about the record
2
- // format rather than about where the data came from: the CVSS metric block
3
- // and the record envelope. Converters (GHSA here, release trackers in
4
- // downstream projects) build the container fields they know about and use
5
- // these so the format-level details are written once.
2
+ // format rather than about where the data came from: the description, the
3
+ // CVSS metric block, the problem type and the record envelope. Converters
4
+ // (GHSA here, release trackers in downstream projects) build the container
5
+ // fields they know about and use these so the format-level details are
6
+ // written once.
6
7
 
7
8
  import { USER_AGENT } from './client.js'
8
9
  import { calculateBaseScore, severityFromScore } from './cvss.js'
@@ -12,6 +13,55 @@ import { OPENJS_CNA_ORG_ID } from './review/schema.js'
12
13
  // published by the OpenJS CNA carries today.
13
14
  export const DATA_VERSION = '5.2'
14
15
 
16
+ /**
17
+ * Strip Markdown formatting down to readable plain text. Generic: headers
18
+ * become "Label:" lines (the published OpenJS CVE convention), emphasis,
19
+ * code spans and links collapse to their text, list bullets and blockquote
20
+ * markers drop, line endings normalise to `\n`.
21
+ */
22
+ export function stripMarkdown (md) {
23
+ if (typeof md !== 'string') return ''
24
+ let text = md.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
25
+ // Headers → "Label:" (any ATX heading, level 1–6). [ \t]* rather than
26
+ // \s* so the blank lines around the heading survive.
27
+ text = text.replace(/^[ \t]*#{1,6}[ \t]+(.+?)[ \t]*$/gm, '$1:')
28
+ // **bold** / __bold__ / *italic* / _italic_ → inner text
29
+ text = text.replace(/\*\*(.+?)\*\*/g, '$1')
30
+ text = text.replace(/__(.+?)__/g, '$1')
31
+ text = text.replace(/(?<![*\w])\*(?!\s)(.+?)(?<!\s)\*(?![*\w])/g, '$1')
32
+ text = text.replace(/(?<![_\w])_(?!\s)(.+?)(?<!\s)_(?![_\w])/g, '$1')
33
+ // `inline code` → inner text
34
+ text = text.replace(/`(.+?)`/g, '$1')
35
+ // [link](url) → link
36
+ text = text.replace(/\[(.+?)\]\([^)]+\)/g, '$1')
37
+ // Bullet / ordered-list markers at line start → strip the marker
38
+ text = text.replace(/^\s*(?:[-*+]|\d+\.)\s+/gm, '')
39
+ // Blockquote markers
40
+ text = text.replace(/^\s*>\s?/gm, '')
41
+ // Collapse 3+ blank lines to a single blank line.
42
+ text = text.replace(/\n{3,}/g, '\n\n')
43
+ return text.trim()
44
+ }
45
+
46
+ /**
47
+ * Build one `descriptions[]` entry from text that may carry Markdown.
48
+ *
49
+ * MITRE's `value` is plain text (NVD and cve.org show it verbatim), so the
50
+ * Markdown is stripped for `value` and the original is kept in
51
+ * `supportingMedia` as `text/markdown`, only when the two differ. Returns
52
+ * `null` for empty input so callers can leave `descriptions` out.
53
+ */
54
+ export function buildDescription (text, { lang = 'en' } = {}) {
55
+ const raw = String(text ?? '').replace(/\r\n/g, '\n').replace(/\r/g, '\n').trim()
56
+ if (!raw) return null
57
+ const plain = stripMarkdown(raw) || raw
58
+ const description = { lang, value: plain }
59
+ if (raw !== plain) {
60
+ description.supportingMedia = [{ type: 'text/markdown', base64: false, value: raw }]
61
+ }
62
+ return description
63
+ }
64
+
15
65
  // Metric block key per CVSS version prefix. v2 is not emitted by anything
16
66
  // the foundation publishes, so it is left out on purpose.
17
67
  const METRIC_KEYS = new Map([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulisesgascon/openjs-cna-tools",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "EXPERIMENTAL fork of the OpenJS Foundation CNA tools: CLI and library for the OpenJS CNA API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -21,7 +21,8 @@
21
21
  "./convert": "./lib/convert/ghsa.js",
22
22
  "./cvss": "./lib/cvss.js",
23
23
  "./record": "./lib/record.js",
24
- "./batch": "./lib/batch.js"
24
+ "./batch": "./lib/batch.js",
25
+ "./hackerone": "./lib/hackerone/index.js"
25
26
  },
26
27
  "files": [
27
28
  "bin/",