PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG:Backend lets an album be locked with no password, making it permanently inaccessible

Open RITVIKKAMASETTY opened this issue 2 weeks ago • 8 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

What happened?

The album create/update endpoints accept is_locked: true without a password. The album is saved as locked with password_hash = NULL, so verify_album_password rejects every password from then on. Its photos can't be viewed, it can't be unlocked, and the password can't be changed. Deleting it is the only way out.

Cause

The "locked albums need a password" check in backend/app/schemas/album.py is a @field_validator("password"). In Pydantic v2, field validators don't run on default values, so when the request leaves out password entirely, the check is skipped.

UpdateAlbumRequest has a second gap: the check passes whenever current_password is non-empty. But update_album only verifies current_password if the album is already locked, so for an unlocked album any string works.

Steps to reproduce

  1. Create path:

    POST /albums/   {"name": "A", "is_locked": true}
    

    → 200. Then POST /albums/{id}/images/get with any password → 401 Invalid Password. PUT /albums/{id} to unlock → 401 Incorrect Password.

  2. Update path (on an existing unlocked album):

    PUT /albums/{id}   {"name": "B", "is_locked": true, "current_password": "junk", "password": null}
    

    → 200 Album updated successfully. The album is now locked with no password and can't be opened.

Expected

Both requests should be rejected with a 400/422 when an album is being locked without a new password.

Notes

The Create/Edit dialogs validate this on the client, so normal UI use doesn't hit it. The backend shouldn't rely on that check, though, and any other client or a future UI change could brick albums.

Suggested fix

  • Replace the password field validator in CreateAlbumRequest with a @model_validator(mode="after") so it always runs.
  • In update_album, return 400 when an album that isn't locked yet is being locked without password.
  • Add tests for both paths.

I checked these and I don't think this is a duplicate:

  • #1617: locked albums can be deleted without a password (delete_album).
  • #1631: images can be added/removed on locked albums without a password.
  • #1662: frontend unlock caching; a wrong password briefly opens the album.

All three are about a missing or wrong password check on an album that has a password. This issue is about the backend letting an album be locked with no password stored at all (password_hash = NULL), because the @field_validator("password") in schemas/album.py is skipped when password is omitted, plus the current_password bypass in update_album. After that, no password can open, unlock or edit the album.

The open fixes for those issues (#1675, #1701, #1691) don't touch this validator, so they wouldn't fix this.

I'd like to work on this if it's approved.

Record

  • [x] I agree to follow this project's Code of Conduct

RITVIKKAMASETTY avatar Nov 14 '26 06:11 RITVIKKAMASETTY

👋 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 14 '26 06:11 github-actions[bot]

I will raise pr once approved and assigned to me

RITVIKKAMASETTY avatar Nov 14 '26 06:11 RITVIKKAMASETTY

⚠️ Potential Duplicate Issue (Semantic Match)

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

  1. BUG: Password-protected locked albums can be deleted without providing a password (#1617, open) https://github.com/AOSSIE-Org/PictoPy/issues/1617 Similarity: 82.5%

  2. BUG: Add/remove image endpoints allow mutations on locked albums without password verification (#1631, open) https://github.com/AOSSIE-Org/PictoPy/issues/1631 Similarity: 81%

  3. BUG: Wrong password briefly opens a locked album, and the right one fails after a wrong attempt (#1662, open) https://github.com/AOSSIE-Org/PictoPy/issues/1662 Similarity: 74.8%

Please review before proceeding.

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

I checked these and I don't think this is a duplicate:

  • #1617: locked albums can be deleted without a password (delete_album).
  • #1631: images can be added/removed on locked albums without a password.
  • #1662: frontend unlock caching; a wrong password briefly opens the album.

All three are about a missing or wrong password check on an album that has a password. This issue is about the backend letting an album be locked with no password stored at all (password_hash = NULL), because the @field_validator("password") in schemas/album.py is skipped when password is omitted, plus the current_password bypass in update_album. After that, no password can open, unlock or edit the album.

The open fixes for those issues (#1675, #1701, #1691) don't touch this validator, so they wouldn't fix this.

RITVIKKAMASETTY avatar Nov 14 '26 06:11 RITVIKKAMASETTY

Link your account with Gitcord

Thanks for opening this issue, @RITVIKKAMASETTY!

To receive Discord notifications and contributor tracking for this organization:

  1. Join Discord: https://discord.gg/hjUhu33uAn
  2. In Discord, run /link RITVIKKAMASETTY
  3. Paste the verification code into your GitHub bio (or a public gist)
  4. Click Verify in Discord (or run /verify-link RITVIKKAMASETTY)

Once linked, Gitcord can notify you about assignments, mentions, and more.

— Posted by Gitcord

gitcordapp[bot] avatar Nov 14 '26 06:11 gitcordapp[bot]

Hello [@rohan-pandeyy](https://github.com/rohan-pandeyy/rohan-pandeyy),

I would like to work on this issue.

Problem 1: A new album gets created when is_locked = True but no password is provided.

My proposed solution:

I ran a test to verify whether this issue actually exists:

import pytest
from app.schemas.album import CreateAlbumRequest

def test_create_album_no_password():
    with pytest.raises(ValueError):
        CreateAlbumRequest(
            name="ABCD",
            is_locked=True
        )

As expected, this test fails with DID NOT RAISE <class 'ValueError'>, confirming that the issue exists.

The reason behind this issue is that the password field inside the CreateAlbumRequest class has a default value:

password: Optional[str] = None

Due to this default value, the field_validator is skipped when no password is provided during album creation. This happens because of how Pydantic's field validators handle default values.

Replacing the field_validator with a model_validator solves this problem by validating the model after all its fields have been initialized.

Problem 2: An existing unlocked album becomes permanently locked when attempting to lock it without providing a password.

When trying to lock an existing album that is initially unlocked, setting is_locked = True without providing a password can result in the album becoming permanently locked.

My proposed solution:

For the second problem, I updated the update_album() function inside backend/app/routes/albums.py.

The change handles the situation where an album was initially unlocked (no password was set) and the user attempts to lock the same album without providing a new password.

I added the following validation:

else:
    if body.is_locked and not body.password:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=ErrorResponse(
                success=False,
                error="Missing Password",
                message="A new password is required when locking an album.",
            ).model_dump(),
        )

Here, the else corresponds to the existing if album["is_locked"] condition. It handles albums that were initially unlocked. This ensures that whenever a user attempts to change an unlocked album into a locked album, a new password must be provided. Otherwise, the API returns an HTTP 400 error. Both fixes have been implemented and tested successfully. The changes are available on my branch: fix/1713-album-password-validation. I have also verified that valid album operations continue to work as expected, while the invalid scenarios are now properly rejected. I am ready to submit a PR for these changes.

sayxnn17 avatar Nov 14 '26 19:11 sayxnn17

@sayxnn17 I think we need to wait until issue is assigned so I did not raise a pr I have already worked on this so can you please close your pr

RITVIKKAMASETTY avatar Nov 14 '26 20:11 RITVIKKAMASETTY

@RITVIKKAMASETTY I have closed my PR. My mistake to open PR before getting assigned.

sayxnn17 avatar Nov 15 '26 20:11 sayxnn17