BUG: /sync-folder does not validate the supplied folder_id
Is there an existing issue for this?
- [x] I have searched the existing issues
What happened?
Problem
While going through the /sync-folder implementation, I noticed that it doesn't check whether the given folder_id actually exists in the database before starting the sync operation.
Where I found the issue
In app/routes/folders.py, the sync_folder() function fetches the child folders using the ID passed in the request:
db_child_folders = db_get_direct_child_folders(request.folder_id)
But there is no check before this to confirm that the folder exists.
I also noticed that db_update_parent_ids_for_subtree() in app/database/folders.py updates parent_folder_id using a regular SQLite connection without enabling foreign-key enforcement. This means an invalid parent ID can be stored in the database.
Expected behaviour
The endpoint should check whether the supplied folder_id exists before proceeding with synchronization. If it doesn't exist, it should return a 404 response without making any database changes.
Possible approach
We could use db_get_folder_path_from_id() in sync_folder() to check whether the folder exists before proceeding.
I would like to work on this and add the necessary regression tests. Please let me know if this behaviour and approach look correct.
Record
- [x] I agree to follow this project's Code of Conduct
👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)
⚠️ Potential Duplicate Issue (Semantic Match)
This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:
-
BUG: Adding a folder also re-indexes similarly named sibling folders (unbounded LIKE prefix match in db_get_folder_ids_by_path_prefix) (#1553, open) https://github.com/AOSSIE-Org/PictoPy/issues/1553 Similarity: 63.9%
-
BUG: sync-folder 500 on missing folder (#1625, open) https://github.com/AOSSIE-Org/PictoPy/issues/1625 Similarity: 61.5%
-
BUG:SQLite OperationalError crashes indexing when scanning large directory trees (e.g., Google Takeout exports) (#1500, open) https://github.com/AOSSIE-Org/PictoPy/issues/1500 Similarity: 60.4%
Please review before proceeding.
@rohan-pandeyy i want to work on this issue can you assign it to me ?
@rohan-pandeyy i want to work on this issue can you assign it to me ?
Sorry @swastiksharma45 this is proposed by me and I already have a fix ready for it ,so I will look forward to work on it once it is accepted.Please look for other suitable issues.Thanks for understanding
@sathvikn113 thanks for the reply, and fair enough that you proposed the issue. Assignment is up to the maintainers though, so I'll leave it to @rohan-pandeyy to decide. If I'm picked, I can start right away and have a PR up quickly.