Search in sources :

Example 16 with SerecoCodeCallStackElement

use of com.mercedesbenz.sechub.sereco.metadata.SerecoCodeCallStackElement in project sechub by mercedes-benz.

the class SerecoFalsePositiveCodeScanStrategy method isFalsePositive.

/**
 * Checks if given vulnerability is identified as false positive by given meta
 * data
 *
 * @param vulnerability
 * @param metaData
 * @return <code>true</code> when identified as false positive
 */
public boolean isFalsePositive(SerecoVulnerability vulnerability, FalsePositiveMetaData metaData) {
    notNull(vulnerability, " vulnerability may not be null");
    notNull(metaData, " metaData may not be null");
    /* check supported scan type */
    if (metaData.getScanType() != ScanType.CODE_SCAN) {
        return false;
    }
    if (vulnerability.getScanType() != ScanType.CODE_SCAN) {
        return false;
    }
    FalsePositiveCodeMetaData metaDataCode = metaData.getCode();
    if (metaDataCode == null) {
        LOG.error("Cannot check code vulnerability for false positives when meta data has no code parts!");
        return false;
    }
    /* ---------------------------------------------------- */
    /* -------------------CWE ID--------------------------- */
    /* ---------------------------------------------------- */
    /* for code scans we only use CWE as wellknown common identifier */
    Integer cweId = metaData.getCweId();
    if (cweId == null) {
        LOG.error("Cannot check code vulnerability for false positives when code meta data has no CWE id set!");
        return false;
    }
    SerecoClassification serecoClassification = vulnerability.getClassification();
    String serecoCWE = serecoClassification.getCwe();
    if (serecoCWE == null || serecoCWE.isEmpty()) {
        LOG.error("Code scan sereco vulnerability type:{} found without CWE! Cannot determin false positive! Classification was:{}", vulnerability.getType(), serecoClassification);
        return false;
    }
    try {
        int serecoCWEint = Integer.parseInt(serecoCWE);
        if (cweId.intValue() != serecoCWEint) {
            /* not same type of common vulnerability enumeration - so skip */
            return false;
        }
    } catch (NumberFormatException e) {
        LOG.error("Code scan sereco vulnerability type:{} found CWE:{} but not expected integer format!", vulnerability.getType(), serecoCWE);
        return false;
    }
    /* ------------------------------------------------------- */
    /* -------------------Location---------------------------- */
    /* ------------------------------------------------------- */
    SerecoCodeCallStackElement serecoFirstElement = vulnerability.getCode();
    if (serecoFirstElement == null) {
        /* strange - canot be investigated */
        LOG.warn("Cannot check code vulnerability for false positives when no first code element is found!");
        return false;
    }
    FalsePositiveCodePartMetaData start = metaDataCode.getStart();
    if (start == null) {
        LOG.warn("Cannot check code vulnerability for false positives when no start code meta data is found!");
        return false;
    }
    if (isLocationDifferent(start, serecoFirstElement)) {
        return false;
    }
    FalsePositiveCodePartMetaData end = metaDataCode.getEnd();
    SerecoCodeCallStackElement serecoLastElement = findLastElement(serecoFirstElement);
    if (isLocationDifferent(end, serecoLastElement)) {
        return false;
    }
    /* ------------------------------------------------------- */
    /* -------------------Relevant parts---------------------- */
    /* ------------------------------------------------------- */
    String relevant1 = start.getRelevantPart();
    String relevant2 = serecoFirstElement.getRelevantPart();
    if (relevant1 == null || relevant1.isEmpty()) {
        relevant1 = createRelevantReplacment(start);
    }
    if (relevant2 == null || relevant2.isEmpty()) {
        relevant2 = createRelevantReplacment(serecoFirstElement);
    }
    if (!relevant1.equals(relevant2)) {
        return false;
    }
    String relevant3 = "";
    String relevant4 = "";
    if (end != null) {
        relevant3 = end.getRelevantPart();
        if (relevant3 == null || relevant3.isEmpty()) {
            relevant3 = createRelevantReplacment(end);
        }
    }
    if (serecoLastElement != null) {
        relevant4 = serecoLastElement.getRelevantPart();
        if (relevant4 == null || relevant4.isEmpty()) {
            relevant4 = createRelevantReplacment(serecoLastElement);
        }
    }
    if (!relevant3.equals(relevant4)) {
        return false;
    }
    return true;
}
Also used : SerecoCodeCallStackElement(com.mercedesbenz.sechub.sereco.metadata.SerecoCodeCallStackElement) FalsePositiveCodeMetaData(com.mercedesbenz.sechub.domain.scan.project.FalsePositiveCodeMetaData) SerecoClassification(com.mercedesbenz.sechub.sereco.metadata.SerecoClassification) FalsePositiveCodePartMetaData(com.mercedesbenz.sechub.domain.scan.project.FalsePositiveCodePartMetaData)

Example 17 with SerecoCodeCallStackElement

use of com.mercedesbenz.sechub.sereco.metadata.SerecoCodeCallStackElement in project sechub by mercedes-benz.

the class TestSerecoVulnerabilityBuilder method codeScan.

public SerecoCodeScanVulnerability codeScan() {
    vulnerability.setScanType(ScanType.CODE_SCAN);
    SerecoCodeCallStackElement element1 = new SerecoCodeCallStackElement();
    vulnerability.setCode(element1);
    return new SerecoCodeScanVulnerability(element1);
}
Also used : SerecoCodeCallStackElement(com.mercedesbenz.sechub.sereco.metadata.SerecoCodeCallStackElement)

Aggregations

SerecoCodeCallStackElement (com.mercedesbenz.sechub.sereco.metadata.SerecoCodeCallStackElement)17 SerecoVulnerability (com.mercedesbenz.sechub.sereco.metadata.SerecoVulnerability)8 SerecoMetaData (com.mercedesbenz.sechub.sereco.metadata.SerecoMetaData)7 Element (org.dom4j.Element)4 ArrayList (java.util.ArrayList)3 ArtifactContent (com.mercedesbenz.sechub.sarif.model.ArtifactContent)2 ArtifactLocation (com.mercedesbenz.sechub.sarif.model.ArtifactLocation)2 PhysicalLocation (com.mercedesbenz.sechub.sarif.model.PhysicalLocation)2 Region (com.mercedesbenz.sechub.sarif.model.Region)2 SerecoClassification (com.mercedesbenz.sechub.sereco.metadata.SerecoClassification)2 SerecoWeb (com.mercedesbenz.sechub.sereco.metadata.SerecoWeb)2 SerecoWebAttack (com.mercedesbenz.sechub.sereco.metadata.SerecoWebAttack)2 SerecoWebRequest (com.mercedesbenz.sechub.sereco.metadata.SerecoWebRequest)2 SerecoWebResponse (com.mercedesbenz.sechub.sereco.metadata.SerecoWebResponse)2 IOException (java.io.IOException)2 List (java.util.List)2 SimpleStringUtils (com.mercedesbenz.sechub.commons.core.util.SimpleStringUtils)1 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 FalsePositiveCodeMetaData (com.mercedesbenz.sechub.domain.scan.project.FalsePositiveCodeMetaData)1 FalsePositiveCodePartMetaData (com.mercedesbenz.sechub.domain.scan.project.FalsePositiveCodePartMetaData)1