forked from mercedes-benz/sechub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Obfuscate secret scan findings in reports (mercedes-benz#2999)
Added obfuscate method to obfuscate secret scan findings in reports
- Loading branch information
1 parent
39c7cb4
commit 7fe6a04
Showing
9 changed files
with
317 additions
and
16 deletions.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
...in/java/com/mercedesbenz/sechub/domain/scan/report/ScanReportSensitiveDataObfuscator.java
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,65 @@ | ||
package com.mercedesbenz.sechub.domain.scan.report; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.mercedesbenz.sechub.commons.core.util.SimpleStringUtils; | ||
import com.mercedesbenz.sechub.commons.model.ScanType; | ||
import com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack; | ||
import com.mercedesbenz.sechub.commons.model.SecHubFinding; | ||
import com.mercedesbenz.sechub.sharedkernel.MustBeDocumented; | ||
|
||
@Component | ||
public class ScanReportSensitiveDataObfuscator { | ||
|
||
@Value("${sechub.report.sensitivedata.max.nonobfuscated.characters:0}") | ||
@MustBeDocumented("Define the amount of visible characters which are NOT obfuscated.") | ||
int sourceVisibleLength; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ScanReportSensitiveDataObfuscator.class); | ||
|
||
/** | ||
* Obfuscates sensitive scan report data | ||
* | ||
* @param report the report to obfuscate | ||
*/ | ||
public void obfuscate(ScanSecHubReport report) { | ||
|
||
if (report == null) { | ||
return; | ||
} | ||
|
||
/* result and findings are not null */ | ||
List<SecHubFinding> findings = report.getResult().getFindings(); | ||
|
||
for (SecHubFinding finding : findings) { | ||
/* obfuscates secrets from secret scan */ | ||
if (ScanType.SECRET_SCAN.equals(finding.getType())) { | ||
SecHubCodeCallStack code = finding.getCode(); | ||
if (code == null) { | ||
LOG.debug("Could not obfuscate secret: codeCallstack was null"); | ||
continue; | ||
} | ||
|
||
String secret = code.getSource(); | ||
if (secret == null) { | ||
LOG.debug("Could not obfuscate secret: code source was null"); | ||
continue; | ||
} | ||
|
||
String obfuscated = SimpleStringUtils.createObfuscatedString(secret, sourceVisibleLength); | ||
if (obfuscated == null) { | ||
LOG.debug("Could not obfuscate secret: obfuscated string was null"); | ||
continue; | ||
} | ||
code.setSource(obfuscated); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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
Oops, something went wrong.