Skip to content

Commit

Permalink
Merge branch 'feature-ptai-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhukovAN committed Oct 18, 2024
2 parents 54ba34c + 48f19a5 commit 16acbaf
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.owasp.benchmarkutils.score.parsers.sarif.CodeQLReader;
import org.owasp.benchmarkutils.score.parsers.sarif.ContrastScanReader;
import org.owasp.benchmarkutils.score.parsers.sarif.DatadogSastReader;
import org.owasp.benchmarkutils.score.parsers.sarif.PTAIReader;
import org.owasp.benchmarkutils.score.parsers.sarif.PrecautionReader;
import org.owasp.benchmarkutils.score.parsers.sarif.SemgrepSarifReader;
import org.owasp.benchmarkutils.score.parsers.sarif.SnykReader;
Expand Down Expand Up @@ -89,6 +90,7 @@ public static List<Reader> allReaders() {
new ParasoftReader(),
new PrecautionReader(),
new PMDReader(),
new PTAIReader(),
new QualysWASReader(),
new Rapid7Reader(),
new ReshiftReader(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* OWASP Benchmark Project
*
* <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project For
* details, please see <a
* href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
*
* <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, version 2.
*
* <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* @author Alexey Zhukov
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers.sarif;

import org.owasp.benchmarkutils.score.CweNumber;

public class PTAIReader extends SarifReader {

static final int PTAI_CWE_EXTERNAL_FILEPATH_CONTROL = 73;
static final int PTAI_CWE_BLIND_XPATH_INJECTION = 91;

public PTAIReader() {
super("Positive Technologies Application Inspector", true, CweSourceType.FIELD);
}

@Override
public int mapCwe(int cwe) {
switch (cwe) {
case PTAI_CWE_EXTERNAL_FILEPATH_CONTROL:
return CweNumber.PATH_TRAVERSAL;
case PTAI_CWE_BLIND_XPATH_INJECTION:
return CweNumber.XPATH_INJECTION;
}
return cwe;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* OWASP Benchmark Project
*
* <p>This file is part of the Open Web Application Security Project (OWASP) Benchmark Project For
* details, please see <a
* href="https://owasp.org/www-project-benchmark/">https://owasp.org/www-project-benchmark/</a>.
*
* <p>The OWASP Benchmark is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation, version 2.
*
* <p>The OWASP Benchmark is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* @author Alexey Zhukov
* @created 2024
*/
package org.owasp.benchmarkutils.score.parsers.sarif;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.owasp.benchmarkutils.score.*;
import org.owasp.benchmarkutils.score.parsers.ReaderTestBase;

public class PTAIReaderTest extends ReaderTestBase {

private ResultFile resultFile;

@BeforeEach
void setUp() {
resultFile = TestHelper.resultFileOf("testfiles/Benchmark_PTAI-v4.7.2.sarif");
BenchmarkScore.TESTCASENAME = "BenchmarkTest";
}

@Test
public void onlyPTAIReaderTestReportsCanReadAsTrue() {
assertOnlyMatcherClassIs(this.resultFile, PTAIReader.class);
}

@Test
void readerHandlesGivenResultFile() throws Exception {
PTAIReader reader = new PTAIReader();
TestSuiteResults result = reader.parse(resultFile);

assertEquals(TestSuiteResults.ToolType.SAST, result.getToolType());

assertEquals("Positive Technologies Application Inspector", result.getToolName());
assertEquals("4.7.2.36549", result.getToolVersion());

assertEquals(2, result.getTotalResults());

assertEquals(CweNumber.PATH_TRAVERSAL, result.get(1).get(0).getCWE());
assertEquals(CweNumber.SQL_INJECTION, result.get(8).get(0).getCWE());
}
}
104 changes: 104 additions & 0 deletions plugin/src/test/resources/testfiles/Benchmark_PTAI-v4.7.2.sarif
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"version": "2.1.0",
"$schema": "http://json.schemastore.org/sarif-2.1.0.json",
"runs": [
{
"tool": {
"driver": {
"name": "Positive Technologies Application Inspector",
"version": "4.7.2.36549",
"organization": "Positive Technologies",
"informationUri": "https://www.ptsecurity.com/ww-en/products/ai/",
"rules": [
{
"id": "SQL Injection",
"name": "SQL Injection",
"properties": {
"cwe": [
"CWE-89"
]
},
"defaultConfiguration": {
"level": "error",
"enabled": true
},
"messageStrings": {
"default": {
"text": "SQL Injection"
}
}
},
{
"id": "Arbitrary File Reading",
"name": "Arbitrary File Reading",
"properties": {
"cwe": [
"CWE-73"
]
},
"defaultConfiguration": {
"level": "error",
"enabled": true
},
"messageStrings": {
"default": {
"text": "Arbitrary File Reading"
}
}
}
]
}
},
"results": [
{
"ruleId": "Arbitrary File Reading",
"suppressions": [
],
"message": {
"id": "default",
"text": "Arbitrary File Reading"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "./src/main/java/org/owasp/benchmark/testcode/BenchmarkTest00001.java"
},
"region": {
"startLine": 71,
"snippet": {
"text": "new java.io.FileInputStream(new java.io.File(fileName))"
}
}
}
}
]
},
{
"ruleId": "SQL Injection",
"suppressions": [
],
"message": {
"id": "default",
"text": "SQL Injection"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "./src/main/java/org/owasp/benchmark/testcode/BenchmarkTest00008.java"
},
"region": {
"startLine": 57,
"snippet": {
"text": "connection.prepareCall(sql)"
}
}
}
}
]
}
]
}
]
}

0 comments on commit 16acbaf

Please sign in to comment.