-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cwe): add cwe into sarif report and KICS CLI results #6845
Merged
Changes from 17 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
4eaedbe
feat(cwe): add cwe into sarif report and KICS CLI results
ArturRibeiro-CX 4cf3afd
feat(cwe): add cwe into sarif report and KICS CLI results
ArturRibeiro-CX 90bb750
feat(cwe): add cwe into sarif report and KICS CLI results
ArturRibeiro-CX df81fab
feat(cwe): add cwe into sarif report and KICS CLI results
ArturRibeiro-CX 9636be8
feat(cwe): add cwe into sarif report and KICS CLI results
ArturRibeiro-CX 1722b58
Merge branch 'master' into cwe
gabriel-cx 20cd3c4
added e2e test for cwe field in sarif report format
ArturRibeiro-CX 060b459
Merge branch 'master' of https://github.com/Checkmarx/kics into cwe
ArturRibeiro-CX 4fb60c3
Merge branch 'cwe' of https://github.com/Checkmarx/kics into cwe
ArturRibeiro-CX 33a15ed
added e2e test for cwe field in sarif report format
ArturRibeiro-CX 18f9dc9
fix cyclonedx commit on wrong branch
ArturRibeiro-CX 4698101
fix cyclonedx commit on wrong branch
ArturRibeiro-CX aeec710
fix cyclonedx commit on wrong branch and remove comments
ArturRibeiro-CX 4a6ffda
Merge branch 'master' into cwe
gabriel-cx ca788e3
remove cwe from sarifMessage
ArturRibeiro-CX b15da83
changes to addition of cwe into sarif report and KICS CLI results
ArturRibeiro-CX cfa3df8
fixing potential file inclusion via variable error by cleaning paths
ArturRibeiro-CX 6aad350
linting issues fixed
ArturRibeiro-CX 5d26283
fixing linting issues
ArturRibeiro-CX 1fd0d35
Merge branch 'master' of https://github.com/Checkmarx/kics into cwe
ArturRibeiro-CX 3ebc66c
fix linting e2e and naming
ArturRibeiro-CX 842f2e4
fix linting problems
ArturRibeiro-CX a516a11
fixing linting
ArturRibeiro-CX b548e42
fixing linting problem sarif.go
ArturRibeiro-CX 8cd6e4b
change to result-sarif.json to accept the new sarif format
ArturRibeiro-CX 30c5e55
changes to result-sarif-required.json to accept new sarif format
ArturRibeiro-CX e797987
e2e for sarif report format
ArturRibeiro-CX 30ae8bf
change bool to boolean type in result-sarif.json
ArturRibeiro-CX f4c5c04
addition of fullDescription text field as empty string to fix e2e error
ArturRibeiro-CX c854f72
fixing fullDescription text required issue on e2e
ArturRibeiro-CX 9a827a1
Merge branch 'master' of https://github.com/Checkmarx/kics into cwe
ArturRibeiro-CX cfa1383
fullDescription equal to shortDescription in taxonomies when empty an…
ArturRibeiro-CX f23a0f9
last fix e2e result sarif files
ArturRibeiro-CX dfe8739
add path to uri locations in E2E_CLI_080 and E2E_CLI_070
ArturRibeiro-CX a256ac0
fix paths E2E_CLI 069 and 070
ArturRibeiro-CX cedc806
add new files to Dockerfile and error verification to sarif.go
ArturRibeiro-CX 49af1ae
fix addition of new files to Dockerfile
ArturRibeiro-CX 8770998
relationship target changed from array to object
ArturRibeiro-CX 7786f26
fix to index being required in relationships as CWE does not require …
ArturRibeiro-CX 1cd8a84
fix to name and guid not being required and lenght of this parameters
ArturRibeiro-CX ffebe5b
fix id lenght when parameters are empty in relationships
ArturRibeiro-CX 8ba89af
changes to sarif report cwe field empty or not and according files
ArturRibeiro-CX 655febf
change to name being required on toolComponent and not target in rela…
ArturRibeiro-CX 9c48780
add test to printer with CWE field
ArturRibeiro-CX 0e4a197
Merge branch 'master' into cwe
ArturRibeiro-CX 9da0e25
add test case for vulnerability builder test with CWE field
ArturRibeiro-CX 6138693
add test to summary_test
ArturRibeiro-CX 86ef7e0
changes to summary_test to have CWE complete
ArturRibeiro-CX f5ca9b6
add tests for taxonomies and taxa fields in sarif report
ArturRibeiro-CX 8f40e37
add one more test to taxonomies definition with no CWE field
ArturRibeiro-CX 5634af0
added test for reading the csv file with CWE info correctly
ArturRibeiro-CX 85b338f
add new cwe_csv to all dockerfiles in docker directory
ArturRibeiro-CX 646f5a5
test Dockerfile change by coppying all directory
ArturRibeiro-CX 82c3962
changes to all dockerfile necessary to copy cwe_csv directory without…
ArturRibeiro-CX 8670aaa
fix typo replacing Run with RUN on Dockerfile in kics root
ArturRibeiro-CX 30846f7
remove '/' from COPY statement in Dockerfiles to maintain the same logic
ArturRibeiro-CX 6c4c407
Merge branch 'master' into cwe
asofsilva 1fafda4
Merge branch 'master' into cwe
gabriel-cx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package testcases | ||
|
||
// E2E-CLI-077 - KICS scan | ||
// should perform a scan saving the reports in sarif format, completing the cwe field when it has values | ||
func init() { //nolint | ||
testSample := TestCase{ | ||
Name: "should perform a scan saving the reports in sarif format, completing the cwe field when it has values [E2E-CLI-077]", | ||
Args: args{ | ||
Args: []cmdArgs{ | ||
[]string{"scan", "-o", "/path/e2e/output", | ||
"--output-name", "E2E_CLI_077_RESULT", | ||
"-p", "\"/path/test/fixtures/test_sarif_cwe_report\"", | ||
"--report-formats", "sarif", | ||
}, | ||
}, | ||
ExpectedResult: []ResultsValidation{ | ||
{ | ||
ResultsFile: "E2E_CLI_077_RESULT", | ||
ResultsFormats: []string{"sarif"}, | ||
}, | ||
}, | ||
}, | ||
WantStatus: []int{50}, | ||
} | ||
|
||
Tests = append(Tests, testSample) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/fixtures/test_sarif_cwe_report/run_block_injection/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "20f14e1a-a899-4e79-9f09-b6a84cd4649b", | ||
"queryName": "Run Block Injection", | ||
"severity": "HIGH", | ||
"category": "Insecure Configurations", | ||
"descriptionText": "GitHub Actions workflows can be triggered by a variety of events. Every workflow trigger is provided with a GitHub context that contains information about the triggering event, such as which user triggered it, the branch name, and other event context details. Some of this event data, like the base repository name, hash value of a changeset, or pull request number, is unlikely to be controlled or used for injection by the user that triggered the event.", | ||
"descriptionUrl": "https://securitylab.github.com/research/github-actions-untrusted-input/", | ||
"platform": "CICD", | ||
"descriptionID": "02044a75", | ||
"cloudProvider": "common", | ||
"cwe": "1234" | ||
} |
186 changes: 186 additions & 0 deletions
186
test/fixtures/test_sarif_cwe_report/run_block_injection/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
|
||
input.document[i].on["pull_request_target"] | ||
run := input.document[i].jobs[j].steps[k].run | ||
|
||
patterns := [ | ||
"github.head_ref", | ||
"github.event.pull_request.body", | ||
"github.event.pull_request.head.label", | ||
"github.event.pull_request.head.ref", | ||
"github.event.pull_request.head.repo.default_branch", | ||
"github.event.pull_request.head.repo.description", | ||
"github.event.pull_request.head.repo.homepage", | ||
"github.event.pull_request.title" | ||
] | ||
|
||
matched = containsPatterns(run, patterns) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("run={{%s}}", [run]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Run block does not contain dangerous input controlled by user.", | ||
"keyActualValue": "Run block contains dangerous input controlled by user.", | ||
"searchLine": common_lib.build_search_line(["jobs", j, "steps", k, "run"],[]), | ||
"searchValue": matched[m] | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
|
||
input.document[i].on["issues"] | ||
run := input.document[i].jobs[j].steps[k].run | ||
|
||
patterns := [ | ||
"github.event.issue.body", | ||
"github.event.issue.title" | ||
] | ||
|
||
matched = containsPatterns(run, patterns) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("run={{%s}}", [run]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Run block does not contain dangerous input controlled by user.", | ||
"keyActualValue": "Run block contains dangerous input controlled by user.", | ||
"searchLine": common_lib.build_search_line(["jobs", j, "steps", k, "run"],[]), | ||
"searchValue": matched[m] | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
|
||
input.document[i].on["issue_comment"] | ||
run := input.document[i].jobs[j].steps[k].run | ||
|
||
patterns := [ | ||
"github.event.comment.body", | ||
"github.event.issue.body", | ||
"github.event.issue.title" | ||
] | ||
|
||
matched = containsPatterns(run, patterns) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("run={{%s}}", [run]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Run block does not contain dangerous input controlled by user.", | ||
"keyActualValue": "Run block contains dangerous input controlled by user.", | ||
"searchLine": common_lib.build_search_line(["jobs", j, "steps", k, "run"],[]), | ||
"searchValue": matched[m] | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
|
||
input.document[i].on["discussion"] | ||
run := input.document[i].jobs[j].steps[k].run | ||
|
||
patterns := [ | ||
"github.event.discussion.body", | ||
"github.event.discussion.title" | ||
] | ||
|
||
matched = containsPatterns(run, patterns) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("run={{%s}}", [run]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Run block does not contain dangerous input controlled by user.", | ||
"keyActualValue": "Run block contains dangerous input controlled by user.", | ||
"searchLine": common_lib.build_search_line(["jobs", j, "steps", k, "run"],[]), | ||
"searchValue": matched[m] | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
|
||
input.document[i].on["discussion_comment"] | ||
run := input.document[i].jobs[j].steps[k].run | ||
|
||
patterns := [ | ||
"github.event.comment.body", | ||
"github.event.discussion.body", | ||
"github.event.discussion.title" | ||
] | ||
|
||
matched = containsPatterns(run, patterns) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("run={{%s}}", [run]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Run block does not contain dangerous input controlled by user.", | ||
"keyActualValue": "Run block contains dangerous input controlled by user.", | ||
"searchLine": common_lib.build_search_line(["jobs", j, "steps", k, "run"],[]), | ||
"searchValue": matched[m] | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
|
||
input.document[i].on["workflow_run"] | ||
run := input.document[i].jobs[j].steps[k].run | ||
|
||
patterns := [ | ||
"github.event.workflow.path", | ||
"github.event.workflow_run.head_branch", | ||
"github.event.workflow_run.head_commit.author.email", | ||
"github.event.workflow_run.head_commit.author.name", | ||
"github.event.workflow_run.head_commit.message", | ||
"github.event.workflow_run.head_repository.description" | ||
] | ||
|
||
matched = containsPatterns(run, patterns) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("run={{%s}}", [run]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Run block does not contain dangerous input controlled by user.", | ||
"keyActualValue": "Run block contains dangerous input controlled by user.", | ||
"searchLine": common_lib.build_search_line(["jobs", j, "steps", k, "run"],[]), | ||
"searchValue": matched[m] | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
|
||
input.document[i].on["author"] | ||
run := input.document[i].jobs[j].steps[k].run | ||
|
||
patterns := [ | ||
"github.*.authors.name", | ||
"github.*.authors.email" | ||
] | ||
|
||
matched = containsPatterns(run, patterns) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("run={{%s}}", [run]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "Run block does not contain dangerous input controlled by user.", | ||
"keyActualValue": "Run block contains dangerous input controlled by user.", | ||
"searchLine": common_lib.build_search_line(["jobs", j, "steps", k, "run"],[]), | ||
"searchValue": matched[m] | ||
} | ||
} | ||
|
||
|
||
|
||
containsPatterns(str, patterns) = matched { | ||
matched := {pattern | | ||
pattern := patterns[_] | ||
regex.match(pattern, str) | ||
} | ||
} | ||
|
29 changes: 29 additions & 0 deletions
29
test/fixtures/test_sarif_cwe_report/run_block_injection/test/negative.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: check-go-coverage | ||
|
||
on: | ||
pull_request_target: | ||
branches: [master] | ||
|
||
jobs: | ||
coverage: | ||
name: Check Go coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Source | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go 1.20.x | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.20.x | ||
- name: Run test metrics script | ||
id: testcov | ||
run: | | ||
make test-coverage-report | tee test-results | ||
echo "coverage=$(cat test-results | grep "Total coverage: " test-results | cut -d ":" -f 2 | bc)" >> $GITHUB_ENV | ||
- name: Checks if Go coverage is at least 80% | ||
if: env.coverage < 80 | ||
run: | | ||
echo "Go coverage is lower than 80%: ${{ env.coverage }}%" | ||
exit 1 |
15 changes: 15 additions & 0 deletions
15
test/fixtures/test_sarif_cwe_report/run_block_injection/test/negative2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Issue Workflow | ||
|
||
on: | ||
issues: | ||
types: | ||
- opened | ||
|
||
jobs: | ||
process_issue: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Greet the New Issue | ||
run: | | ||
# Echo a simple sentence | ||
echo "Hello, a new issue has been opened!" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need this item?