PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG: /sync-folder does not validate the supplied folder_id

Open sathvikn113 opened this issue 2 weeks ago • 5 comments

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

sathvikn113 avatar Nov 16 '26 14:11 sathvikn113

👋 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 :)

github-actions[bot] avatar Nov 16 '26 14:11 github-actions[bot]

⚠️ Potential Duplicate Issue (Semantic Match)

This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:

  1. 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%

  2. BUG: sync-folder 500 on missing folder (#1625, open) https://github.com/AOSSIE-Org/PictoPy/issues/1625 Similarity: 61.5%

  3. 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.

github-actions[bot] avatar Nov 16 '26 14:11 github-actions[bot]

@rohan-pandeyy i want to work on this issue can you assign it to me ?

swastiksharma45 avatar Nov 16 '26 16:11 swastiksharma45

@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 avatar Nov 17 '26 05:11 sathvikn113

@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.

swastiksharma45 avatar Nov 17 '26 05:11 swastiksharma45