Skip to content

Commit

Permalink
Merge pull request #7207 from Checkmarx/AST-54409
Browse files Browse the repository at this point in the history
fix(query): fix CWE field not appearing in KICS CLI and sarif reports
  • Loading branch information
cx-andrep authored Jul 30, 2024
2 parents f707b51 + c833aa8 commit f0cf78d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,20 @@ def generate_md_docs(queries_database : str, output_path : str, template_file_pa
doc_template = f.read()

for key, query_data in queries_database.items():
cwe = query_data.get('cwe', '')
if cwe == '':
cwe = 'Ongoing'
else:
cwe_url = f'https://cwe.mitre.org/data/definitions/{cwe}.html'
cwe = f'<a href="{cwe_url}" onclick="newWindowOpenerSafe(event, \'{cwe_url}\')">{cwe}</a>'

query_doc = doc_template
query_doc = doc_template.replace('<QUERY_ID>', key).replace(
'<QUERY_NAME>', query_data.get('queryName')).replace(
'<PLATFORM>', query_data.get('platform')).replace(
'<SEVERITY>', format_severity(query_data.get('severity'))).replace(
'<CATEGORY>', query_data.get('category')).replace(
'<CWE>', cwe).replace(
'<GITHUB_URL>', query_data.get('githubUrl')).replace(
'<DESCRIPTION_TEXT>', query_data.get('descriptionText')).replace(
'<DESCRIPTION_URL>', query_data.get('descriptionUrl')).replace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ hide:
- **Platform:** <PLATFORM>
- **Severity:** <SEVERITY>
- **Category:** <CATEGORY>
- **CWE:** <CWE>
- **URL:** [Github](<GITHUB_URL>)

### Description
Expand Down
2 changes: 2 additions & 0 deletions e2e/fixtures/E2E_CLI_032_RESULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"query_url": "https://docs.kics.io/latest/secrets/",
"severity": "HIGH",
"platform": "Common",
"cwe": "798",
"cloud_provider": "COMMON",
"category": "Secret Management",
"experimental": false,
Expand All @@ -97,6 +98,7 @@
"query_url": "https://docs.kics.io/latest/secrets/",
"severity": "HIGH",
"platform": "Common",
"cwe": "798",
"cloud_provider": "COMMON",
"category": "Secret Management",
"experimental": false,
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_086_RESULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"query_url": "https://docs.kics.io/latest/secrets/",
"severity": "HIGH",
"platform": "Common",
"cwe": "798",
"cloud_provider": "COMMON",
"category": "Secret Management",
"experimental": false,
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_087_RESULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"query_url": "https://docs.kics.io/latest/secrets/",
"severity": "HIGH",
"platform": "Common",
"cwe": "798",
"cloud_provider": "COMMON",
"category": "Secret Management",
"experimental": false,
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/E2E_CLI_088_RESULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"query_url": "https://docs.kics.io/latest/secrets/",
"severity": "HIGH",
"platform": "Common",
"cwe": "798",
"cloud_provider": "COMMON",
"category": "Secret Management",
"experimental": false,
Expand Down
1 change: 1 addition & 0 deletions pkg/engine/secrets/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ func (c *Inspector) addVulnerability(basePaths []string, file *model.FileMetadat
VulnLines: hideSecret(&linesVuln, issueLine, query, &c.SecretTracker),
IssueType: "RedundantAttribute",
Platform: SecretsQueryMetadata["platform"],
CWE: SecretsQueryMetadata["cwe"],
Severity: model.SeverityHigh,
QueryURI: SecretsQueryMetadata["descriptionUrl"],
Category: SecretsQueryMetadata["category"],
Expand Down
15 changes: 9 additions & 6 deletions pkg/engine/secrets/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,11 @@ var testNewInspectorInputs = []struct {
"severity": "HIGH",
"category": "Secret Management",
"descriptionText": "Query to find passwords and secrets in infrastructure code.",
"descriptionUrl": "https://kics.io/",
"descriptionUrl": "https://docs.kics.io/latest/secrets/",
"platform": "Common",
"descriptionID": "d69d8a89",
"cloudProvider": "common"
"cloudProvider": "common",
"cwe": "798"
}`,
disableSecrets: false,
wantRegLen: 1,
Expand All @@ -508,10 +509,11 @@ var testNewInspectorInputs = []struct {
"severity": "HIGH",
"category": "Secret Management",
"descriptionText": "Query to find passwords and secrets in infrastructure code.",
"descriptionUrl": "https://kics.io/",
"descriptionUrl": "https://docs.kics.io/latest/secrets/",
"platform": "Common",
"descriptionID": "d69d8a89",
"cloudProvider": "common"
"cloudProvider": "common",
"cwe": "798"
}`,
disableSecrets: true,
wantRegLen: 0,
Expand All @@ -538,10 +540,11 @@ var testNewInspectorInputs = []struct {
"severity": "HIGH",
"category": "Secret Management",
"descriptionText": "Query to find passwords and secrets in infrastructure code.",
"descriptionUrl": "https://kics.io/",
"descriptionUrl": "https://docs.kics.io/latest/secrets/",
"platform": "Common",
"descriptionID": "d69d8a89",
"cloudProvider": "common"
"cloudProvider": "common",
"cwe": "798"
}`,
disableSecrets: false,
wantRegLen: 1,
Expand Down

0 comments on commit f0cf78d

Please sign in to comment.