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

Commit 189d790

Browse files
committed
start addign code snippets
1 parent 0081e69 commit 189d790

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/codegate/pipeline/secrets/secrets.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from codegate.config import Config
1010
from codegate.pipeline.base import (
1111
AlertSeverity,
12+
CodeSnippet,
1213
PipelineContext,
1314
PipelineResult,
1415
PipelineStep,
@@ -44,7 +45,7 @@ def _hide_secret(self, match: Match) -> str:
4445
pass
4546

4647
@abstractmethod
47-
def _notify_secret(self, match: Match, protected_text: List[str]) -> None:
48+
def _notify_secret(self, match: Match, code_snippet: Optional[CodeSnippet], protected_text: List[str]) -> None:
4849
"""
4950
Notify about a found secret
5051
TODO: If the secret came from a CodeSnippet we should notify about that. This would
@@ -185,11 +186,23 @@ def _hide_secret(self, match: Match) -> str:
185186
)
186187
return f"REDACTED<${encrypted_value}>"
187188

188-
def _notify_secret(self, match: Match, protected_text: List[str]) -> None:
189+
def _notify_secret(
190+
self, match: Match, code_snippet: Optional[CodeSnippet], protected_text: List[str]
191+
) -> None:
189192
secret_lines = self._get_surrounding_secret_lines(protected_text, match.line_number)
190-
notify_string = f"{match.service} - {match.type}:\n{secret_lines}"
193+
notify_string = (
194+
f"**Secret Detected** 🔒\n"
195+
f"- Service: {match.service}\n"
196+
f"- Type: {match.type}\n"
197+
f"- Key: {match.key if match.key else '(Unknown)'}\n"
198+
f"- Line Number: {match.line_number}\n"
199+
f"- Context:\n```\n{secret_lines}\n```"
200+
)
191201
self._context.add_alert(
192-
self._name, trigger_string=notify_string, severity_category=AlertSeverity.CRITICAL
202+
self._name,
203+
trigger_string=notify_string,
204+
severity_category=AlertSeverity.CRITICAL,
205+
code_snippet=code_snippet,
193206
)
194207

195208

@@ -206,7 +219,7 @@ def _hide_secret(self, match: Match) -> str:
206219
"""
207220
return "*" * 32
208221

209-
def _notify_secret(self, match: Match, protected_text: List[str]) -> None:
222+
def _notify_secret(self, match: Match, code_snippet: Optional[CodeSnippet], protected_text: List[str]) -> None:
210223
pass
211224

212225

@@ -282,6 +295,9 @@ async def process(
282295
# Process all messages
283296
for i, message in enumerate(new_request["messages"]):
284297
if "content" in message and message["content"]:
298+
# check if we can extract snippets from the text
299+
#snippets = extract_snippets(user_message)
300+
285301
# Protect the text
286302
protected_string, secrets_matched = self._redact_text(
287303
str(message["content"]), secrets_manager, session_id, context

0 commit comments

Comments
 (0)