Skip to content

Commit

Permalink
feat: Reduce level for Bandit and fix code to adapt (#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbyte authored Nov 14, 2024
1 parent 4ca785e commit 9285ebf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/security-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
run: pip install bandit

- name: Run Bandit
run: bandit -c pyproject.toml -r src/ -lll
run: bandit -c pyproject.toml -r src/ -ll

6 changes: 4 additions & 2 deletions src/crewai/cli/authentication/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def _get_device_code(self) -> Dict[str, Any]:
"scope": "openid",
"audience": AUTH0_AUDIENCE,
}
response = requests.post(url=self.DEVICE_CODE_URL, data=device_code_payload)
response = requests.post(
url=self.DEVICE_CODE_URL, data=device_code_payload, timeout=20
)
response.raise_for_status()
return response.json()

Expand All @@ -54,7 +56,7 @@ def _poll_for_token(self, device_code_data: Dict[str, Any]) -> None:

attempts = 0
while True and attempts < 5:
response = requests.post(self.TOKEN_URL, data=token_payload)
response = requests.post(self.TOKEN_URL, data=token_payload, timeout=30)
token_data = response.json()

if response.status_code == 200:
Expand Down
2 changes: 1 addition & 1 deletion src/crewai/memory/storage/kickoff_task_outputs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def update(
else value
)

query = f"UPDATE latest_kickoff_task_outputs SET {', '.join(fields)} WHERE task_index = ?"
query = f"UPDATE latest_kickoff_task_outputs SET {', '.join(fields)} WHERE task_index = ?" # nosec
values.append(task_index)

cursor.execute(query, tuple(values))
Expand Down
2 changes: 1 addition & 1 deletion src/crewai/memory/storage/ltm_sqlite_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def load(
WHERE task_description = ?
ORDER BY datetime DESC, score ASC
LIMIT {latest_n}
""",
""", # nosec
(task_description,),
)
rows = cursor.fetchall()
Expand Down
8 changes: 6 additions & 2 deletions src/crewai/utilities/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def __init__(self, file_path):

def log(self, **kwargs):
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = f"{now}: " + ", ".join([f"{key}=\"{value}\"" for key, value in kwargs.items()]) + "\n"
message = (
f"{now}: "
+ ", ".join([f'{key}="{value}"' for key, value in kwargs.items()])
+ "\n"
)
with open(self._path, "a", encoding="utf-8") as file:
file.write(message + "\n")

Expand Down Expand Up @@ -63,7 +67,7 @@ def load(self) -> dict:

with open(self.file_path, "rb") as file:
try:
return pickle.load(file)
return pickle.load(file) # nosec
except EOFError:
return {} # Return an empty dictionary if the file is empty or corrupted
except Exception:
Expand Down

0 comments on commit 9285ebf

Please sign in to comment.