Skip to content

Commit 16920bc

Browse files
authored
Merge pull request #45 from OPPIDA/feat/sast-extra-lang
2 parents 03514c6 + 9007c2b commit 16920bc

14 files changed

Lines changed: 679 additions & 528 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ For more details on the design and integration of SAST tools and datasets in Cod
6262
|SpotBugs|Java||||[Latest PR](https://github.com/OPPIDA/CodeSecTools/actions/workflows/ci.yaml)|
6363
|Cppcheck|C/C++||||[Latest PR](https://github.com/OPPIDA/CodeSecTools/actions/workflows/ci.yaml)|
6464

65+
Languages supported by the SAST tool are also available, but they are not actively maintained (some features are disabled).
66+
6567
## Usage
6668

6769
### Running the Tool

codesectools/sasts/all/report/HTML.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class HTMLReport(Report):
5757
<body>
5858
<a href="./home.html"><h1>CodeSecTools All SAST Tools Report</h1></a>
5959
<h3>SAST Tools used: [sasts]</h3>
60-
<h2>[name]</h2>
60+
<h2>[cstools-name]</h2>
6161
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code style="font-family:inherit">{code}</code></pre>
6262
<script src="https://unpkg.com/@popperjs/core@2"></script>
6363
<script src="https://unpkg.com/tippy.js@6"></script>
64-
<script>[tippy_calls]</script>
64+
<script>[cstools-tippy_calls]</script>
6565
<a href="#" id="top">^</a>
6666
</body>
6767
</html>
@@ -164,12 +164,12 @@ def generate_single_defect(self, defect_file: dict) -> str:
164164
html_content = file_page.export_html(code_format=self.TEMPLATE)
165165
html_content = html_content.replace('href="HACK', 'id="')
166166
html_content = html_content.replace(
167-
"[name]",
167+
"[cstools-name]",
168168
str(
169169
Path(defect_file["source_path"]).relative_to(self.result.source_path) # ty:ignore[no-matching-overload]
170170
),
171171
)
172-
html_content = html_content.replace("[tippy_calls]", tippy_calls)
172+
html_content = html_content.replace("[cstools-tippy_calls]", tippy_calls)
173173

174174
return html_content
175175

@@ -218,7 +218,7 @@ def generate(self) -> None:
218218
home_page.print(main_table)
219219
html_content = home_page.export_html(code_format=self.TEMPLATE)
220220
html_content = html_content.replace(
221-
"[name]", f"Project: {self.result.source_path}"
221+
"[cstools-name]", f"Project: {self.result.source_path}"
222222
)
223223

224224
report_home_file = self.report_dir / "home.html"

codesectools/sasts/all/sast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self) -> None:
3737
self.sasts_by_dataset = {}
3838

3939
for sast in self.full_sasts:
40-
for lang in sast.supported_languages:
40+
for lang in sast.supported_languages + sast.extra_languages:
4141
if self.sasts_by_lang.get(lang):
4242
self.sasts_by_lang[lang].append(sast)
4343
else:

codesectools/sasts/core/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ def analyze(
160160
lang: Annotated[
161161
str,
162162
typer.Argument(
163-
click_type=Choice(self.sast.supported_languages),
163+
click_type=Choice(
164+
self.sast.supported_languages + self.sast.extra_languages
165+
),
164166
help="Source code language (only one at the time)",
165167
metavar="LANG",
166168
),

codesectools/sasts/core/parser/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from abc import ABC, abstractmethod
1010
from pathlib import Path
1111
from typing import Literal, Self
12+
from urllib.parse import unquote
1213

1314
from codesectools.shared.cwe import CWE
1415

@@ -52,6 +53,8 @@ def __init__(
5253
lines: A list of line numbers where the defect is located.
5354
5455
"""
56+
# URL decode
57+
filepath = Path(unquote(str(filepath)))
5558
if not filepath.is_file():
5659
raise FileNotFoundError(filepath.resolve())
5760
self.filepath = filepath

codesectools/sasts/core/sast/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AnalysisInfo(BaseModel):
4444
project_dir: The absolute path to the project directory that was analyzed.
4545
lang: The programming language of the project.
4646
command_lines: The command lines that were executed for the analysis.
47+
logs: The logs generated during the analysis.
4748
duration: The duration of the analysis in seconds.
4849
lines_of_codes: The number of lines of code in the project for the given language.
4950
@@ -66,6 +67,7 @@ class SAST(ABC):
6667
Attributes:
6768
name (str): The name of the SAST tool.
6869
supported_languages (list[str]): A list of supported programming languages.
70+
extra_languages (list[str]): Languages supported by the tool itself but not codesectools.
6971
supported_dataset_names (list[str]): Names of compatible datasets.
7072
supported_datasets (list[Dataset]): A list of supported dataset classes.
7173
properties (SASTProperties): The properties of the SAST tool.
@@ -89,6 +91,7 @@ class SAST(ABC):
8991

9092
name: str
9193
supported_languages: list[str]
94+
extra_languages: list[str] = []
9295
supported_dataset_names: list[str]
9396
supported_datasets: list[Dataset]
9497
properties: SASTProperties

codesectools/sasts/tools/Bearer/sast.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class BearerSAST(BuildlessSAST):
2525
Attributes:
2626
name (str): The name of the SAST tool.
2727
supported_languages (list[str]): A list of supported programming languages.
28+
extra_languages (list[str]): Languages supported by the tool itself but not codesectools.
2829
supported_dataset_names (list[str]): A list of names of compatible datasets.
2930
properties (SASTProperties): The properties of the SAST tool.
3031
requirements (SASTRequirements): The requirements for the SAST tool.
@@ -39,6 +40,7 @@ class BearerSAST(BuildlessSAST):
3940

4041
name = "Bearer"
4142
supported_languages = ["java"]
43+
extra_languages = ["go", "javascript", "php", "python", "ruby"]
4244
supported_dataset_names = ["BenchmarkJava", "CVEfixes"]
4345
properties = SASTProperties(free=True, offline=True)
4446
requirements = SASTRequirements(

codesectools/sasts/tools/Coverity/sast.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CoveritySAST(BuildlessSAST):
2020
Attributes:
2121
name (str): The name of the SAST tool.
2222
supported_languages (list[str]): A list of supported programming languages.
23+
extra_languages (list[str]): Languages supported by the tool itself but not codesectools.
2324
supported_dataset_names (list[str]): A list of names of compatible datasets.
2425
properties (SASTProperties): The properties of the SAST tool.
2526
requirements (SASTRequirements): The requirements for the SAST tool.
@@ -33,6 +34,20 @@ class CoveritySAST(BuildlessSAST):
3334

3435
name = "Coverity"
3536
supported_languages = ["c", "java"]
37+
extra_languages = [
38+
"csharp",
39+
"dart",
40+
"go",
41+
"javascript",
42+
"kotlin",
43+
"objective-c",
44+
"php",
45+
"python",
46+
"ruby",
47+
"apex",
48+
"swift",
49+
"typescript",
50+
]
3651
supported_dataset_names = ["BenchmarkJava", "CVEfixes"]
3752
properties = SASTProperties(free=False, offline=True)
3853
requirements = SASTRequirements(

codesectools/sasts/tools/SemgrepCE/sast.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class SemgrepCESAST(BuildlessSAST):
2525
Attributes:
2626
name (str): The name of the SAST tool.
2727
supported_languages (list[str]): A list of supported programming languages.
28+
extra_languages (list[str]): Languages supported by the tool itself but not codesectools.
2829
supported_dataset_names (list[str]): A list of names of compatible datasets.
2930
properties (SASTProperties): The properties of the SAST tool.
3031
requirements (SASTRequirements): The requirements for the SAST tool.
@@ -38,6 +39,20 @@ class SemgrepCESAST(BuildlessSAST):
3839

3940
name = "SemgrepCE"
4041
supported_languages = ["java", "c"]
42+
extra_languages = [
43+
"csharp",
44+
"go",
45+
"javascript",
46+
"kotlin",
47+
"python",
48+
"typescript",
49+
"jsx",
50+
"ruby",
51+
"scala",
52+
"swift",
53+
"rust",
54+
"php",
55+
]
4156
supported_dataset_names = ["BenchmarkJava", "CVEfixes", "JulietTestSuiteC"]
4257
properties = SASTProperties(free=True, offline=True)
4358
requirements = SASTRequirements(

codesectools/sasts/tools/SnykCode/sast.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SnykCodeSAST(BuildlessSAST):
1919
Attributes:
2020
name (str): The name of the SAST tool.
2121
supported_languages (list[str]): A list of supported programming languages.
22+
extra_languages (list[str]): Languages supported by the tool itself but not codesectools.
2223
supported_dataset_names (list[str]): A list of names of compatible datasets.
2324
properties (SASTProperties): The properties of the SAST tool.
2425
requirements (SASTRequirements): The requirements for the SAST tool.
@@ -32,6 +33,25 @@ class SnykCodeSAST(BuildlessSAST):
3233

3334
name = "SnykCode"
3435
supported_languages = ["java", "c"]
36+
extra_languages = [
37+
"apex",
38+
"dart",
39+
"elixir",
40+
"go",
41+
"groovy",
42+
"java",
43+
"kotlin",
44+
"javascript",
45+
"csharp",
46+
"php",
47+
"python",
48+
"ruby",
49+
"rust",
50+
"scala",
51+
"swift",
52+
"objective-c",
53+
"typescript",
54+
]
3555
supported_dataset_names = ["BenchmarkJava", "CVEfixes", "JulietTestSuiteC"]
3656
properties = SASTProperties(free=False, offline=False)
3757
requirements = SASTRequirements(

0 commit comments

Comments
 (0)