Skip to content

Commit a986d81

Browse files
#130 Security issues output (#131)
Co-authored-by: Nicola Coretti <[email protected]>
1 parent b0a7037 commit a986d81

File tree

8 files changed

+103
-20
lines changed

8 files changed

+103
-20
lines changed

.github/actions/python-environment/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ runs:
1919
steps:
2020

2121
- name: Setup Python (${{ inputs.python-version}})
22-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ inputs.python-version }}
2525

@@ -30,4 +30,4 @@ runs:
3030

3131
- name: Poetry install
3232
run: poetry install
33-
shell: bash
33+
shell: bash

.github/actions/security-issues/action.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ inputs:
1919
description: 'Project the created tickets shall be associated with'
2020
required: false
2121

22+
23+
outputs:
24+
25+
created-issues:
26+
description: 'Information about the created issues and the vulnerabilities in JSONL format'
27+
value: ${{ steps.get-created-issues.outputs.issues }}
28+
2229
runs:
2330

2431
using: "composite"
2532
steps:
2633

2734
- name: Setup Python (${{ inputs.python-version}})
28-
uses: actions/setup-python@v4
35+
uses: actions/setup-python@v5
2936
with:
3037
python-version: 3.11
3138

@@ -57,13 +64,21 @@ runs:
5764
GH_TOKEN: ${{ inputs.github-token }}
5865
shell: bash
5966
run: |
60-
tbx security cve create --project "${{ inputs.project }}" < issues.jsonl | tee created.txt
67+
tbx security cve create --project "${{ inputs.project }}" < issues.jsonl | tee created.jsonl
68+
69+
- name: Define Output Parameter
70+
id: get-created-issues
71+
shell: bash
72+
run: |
73+
echo 'issues<<EOF' >> "$GITHUB_OUTPUT"
74+
cat created.jsonl >> "$GITHUB_OUTPUT"
75+
echo 'EOF' >> "$GITHUB_OUTPUT"
6176
6277
- name: Create Report
6378
shell: bash
6479
run: |
6580
echo -e "# Summary\n" >> $GITHUB_STEP_SUMMARY
6681
echo -e "## Created Security Issue\n" >> $GITHUB_STEP_SUMMARY
67-
cat created.txt >> $GITHUB_STEP_SUMMARY
82+
cat created.jsonl >> $GITHUB_STEP_SUMMARY
6883
echo -e "## Filtered Security Issue\n" >> $GITHUB_STEP_SUMMARY
6984
tail -n +2 filtered.txt | grep . || true >> $GITHUB_STEP_SUMMARY

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
Unreleased
77
==========
88

9+
✨ Added
10+
--------
11+
* Added output `created-issues` to `security-issues` action containing the found security issues including the created GitHub issues in JSONL format.
912

1013
.. _changelog-0.7.0:
1114

exasol/toolbox/templates/github/actions/python-environment/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ runs:
1919
steps:
2020

2121
- name: Setup Python (${{ inputs.python-version}})
22-
uses: actions/setup-python@v4
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ inputs.python-version }}
2525

exasol/toolbox/tools/security.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ def from_maven(report: str) -> Iterable[Issue]:
8888
# Note: Consider adding warnings if there is the same cve with multiple coordinates
8989
report = json.loads(report)
9090
dependencies = report.get("vulnerable", {}) # type: ignore
91-
for _, dependency in dependencies.items(): # type: ignore
91+
for dependency_name, dependency in dependencies.items(): # type: ignore
9292
for v in dependency["vulnerabilities"]: # type: ignore
9393
references = [v["reference"]] + v["externalReferences"]
9494
yield Issue(
9595
cve=v["cve"],
9696
cwe=v["cwe"],
9797
description=v["description"],
98-
coordinates=dependency["coordinates"],
98+
coordinates=dependency_name,
9999
references=tuple(references),
100100
)
101101

