-
Notifications
You must be signed in to change notification settings - Fork 0
Fix security vulnerabilities, register missing blueprint, and clean up codebase issues #2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,21 @@ | ||
| import os | ||
| import warnings | ||
|
|
||
| class Config: | ||
| SECRET_KEY = os.urandom(24) | ||
| SQLALCHEMY_DATABASE_URI = 'sqlite:///fileflow.db' | ||
| # SECRET_KEY should be set via environment variable in production | ||
| # A random fallback is used only for development; this will invalidate | ||
| # sessions on every restart | ||
| SECRET_KEY = os.environ.get('SECRET_KEY') | ||
| if not SECRET_KEY: | ||
| warnings.warn( | ||
| "SECRET_KEY not set in environment. Using random key. " | ||
| "Sessions will be invalidated on restart. " | ||
| "Set SECRET_KEY environment variable for production use.", | ||
| RuntimeWarning | ||
| ) | ||
| SECRET_KEY = os.urandom(24) | ||
|
|
||
| SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'sqlite:///fileflow.db' | ||
| SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
| UPLOAD_FOLDER = 'user_files' | ||
| MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB max file upload | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,44 @@ | |||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class CompressionService: | ||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||
| def _is_safe_path(base_path, target_path): | ||||||||||||||||||||||||||||||
| """Check if target path is within base path (prevents directory traversal) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Note: This validates the path string without resolving symlinks to prevent | ||||||||||||||||||||||||||||||
| symlink-based attacks. The check uses string comparison after normalization. | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||
| base = Path(base_path).resolve() | ||||||||||||||||||||||||||||||
| # Normalize target without fully resolving to prevent symlink attacks | ||||||||||||||||||||||||||||||
| # Join base with target and check if it stays within base | ||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+17
|
||||||||||||||||||||||||||||||
| Note: This validates the path string without resolving symlinks to prevent | |
| symlink-based attacks. The check uses string comparison after normalization. | |
| """ | |
| try: | |
| base = Path(base_path).resolve() | |
| # Normalize target without fully resolving to prevent symlink attacks | |
| # Join base with target and check if it stays within base | |
| Note: This resolves both the base path and the combined target path to | |
| absolute, symlink-resolved paths and then verifies the target remains | |
| within the base directory. | |
| """ | |
| try: | |
| base = Path(base_path).resolve() | |
| # Resolve the combined path and ensure it stays within the resolved base |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is_relative_to() method was added in Python 3.9. For compatibility with earlier Python versions, this will raise an AttributeError. Consider adding a compatibility check or documenting the minimum Python version requirement in requirements.txt or README.
| return full_path.is_relative_to(base) | |
| try: | |
| # If full_path is not within base, this will raise ValueError | |
| full_path.relative_to(base) | |
| return True | |
| except ValueError: | |
| return False |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception handler on line 20 catches ValueError and RuntimeError but not AttributeError, which will be raised on Python versions before 3.9 when calling is_relative_to(). This method was only added in Python 3.9. The exception tuple should include AttributeError to handle older Python versions gracefully: except (ValueError, RuntimeError, AttributeError):
| except (ValueError, RuntimeError): | |
| except (ValueError, RuntimeError, AttributeError): |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first parameter archive_path is not used in the function body. This parameter should be removed from the function signature as it serves no purpose in the validation logic.
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calls to _safe_extract_member pass archive_path as the first parameter, but this parameter is unused in the function. All three extraction methods (extract_zip, extract_tar, extract_7z) should be updated to remove this unnecessary parameter.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SECRET_KEY is regenerated on every restart when not set via environment variable, which will invalidate all existing user sessions. While the warning message mentions this, the implementation stores the random key in a class variable that persists for the app lifetime but is lost on restart. Consider using a persistent fallback (like storing in a file) for development environments, or make the warning more prominent to ensure production deployments always set the environment variable.