Skip to content
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

fix(query): fix CWE field not appearing in KICS CLI and sarif reports #7207

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading