Skip to content

Commit 0b45990

Browse files
authored
upload all filepaths referenced for checkmarx reports (#60)
* upload all filepaths referenced for checkmarx reports * bump version
1 parent df064ea commit 0b45990

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "corgea"
3-
version = "1.7.0"
3+
version = "1.7.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/scanners/parsers/checkmarx.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ pub struct CheckmarxCliParser;
99
impl ScanParser for CheckmarxCliParser {
1010
fn detect(&self, input: &str) -> bool {
1111
if let Ok(data) = serde_json::from_str::<Value>(input) {
12-
data.get("totalCount").is_some()
13-
&& data.get("results").is_some()
12+
data.get("totalCount").is_some()
13+
&& data.get("results").is_some()
1414
&& data.get("scanID").is_some()
1515
} else {
1616
false
1717
}
1818
}
19-
19+
2020
fn parse(&self, input: &str) -> Option<ParseResult> {
2121
debug("Detected checkmarx cli schema");
22-
22+
2323
let data: Value = match serde_json::from_str(input) {
2424
Ok(data) => data,
2525
Err(_) => return None,
2626
};
27-
27+
2828
let mut paths = Vec::new();
2929
if let Some(results) = data.get("results").and_then(|v| v.as_array()) {
3030
for result in results {
@@ -41,13 +41,13 @@ impl ScanParser for CheckmarxCliParser {
4141
}
4242
}
4343
}
44-
44+
4545
Some(ParseResult {
4646
paths,
4747
scanner: "checkmarx".to_string(),
4848
})
4949
}
50-
50+
5151
fn scanner_name(&self) -> &str {
5252
"checkmarx-cli"
5353
}
@@ -63,15 +63,15 @@ impl ScanParser for CheckmarxWebParser {
6363
false
6464
}
6565
}
66-
66+
6767
fn parse(&self, input: &str) -> Option<ParseResult> {
6868
debug("Detected checkmarx web schema");
69-
69+
7070
let data: Value = match serde_json::from_str(input) {
7171
Ok(data) => data,
7272
Err(_) => return None,
7373
};
74-
74+
7575
let mut paths = Vec::new();
7676
if let Some(scan_results) = data.get("scanResults") {
7777
if let Some(sast) = scan_results.get("sast") {
@@ -98,13 +98,13 @@ impl ScanParser for CheckmarxWebParser {
9898
}
9999
}
100100
}
101-
101+
102102
Some(ParseResult {
103103
paths,
104104
scanner: "checkmarx".to_string(),
105105
})
106106
}
107-
107+
108108
fn scanner_name(&self) -> &str {
109109
"checkmarx-web"
110110
}
@@ -117,9 +117,9 @@ impl CheckmarxXmlParser {
117117
debug("Detected checkmarx xml schema");
118118
let mut paths = Vec::new();
119119
let mut reader = Reader::from_str(input);
120-
120+
121121
let mut buf = Vec::new();
122-
122+
123123
loop {
124124
match reader.read_event_into(&mut buf) {
125125
Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e)) => {
@@ -136,6 +136,15 @@ impl CheckmarxXmlParser {
136136
}
137137
}
138138
}
139+
} else if e.name().as_ref() == b"FileName" {
140+
if let Ok(Event::Text(text)) = reader.read_event_into(&mut buf) {
141+
if let Ok(file_name) = std::str::from_utf8(text.as_ref()) {
142+
let clean_path = file_name.trim_start_matches('/').trim_start_matches('\\');
143+
if !clean_path.is_empty() {
144+
paths.push(clean_path.to_string());
145+
}
146+
}
147+
}
139148
}
140149
}
141150
Ok(Event::Eof) => break,
@@ -147,7 +156,7 @@ impl CheckmarxXmlParser {
147156
}
148157
buf.clear();
149158
}
150-
159+
151160
Some(ParseResult {
152161
paths,
153162
scanner: "checkmarx".to_string(),
@@ -159,14 +168,12 @@ impl ScanParser for CheckmarxXmlParser {
159168
fn detect(&self, input: &str) -> bool {
160169
input.trim().starts_with("<?xml") && input.contains("<CxXMLResults")
161170
}
162-
171+
163172
fn parse(&self, input: &str) -> Option<ParseResult> {
164173
self.parse_xml_content(input)
165174
}
166-
175+
167176
fn scanner_name(&self) -> &str {
168177
"checkmarx-xml"
169178
}
170179
}
171-
172-

0 commit comments

Comments
 (0)