Skip to content

Commit

Permalink
bugfix: Added additional checks when saving/deleting histories.
Browse files Browse the repository at this point in the history
  • Loading branch information
GaiZhenbiao committed Sep 18, 2024
1 parent 226a9b2 commit 526c615
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,10 @@ def delete_chat_history(self, filename):
else:
history_file_path = filename
md_history_file_path = history_file_path[:-5] + ".md"
# check if history file path matches user_name
# if user access control is not enabled, user_name is empty, don't check
assert os.path.dirname(history_file_path) == self.user_name or self.user_name == ""
assert os.path.dirname(md_history_file_path) == self.user_name or self.user_name == ""
try:
os.remove(history_file_path)
os.remove(md_history_file_path)
Expand Down
3 changes: 3 additions & 0 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ def save_file(filename, model, chatbot):
else:
history_file_path = os.path.join(HISTORY_DIR, user_name, filename)

# check if history file path matches user_name
# if user access control is not enabled, user_name is empty, don't check
assert os.path.dirname(history_file_path) == model.user_name or model.user_name == ""
with open(history_file_path, "w", encoding="utf-8") as f:
json.dump(json_s, f, ensure_ascii=False, indent=4)

Expand Down

0 comments on commit 526c615

Please sign in to comment.