@@ -251,10 +251,14 @@ def create(
251251
Links to the created issue(s)
252252
"""
253253
for issue in _issues(input_file):
254-
std_err, std_out = create_security_issue(issue, project)
254+
std_err, issue_url = create_security_issue(issue, project)
255255
stderr(std_err)
256-
stdout(std_out)
256+
stdout(format_jsonl(issue_url, issue))
257257

258+
def format_jsonl(issue_url: str, issue: Issue) -> str:
259+
issue_json = asdict(issue)
260+
issue_json["url"] = issue_url.strip()
261+
return json.dumps(issue_json)
258262

259263
if __name__ == "__main__":
260264
CLI()

test/integration/cli/security-cve-convert.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Test convert maven input from stdin
7373
"cve": "CVE-2020-4333",
7474
"cwe": "CWE-502",
7575
"description": "When deserializing untrusted or corrupted data, it is possible for a reader to consume memory beyond the allowed constraints and thus lead to out of memory on the system.\n\nThis issue affects Java applications using Apache Avro Java SDK up to and including 1.11.2. Users should update to apache-avro version 1.11.3 which addresses this issue.\n\n",
76-
"coordinates": "pkg:maven/org.apache.avro/avro@1.7.7",
76+
"coordinates": "org.apache.avro:avro:jar:1.7.7:compile",
7777
"references": [
7878
"https://ossindex.sonatype.org/vulnerability/CVE-2023-39410?component-type=maven&component-name=org.apache.avro%2Favro&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
7979
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2023-39410",
@@ -86,7 +86,7 @@ Test convert maven input from stdin
8686
"cve": "CVE-2020-36641",
8787
"cwe": "CWE-611",
8888
"description": "A vulnerability classified as problematic was found in gturri aXMLRPC up to 1.12.0. This vulnerability affects the function ResponseParser of the file src/main/java/de/timroes/axmlrpc/ResponseParser.java. The manipulation leads to xml external entity reference. Upgrading to version 1.12.1 is able to address this issue. The patch is identified as ad6615b3ec41353e614f6ea5fdd5b046442a832b. It is recommended to upgrade the affected component. VDB-217450 is the identifier assigned to this vulnerability.\n\nSonatype's research suggests that this CVE's details differ from those defined at NVD. See https://ossindex.sonatype.org/vulnerability/CVE-2020-36641 for details",
89-
"coordinates": "pkg:maven/fr.turri/aXMLRPC@1.13.0",
89+
"coordinates": "fr.turri:aXMLRPC:jar:1.13.0:test",
9090
"references": [
9191
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641?component-type=maven&component-name=fr.turri%2FaXMLRPC&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
9292
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-36641",
@@ -101,7 +101,7 @@ Test convert maven input from file
101101
"cve": "CVE-2020-4333",
102102
"cwe": "CWE-502",
103103
"description": "When deserializing untrusted or corrupted data, it is possible for a reader to consume memory beyond the allowed constraints and thus lead to out of memory on the system.\n\nThis issue affects Java applications using Apache Avro Java SDK up to and including 1.11.2. Users should update to apache-avro version 1.11.3 which addresses this issue.\n\n",
104-
"coordinates": "pkg:maven/org.apache.avro/avro@1.7.7",
104+
"coordinates": "org.apache.avro:avro:jar:1.7.7:compile",
105105
"references": [
106106
"https://ossindex.sonatype.org/vulnerability/CVE-2023-39410?component-type=maven&component-name=org.apache.avro%2Favro&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
107107
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2023-39410",
@@ -114,7 +114,7 @@ Test convert maven input from file
114114
"cve": "CVE-2020-36641",
115115
"cwe": "CWE-611",
116116
"description": "A vulnerability classified as problematic was found in gturri aXMLRPC up to 1.12.0. This vulnerability affects the function ResponseParser of the file src/main/java/de/timroes/axmlrpc/ResponseParser.java. The manipulation leads to xml external entity reference. Upgrading to version 1.12.1 is able to address this issue. The patch is identified as ad6615b3ec41353e614f6ea5fdd5b046442a832b. It is recommended to upgrade the affected component. VDB-217450 is the identifier assigned to this vulnerability.\n\nSonatype's research suggests that this CVE's details differ from those defined at NVD. See https://ossindex.sonatype.org/vulnerability/CVE-2020-36641 for details",
117-
"coordinates": "pkg:maven/fr.turri/aXMLRPC@1.13.0",
117+
"coordinates": "fr.turri:aXMLRPC:jar:1.13.0:test",
118118
"references": [
119119
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641?component-type=maven&component-name=fr.turri%2FaXMLRPC&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
120120
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-36641",

test/integration/cli/security-cve-create.t

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Create a GitHub CLI mock
22

33
$ cat > gh <<EOF
44
> #!/usr/bin/sh
5-
> echo https://github.com/exasol/a-project/issues/`uuidgen`
5+
> echo https://github.com/exasol/a-project/issues/123
66
> EOF
77

88
$ chmod u+x gh
@@ -18,6 +18,30 @@ Create test input
1818

1919
Run test case
2020

21-
$ tbx security cve create cves.jsonl 2> /dev/null | grep .
22-
https://github.com/exasol/a-project/issues/[a-f0-9\-]+ (re)
23-
https://github.com/exasol/a-project/issues/[a-f0-9\-]+ (re)
21+
$ tbx security cve create cves.jsonl 2> /dev/null | python -m json.tool --json-lines
22+
{
23+
"cve": "CVE-2023-39410",
24+
"cwe": "CWE-502",
25+
"description": "When deserializing untrusted or corrupted data, it is possible for a reader to consume memory beyond the allowed constraints and thus lead to out of memory on the system.\n\nThis issue affects Java applications using Apache Avro Java SDK up to and including 1.11.2. Users should update to apache-avro version 1.11.3 which addresses this issue.\n\n",
26+
"coordinates": "pkg:maven/org.apache.avro/[email protected]",
27+
"references": [
28+
"https://ossindex.sonatype.org/vulnerability/CVE-2023-39410?component-type=maven&component-name=org.apache.avro%2Favro&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
29+
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2023-39410",
30+
"https://github.com/apache/avro/pull/2432",
31+
"https://issues.apache.org/jira/browse/AVRO-3819",
32+
"https://lists.apache.org/thread/q142wj99cwdd0jo5lvdoxzoymlqyjdds"
33+
],
34+
"url": "https://github.com/exasol/a-project/issues/123"
35+
}
36+
{
37+
"cve": "CVE-2020-36641",
38+
"cwe": "CWE-611",
39+
"description": "A vulnerability classified as problematic was found in gturri aXMLRPC up to 1.12.0. This vulnerability affects the function ResponseParser of the file src/main/java/de/timroes/axmlrpc/ResponseParser.java. The manipulation leads to xml external entity reference. Upgrading to version 1.12.1 is able to address this issue. The patch is identified as ad6615b3ec41353e614f6ea5fdd5b046442a832b. It is recommended to upgrade the affected component. VDB-217450 is the identifier assigned to this vulnerability.\n\nSonatype's research suggests that this CVE's details differ from those defined at NVD. See https://ossindex.sonatype.org/vulnerability/CVE-2020-36641 for details",
40+
"coordinates": "pkg:maven/fr.turri/[email protected]",
41+
"references": [
42+
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641?component-type=maven&component-name=fr.turri%2FaXMLRPC&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
43+
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-36641",
44+
"https://www.tenable.com/cve/CVE-2020-36641"
45+
],
46+
"url": "https://github.com/exasol/a-project/issues/123"
47+
}

test/unit/security_test.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def test_convert_maven_input(maven_report): # pylint: disable=redefined-outer-n
317317
"Java SDK up to and including 1.11.2. Users should update "
318318
"to apache-avro version 1.11.3 which addresses this issue.\n"
319319
"\n",
320-
coordinates="pkg:maven/org.apache.avro/avro@1.7.7",
320+
coordinates="org.apache.avro:avro:jar:1.7.7:compile",
321321
references=(
322322
"https://ossindex.sonatype.org/vulnerability/CVE-2023-39410?component-type=maven&component-name=org.apache.avro%2Favro&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
323323
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2023-39410",
@@ -344,7 +344,7 @@ def test_convert_maven_input(maven_report): # pylint: disable=redefined-outer-n
344344
"differ from those defined at NVD. See "
345345
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641 "
346346
"for details",
347-
coordinates="pkg:maven/fr.turri/aXMLRPC@1.13.0",
347+
coordinates="fr.turri:aXMLRPC:jar:1.13.0:test",
348348
references=(
349349
"https://ossindex.sonatype.org/vulnerability/CVE-2020-36641?component-type=maven&component-name=fr.turri%2FaXMLRPC&utm_source=ossindex-client&utm_medium=integration&utm_content=1.8.1",
350350
"http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-36641",
@@ -359,3 +359,40 @@ def test_convert_maven_input(maven_report): # pylint: disable=redefined-outer-n
359359
def test_convert_maven_input_no_vulnerable(): # pylint: disable=redefined-outer-name
360360
actual = set(security.from_maven("{}"))
361361
assert len(actual) == 0
362+
363+
def test_format_jsonl():
364+
issue = security.Issue(
365+
coordinates="coordinates",
366+
cve="cve", cwe="cwe",
367+
description="description",
368+
references=()
369+
)
370+
expected = json.dumps({
371+
"cve": "cve",
372+
"cwe": "cwe",
373+
"description": "description",
374+
"coordinates": "coordinates",
375+
"references": [],
376+
"url": "issue_url"
377+
})
378+
actual = security.format_jsonl("issue_url", issue)
379+
assert actual == expected
380+
381+
382+
def test_format_jsonl_removes_newline():
383+
issue = security.Issue(
384+
coordinates="coordinates",
385+
cve="cve", cwe="cwe",
386+
description="description",
387+
references=()
388+
)
389+
expected = json.dumps({
390+
"cve": "cve",
391+
"cwe": "cwe",
392+
"description": "description",
393+
"coordinates": "coordinates",
394+
"references": [],
395+
"url": "issue_url"
396+
})
397+
actual = security.format_jsonl("issue_url\n", issue)
398+
assert actual == expected

0 commit comments

Comments
 (0)