Skip to content

Handle revoked database file access with reselect flow - #2572

Open
empratyush wants to merge 5 commits into
Kunzisoft:masterfrom
empratyush:1233-handle-database-permission-denial
Open

empratyush wants to merge 5 commits into
Kunzisoft:masterfrom
empratyush:1233-handle-database-permission-denial

Conversation

@empratyush

Copy link
Copy Markdown

Summary

This PR improves the recovery flow when Android/SAF revokes access to the selected database file. Instead of requiring users to remove and re-add the database, KeePassDX now prompts them to reselect the file directly, opening the picker near the previous file location when possible.

Changes

KeePassDX now detects revoked persisted access before opening the database, treats revoked or missing URI access as an inaccessible database, and routes the user into the reselect-file flow.

Background

I have been using KeePassXC for a long time, with my database synced through Nextcloud. After switching to a new device, the Nextcloud app started behaving strangely and would crash when I tried to open the database through SAF. So I switched to FolderSync Pro instead.

At first, everything worked fine. The issue started after I modified an entry from the desktop side. KeePassDX then showed:

Access to the file revoked by file manager

The workaround was to remove the database from KeePassDX and add it again. That fixed it temporarily, but the issue came back every time the database was modified from the desktop side.

My assumption is that FolderSync Pro recreates the database file during sync, or at least Android treats it that way, which invalidates the existing SAF permission grant.

This PR adds a smoother recovery flow for that case: when access to the database file is revoked, KeePassDX now lets the user reselect the same database file instead of requiring them to remove and re-add it manually.

One more thing I noticed during the workaround: after removing and re-adding the same database, the database password was fetched automatically after the biometric prompt. I am not sure if that behavior is expected.

Handle SecurityException from takePersistableUriPermission separately so
revoked or missing SAF grants are visible in logs before the generic fallback.
FileNotFoundException is already mapped inside database stream parsing, but
openInputStream can fail before parsing starts. Convert FileNotFoundException
and SecurityException from opening the URI into FileNotFoundDatabaseException
so a later change can prompt the user to reselect the file.
Pass EXTRA_INITIAL_URI to SAF so re-selecting a known file starts near its
previous location.
Detect missing persisted read access before loading database metadata and
launch SAF with the previous URI as the initial picker location.
@empratyush

Copy link
Copy Markdown
Author
demo.mp4

Demo video of the original and dev versions running on a stock Google Pixel.

cc @J-Jamet

@empratyush
empratyush marked this pull request as ready for review June 15, 2026 06:17
@J-Jamet J-Jamet moved this to Todo in KeePassDX 4.7.0 Jun 15, 2026
@J-Jamet

J-Jamet commented Jun 15, 2026

Copy link
Copy Markdown
Member

This feature is interesting and really improves the workflow. It might be a good idea to add a button to remove the link, but that can be done later. It looks promising.

I’ll take a look at the code in version 4.6.0. (it will need to be merged with the latest changes because a refactoring is in progress in version 4.5.0.)

@empratyush

Copy link
Copy Markdown
Author

I’ll take a look at the code in version 4.6.0. (it will need to be merged with the latest changes because a refactoring is in progress in version 4.5.0.)

Thanks! Just ping me when it needs rebasing.

@empratyush

Copy link
Copy Markdown
Author

I found another workaround that fixes the issue.

When I open KeePassDX and see the file path instead of the database name (which usually means I'm about to get a "permission revoked" error), I don't try to open the database or remove and re-add it. Instead, I tap "Open Existing Vault" at the bottom and simply reselect the same database file. That restores access and fixes the issue.

@kraftnix

kraftnix commented Aug 4, 2026

Copy link
Copy Markdown

The Open Existing Vault workaround only works sometimes for me. Very often I still get stuck being unable to open the db until I remove and readd the db file... (4.4.5 from Fdroid)

@Gerporgl

Gerporgl commented Aug 6, 2026

Copy link
Copy Markdown

Is it not possible to request from the file manager access to an entire folder instead? Would that solve the problem?

Actually based on the linked other project above it seems like a working solution:
chvp/NanoLedger#458

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants