Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge dev #3755

Open
wants to merge 98 commits into
base: master
Choose a base branch
from
Open

merge dev #3755

wants to merge 98 commits into from

Conversation

vladmandic
Copy link
Owner

No description provided.

vladmandic and others added 30 commits February 5, 2025 17:07
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
vladmandic and others added 24 commits February 14, 2025 15:33
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
files += [f.name for f in batch_files]
if batch_folder is not None:
files += [f.name for f in batch_folder]
if batch_str is not None and len(batch_str) > 0 and os.path.exists(batch_str) and os.path.isdir(batch_str):

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix AI 1 day ago

To fix the problem, we need to validate the batch_str path to ensure it is within a safe root directory. This involves normalizing the path and checking that it starts with the intended base path. We will implement this validation in the batch function before using the batch_str variable.

  1. Define a safe root directory for the batch operations.
  2. Normalize the batch_str path using os.path.normpath.
  3. Check that the normalized path starts with the safe root directory.
  4. Raise an exception if the path validation fails.
Suggested changeset 1
modules/interrogate/vqa.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/interrogate/vqa.py b/modules/interrogate/vqa.py
--- a/modules/interrogate/vqa.py
+++ b/modules/interrogate/vqa.py
@@ -514,5 +514,9 @@
         files += [f.name for f in batch_folder]
-    if batch_str is not None and len(batch_str) > 0 and os.path.exists(batch_str) and os.path.isdir(batch_str):
+    if batch_str is not None and len(batch_str) > 0:
+        safe_root = '/server/static/images'  # Define a safe root directory
+        normalized_path = os.path.normpath(batch_str)
+        if not normalized_path.startswith(safe_root) or not os.path.exists(normalized_path) or not os.path.isdir(normalized_path):
+            raise Exception("Invalid batch_str path")
         from modules.files_cache import list_files
-        files += list(list_files(batch_str, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
+        files += list(list_files(normalized_path, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
     if len(files) == 0:
EOF
@@ -514,5 +514,9 @@
files += [f.name for f in batch_folder]
if batch_str is not None and len(batch_str) > 0 and os.path.exists(batch_str) and os.path.isdir(batch_str):
if batch_str is not None and len(batch_str) > 0:
safe_root = '/server/static/images' # Define a safe root directory
normalized_path = os.path.normpath(batch_str)
if not normalized_path.startswith(safe_root) or not os.path.exists(normalized_path) or not os.path.isdir(normalized_path):
raise Exception("Invalid batch_str path")
from modules.files_cache import list_files
files += list(list_files(batch_str, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
files += list(list_files(normalized_path, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
if len(files) == 0:
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
files += [f.name for f in batch_files]
if batch_folder is not None:
files += [f.name for f in batch_folder]
if batch_str is not None and len(batch_str) > 0 and os.path.exists(batch_str) and os.path.isdir(batch_str):

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.

Copilot Autofix AI 1 day ago

To fix the problem, we need to validate the batch_str path before using it. The best way to do this is to normalize the path using os.path.normpath and ensure it starts with a predefined safe root directory. This will prevent directory traversal attacks and ensure that the path is within the expected directory structure.

  1. Define a safe root directory.
  2. Normalize the batch_str path using os.path.normpath.
  3. Check if the normalized path starts with the safe root directory.
  4. If the path is not valid, raise an exception or handle the error appropriately.
Suggested changeset 1
modules/interrogate/vqa.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/interrogate/vqa.py b/modules/interrogate/vqa.py
--- a/modules/interrogate/vqa.py
+++ b/modules/interrogate/vqa.py
@@ -514,5 +514,10 @@
         files += [f.name for f in batch_folder]
-    if batch_str is not None and len(batch_str) > 0 and os.path.exists(batch_str) and os.path.isdir(batch_str):
-        from modules.files_cache import list_files
-        files += list(list_files(batch_str, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
+    if batch_str is not None and len(batch_str) > 0:
+        safe_root = '/server/static/images'  # Define your safe root directory
+        normalized_path = os.path.normpath(batch_str)
+        if not normalized_path.startswith(safe_root):
+            raise Exception("Invalid path")
+        if os.path.exists(normalized_path) and os.path.isdir(normalized_path):
+            from modules.files_cache import list_files
+            files += list(list_files(normalized_path, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
     if len(files) == 0:
EOF
@@ -514,5 +514,10 @@
files += [f.name for f in batch_folder]
if batch_str is not None and len(batch_str) > 0 and os.path.exists(batch_str) and os.path.isdir(batch_str):
from modules.files_cache import list_files
files += list(list_files(batch_str, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
if batch_str is not None and len(batch_str) > 0:
safe_root = '/server/static/images' # Define your safe root directory
normalized_path = os.path.normpath(batch_str)
if not normalized_path.startswith(safe_root):
raise Exception("Invalid path")
if os.path.exists(normalized_path) and os.path.isdir(normalized_path):
from modules.files_cache import list_files
files += list(list_files(normalized_path, ext_filter=['.png', '.jpg', '.jpeg', '.webp'], recursive=recursive))
if len(files) == 0:
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Signed-off-by: Vladimir Mandic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants