Skip to content

Commit e18cc82

Browse files
Security bandit fixes
1 parent 531f64d commit e18cc82

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/mcp_optimizer/db/tool_response_ops.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def create_tool_response(
6161
created_at, expires_at, metadata)
6262
VALUES (:id, :session_key, :tool_name, :original_content, :content_type,
6363
:created_at, :expires_at, :metadata)
64-
"""
64+
""" # nosec B608 - TABLE_NAME is a code-controlled constant, not user input
6565

6666
params = {
6767
"id": response_id,
@@ -119,7 +119,7 @@ async def get_tool_response(
119119
created_at, expires_at, metadata
120120
FROM {self.TABLE_NAME}
121121
WHERE id = :id
122-
"""
122+
""" # nosec B608 - TABLE_NAME is a code-controlled constant, not user input
123123

124124
results = await self.db.execute_query(query, {"id": response_id}, conn=conn)
125125

@@ -168,7 +168,7 @@ async def get_responses_by_session(
168168
FROM {self.TABLE_NAME}
169169
WHERE session_key = :session_key AND expires_at > :now
170170
ORDER BY created_at DESC
171-
"""
171+
""" # nosec B608 - TABLE_NAME is a code-controlled constant, not user input
172172

173173
results = await self.db.execute_query(
174174
query, {"session_key": session_key, "now": now}, conn=conn
@@ -206,14 +206,14 @@ async def cleanup_expired(
206206
# First count how many will be deleted
207207
count_query = f"""
208208
SELECT COUNT(*) FROM {self.TABLE_NAME} WHERE expires_at <= :now
209-
"""
209+
""" # nosec B608 - TABLE_NAME is a code-controlled constant, not user input
210210
result = await self.db.execute_query(count_query, {"now": now}, conn=conn)
211211
count = result[0][0] if result else 0
212212

213213
# Then delete
214214
delete_query = f"""
215215
DELETE FROM {self.TABLE_NAME} WHERE expires_at <= :now
216-
"""
216+
""" # nosec B608 - TABLE_NAME is a code-controlled constant, not user input
217217
await self.db.execute_non_query(delete_query, {"now": now}, conn=conn)
218218

219219
if count > 0:
@@ -227,5 +227,5 @@ async def _delete_response(
227227
conn: AsyncConnection | None = None,
228228
) -> None:
229229
"""Delete a single response by ID."""
230-
query = f"DELETE FROM {self.TABLE_NAME} WHERE id = :id"
230+
query = f"DELETE FROM {self.TABLE_NAME} WHERE id = :id" # nosec B608
231231
await self.db.execute_non_query(query, {"id": response_id}, conn=conn)

src/mcp_optimizer/response_optimizer/query_executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
import shutil
5-
import subprocess
5+
import subprocess # nosec B404 - subprocess used for trusted jq tool only
66

77
from mcp_optimizer.response_optimizer.models import ContentType
88

@@ -37,7 +37,7 @@ def execute_jq_query(content: str, query: str) -> str:
3737
)
3838

3939
try:
40-
result = subprocess.run( # noqa: S603 - jq is a trusted tool
40+
result = subprocess.run( # noqa: S603 # nosec B603 - jq is a trusted tool, path validated
4141
[jq_path, query],
4242
input=content,
4343
capture_output=True,

src/mcp_optimizer/response_optimizer/summarizers/llmlingua.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def _load_model(self) -> bool:
8383
# Try to load from local path first, fall back to HuggingFace
8484
tokenizer_path = self.model_path
8585
if (tokenizer_path / "tokenizer_config.json").exists():
86-
self._tokenizer = AutoTokenizer.from_pretrained(str(tokenizer_path))
86+
self._tokenizer = AutoTokenizer.from_pretrained(str(tokenizer_path)) # nosec B615
8787
else:
8888
# Fall back to HuggingFace
89-
self._tokenizer = AutoTokenizer.from_pretrained(
89+
self._tokenizer = AutoTokenizer.from_pretrained( # nosec B615
9090
"microsoft/llmlingua-2-bert-base-multilingual-cased-meetingbank"
9191
)
9292

0 commit comments

Comments
 (0)