fix: secure SQLite database paths to prevent path traversal#134
fix: secure SQLite database paths to prevent path traversal#134MasumRab wants to merge 7 commits intoscientificfrom
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideSmartFilterManager now secures SQLite database paths by introducing a ROOT_DIR constant and resolving any unspecified or relative db_path against it, ensuring all database files reside within the project root and preventing path traversal. Class diagram for updated SmartFilterManager initializationclassDiagram
class SmartFilterManager {
-db_path: str
-logger
-conn
+__init__(db_path: str = None)
}
class EmailFilter
SmartFilterManager --> EmailFilter
Flow diagram for secure SQLite database path resolutionflowchart TD
A["__init__ called with db_path"] --> B{Is db_path None?}
B -- Yes --> C["Set db_path to ROOT_DIR/smart_filters.db"]
B -- No --> D{Is db_path absolute?}
D -- Yes --> E["Use db_path as is"]
D -- No --> F["Set db_path to ROOT_DIR/db_path"]
C --> G["Assign db_path"]
E --> G
F --> G
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `backend/python_nlp/smart_filters.py:95-96` </location>
<code_context>
- def __init__(self, db_path: str = "smart_filters.db"):
+ def __init__(self, db_path: str = None):
"""Initializes the SmartFilterManager."""
+ if db_path is None:
+ db_path = os.path.join(ROOT_DIR, "smart_filters.db")
+ elif not os.path.isabs(db_path):
+ db_path = os.path.join(ROOT_DIR, db_path)
</code_context>
<issue_to_address>
**suggestion:** Defaulting to a project-root-based database path may cause unexpected file placement.
Using the project root for the database file may cause permission problems and clutter. A dedicated data directory or configurable path is recommended.
</issue_to_address>
### Comment 2
<location> `backend/python_nlp/smart_filters.py:97-98` </location>
<code_context>
"""Initializes the SmartFilterManager."""
+ if db_path is None:
+ db_path = os.path.join(ROOT_DIR, "smart_filters.db")
+ elif not os.path.isabs(db_path):
+ db_path = os.path.join(ROOT_DIR, db_path)
self.db_path = db_path
self.logger = logging.getLogger(__name__)
</code_context>
<issue_to_address>
**question:** Relative db_path resolution may not match user expectations if called from different working directories.
Please document that relative paths are resolved against the project root, or add a parameter to allow users to specify the resolution behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…sumRab/EmailIntelligence into fix/initial-attempt-and-reset
…sumRab/EmailIntelligence into fix/initial-attempt-and-reset
…l attacks - Add path validation logic to SmartFilterManager.__init__() - Resolve relative paths relative to DATA_DIR to prevent directory traversal - Preserve absolute paths for backward compatibility - Update docstring to clarify path resolution behavior This completes the security fix for PR #134 by properly implementing the path traversal prevention that was identified in the code review.
…l attacks - Add path validation logic to SmartFilterManager.__init__() - Resolve relative paths relative to DATA_DIR to prevent directory traversal - Preserve absolute paths for backward compatibility - Update docstring to clarify path resolution behavior This completes the security fix for PR #134 by properly implementing the path traversal prevention that was identified in the code review.
…l attacks - Add path validation logic to SmartFilterManager.__init__() - Resolve relative paths relative to DATA_DIR to prevent directory traversal - Preserve absolute paths for backward compatibility - Update docstring to clarify path resolution behavior This completes the security fix for PR #134 by properly implementing the path traversal prevention that was identified in the code review.
…l attacks - Add path validation logic to SmartFilterManager.__init__() - Resolve relative paths relative to DATA_DIR to prevent directory traversal - Preserve absolute paths for backward compatibility - Update docstring to clarify path resolution behavior This completes the security fix for PR #134 by properly implementing the path traversal prevention that was identified in the code review.
Summary by Sourcery
Secure SQLite database path resolution in SmartFilterManager by anchoring database file paths to the project root and preventing path traversal
Bug Fixes:
Enhancements: