Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit c3ef51e

Browse files
authored
Disable suspicious commands for now (#1073)
* Disable suspicious commands for now Signed-off-by: nigel brown <[email protected]> * Use nonstandard quotes... Signed-off-by: nigel brown <[email protected]> * ruff check Signed-off-by: nigel brown <[email protected]> --------- Signed-off-by: nigel brown <[email protected]>
1 parent 490763b commit c3ef51e

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

src/codegate/pipeline/comment/output.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
)
1313
from codegate.pipeline.base import PipelineContext
1414
from codegate.pipeline.output import OutputPipelineContext, OutputPipelineStep
15-
from codegate.pipeline.suspicious_commands.suspicious_commands import SuspiciousCommands
15+
16+
# from codegate.pipeline.suspicious_commands.suspicious_commands import check_suspicious_code
1617
from codegate.storage import StorageEngine
1718
from codegate.utils.package_extractor import PackageExtractor
1819

@@ -51,24 +52,11 @@ def _create_chunk(self, original_chunk: ModelResponse, content: str) -> ModelRes
5152
async def _snippet_comment(self, snippet: CodeSnippet, context: PipelineContext) -> str:
5253
"""Create a comment for a snippet"""
5354
comment = ""
54-
sc = SuspiciousCommands.get_instance()
55-
class_, prob = await sc.classify_phrase(snippet.code)
56-
if class_ == 1:
57-
liklihood = "possibly"
58-
language = "code"
59-
if prob > 0.9:
60-
liklihood = "likely"
61-
if snippet.language is not None:
62-
language = snippet.language
63-
if language not in [
64-
"python",
65-
"javascript",
66-
"typescript",
67-
"go",
68-
"rust",
69-
"java",
70-
]: # noqa: E501
71-
comment = f"{comment}\n\n🛡️ CodeGate: The {language} supplied is {liklihood} unsafe. Please check carefully!\n\n" # noqa: E501
55+
56+
# Remove this for now. We need to find a better place for it.
57+
# comment, is_suspicious = await check_suspicious_code(snippet.code, snippet.language)
58+
# if is_suspicious:
59+
# comment += comment
7260

7361
snippet.libraries = PackageExtractor.extract_packages(snippet.code, snippet.language)
7462

src/codegate/pipeline/suspicious_commands/suspicious_commands.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,35 @@ async def classify_phrase(self, phrase, embeddings=None):
110110
prediction = np.argmax(ort_outs[0])
111111
probability = np.max(ort_outs[0])
112112
return prediction, probability
113+
114+
115+
async def check_suspicious_code(code, language=None):
116+
"""
117+
Check if the given code is suspicious and return a comment if it is.
118+
119+
Args:
120+
code (str): The code to check.
121+
language (str, optional): The language of the code.
122+
123+
Returns:
124+
tuple: A comment string and a boolean indicating if the code is suspicious.
125+
"""
126+
sc = SuspiciousCommands.get_instance()
127+
comment = ""
128+
class_, prob = await sc.classify_phrase(code)
129+
if class_ == 1:
130+
liklihood = "possibly"
131+
if prob > 0.9:
132+
liklihood = "likely"
133+
if language is None:
134+
language = "code"
135+
if language not in [
136+
"python",
137+
"javascript",
138+
"typescript",
139+
"go",
140+
"rust",
141+
"java",
142+
]:
143+
comment = f"{comment}\n\n🛡️ CodeGate: The {language} supplied is {liklihood} unsafe. Please check carefully!\n\n" # noqa: E501
144+
return comment, class_ == 1

0 commit comments

Comments
 (0)