Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tiatoolbox/visualization/tileserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def load_annotations(self: TileServer) -> str:
file_path,
np.array(model_mpp) / np.array(self.slide_mpps[session_id]),
)
tmp_path = Path(tempfile.gettempdir()) / "temp.db"
tmp_path = Path(tempfile.gettempdir()) / f"temp_{session_id}.db"
Copy link

Copilot AI May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that session_id is sanitized or validated before using it in the file name to prevent potential file path injection vulnerabilities.

Suggested change
tmp_path = Path(tempfile.gettempdir()) / f"temp_{session_id}.db"
sanitized_session_id = re.sub(r'[^a-zA-Z0-9_]', '_', session_id)
tmp_path = Path(tempfile.gettempdir()) / f"temp_{sanitized_session_id}.db"

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tiatoolbox code generates the session ID, so this is not a concern.

sq.dump(tmp_path)
sq = SQLiteStore(tmp_path)
self.pyramids[session_id]["overlay"] = AnnotationTileGenerator(
Expand Down Expand Up @@ -536,7 +536,7 @@ def change_overlay(self: TileServer) -> str:
sq = SQLiteStore(overlay_path, auto_commit=False)
else:
# make a temporary db for the new annotations
tmp_path = Path(tempfile.gettempdir()) / "temp.db"
tmp_path = Path(tempfile.gettempdir()) / f"temp_{session_id}.db"
Copy link

Copilot AI May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refactoring the logic for creating session-specific temporary file names into a helper function to avoid code duplication and potential inconsistencies in future modifications.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tiatoolbox code generates the session ID, so this is not a concern.

sq.dump(tmp_path)
sq = SQLiteStore(tmp_path)

Expand Down Expand Up @@ -621,7 +621,7 @@ def commit_db(self: TileServer) -> str:
if isinstance(layer, AnnotationTileGenerator):
if (
layer.store.path.suffix == ".db"
and layer.store.path.name != "temp.db"
and layer.store.path.name != f"temp_{session_id}.db"
):
logger.info("%s*.db committed.", layer.store.path.stem)
layer.store.commit()
Expand Down