KeePassDX icon indicating copy to clipboard operation
KeePassDX copied to clipboard

Autofill not working with Fenix when not signed in into DB

Open drujd opened this issue 2 years ago • 32 comments

Autofill with KeePassDX as autofill provider does not work completely with Fenix in some specific cases where Keepass2Android works perfectly in the same circumstances. This seems to happen only when KeePassDX is not currently signed into my DB.

Website examples with the problem (when logged out from the website & signed out from the DB): https://www.reddit.com/login https://login.cncenter.cz/Login

Keepass2Android : I can click either username or password and click autofill on my keyboard, unlock database prompt shows up and both fields get filled out after I successfully login into the DB. Basically it works in all cases: Unlocked, "quicklocked" and without the DB loaded.

KeePassDX : When DB is not open, autofill does not work on the username field (in keyboard prompt, there is no autofill option in context menu, but that seems normal in Fenix regardless of autofill provider), it usually works for the password field, but it also only fills the password after logging into the DB, not the username. If I manually open KeePassDX and login into my DB and then refresh the page, autofill starts working on the username field as well.

KeePass Database

  • Created with: Some ancient version of KeePass on Windows, but probably does not matter
  • Version: V2 - KDBX4.1
  • Location: Remote file retrieved with OneDrive app
  • File provider (content:// URI): content://com.microsoft.skydrive.content.StorageAccessProvider/document/content...[cut]
  • Size: ~600 KiB
  • Contains attachment: Some entries yes

KeePassDX:

  • Version: 3.5.0
  • Build: Free
  • Language: English

Android:

  • Device: Samsung S23 Ultra
  • Version: 13 (One UI 5.1)

Firefox:: Firefox for Android (Fenix) 110.0

drujd avatar Feb 11 '23 11:02 drujd

Thank you for the accurate description. It is planned to completely redo the autofill recognition system to have a recognition granularity per form but it needs a lot of work. I will already look if the username can be easily recognized in this specific case.

J-Jamet avatar Feb 11 '23 14:02 J-Jamet

Well, now I am experiencing the issue on reddit even with the db opened. It seems to behave randomly... Stopping firefox, closing all tabs and reopening reddit fixed that.

drujd avatar Feb 11 '23 16:02 drujd

I can confirm I also experience this issue in Mull browser (based on Firefox). Only the password field is detected sometimes.

Also Autofill does not work at all in kiwi browser or bromite even though I have added them to the list of allowed Autofill apps via adb. It is temperamental in other apps (e.g. DroidFS)

TippyLion28 avatar Mar 04 '23 18:03 TippyLion28

I have to check but if the username is filled with a password, it means that the form creators have indicated that the username field is a password field... To get around this, we have to either indicate this bug in the form, or make a lot of exceptions (which might be the case if we create and apply a URL form recognition library)

J-Jamet avatar Mar 14 '23 17:03 J-Jamet

I have to check but if the username is filled with a password, it means that the form creators have indicated that the username field is a password field... To get around this, we have to either indicate this bug in the form, or make a lot of exceptions (which might be the case if we create and apply a URL form recognition library)

Huh, I have read through my report and all the comments again, nowhere do I see anyone reporting username field being filled with password. Just the username not being filled at all - and only when DB is not currently open. KeePassDX works perfectly for me as long as I am logged into the DB and I open the page afterwards - which leads me to the conclusion that this behaviour is really just some bug in autofill->open/unlock DB scenario.

drujd avatar Mar 14 '23 18:03 drujd

Sorry, I was on another issue that is related and answered in the wrong thread. I need to see why it works in your case only when a database is open, but normally the Autofill service works the same way if the database is opened or closed. It is possible that the autofill service does not start because the system does not detect the application anymore because the KeePassDX service (different from the Autofill service) indicates the app currently running to your system.

J-Jamet avatar Mar 14 '23 18:03 J-Jamet

There might be a form recognition bug that I didn't identify, I'll check that for version 5.0.0

J-Jamet avatar Mar 14 '23 18:03 J-Jamet

If it didn't work at all, that would make sense, but it partially works even when the DB is closed - it does show the autofill button (for the password field) and after opening the DB it does fill out the password.

When I open the DB, close the Firefox tab, open a new tab with the same website, autofill starts working for username fields as well (shows autofill button even in the username field and fills out the username field as well).

drujd avatar Mar 14 '23 18:03 drujd

In this case, it is not a problem in the implementation of the service rules provided by KeePassDX, because they are always the same. Honestly I don't see what I can do from KeePassDX. If it depends on a Firefox tab, maybe it's a bug in Firefox or in the Autofill service of your device.

J-Jamet avatar Mar 17 '23 01:03 J-Jamet

And yet Keepass2Android always works without problems with Fenix...

EDIT: Ignore all of this and see my next post...

So I did some additional testing and I think this has nothing to do with the database being closed/open, but with some part of the application running (or not).

My new test that always replicates the issue:

  1. Select Keepass2Android OR KeePassDX as your autofill provider, no need to unlock your DB or anything like that, we will be stopping it anyway
  2. Close all tabs in Fenix and close Fenix app
  3. FORCE STOP the selected autofill provider app
  4. Open Fenix, some web with standard login page - e.g. reddit.com - and try to login by tapping the username field

Keepass2Android as autofill provider: Still shows the autofill prompt in keyboard in the username field KeePassDX: Only shows the prompt in the password field and subsequently fills out only the password

Now in the case of KeePassDX: 5. Click the password field and click autofill 6. This opens KeePassDX with db selection/unlock - ypu can close it immediately, no need to login to the DB 7. Repeat step 2 and 4

Even KeePassDX now works as expected.

Sorry for incorrecly identifying the underlying cause, clearly it is about something running that starts only after an autofill attempt. I will now try to set battery optimization for KeePassDX to Unrestricted and see if that works around or at least improves the situation, but again, Keepass2Android does not need any of this.

I have also noticed that a short while after force stopping the current autofill provider app, the system apparently starts it again (because it is needed for autofill functionality, I guess) - that does not happen after force stopping the other app (currently not set as autofill provider).

Maybe there is some issue with KeePassDX not starting correctly/completely until you actually try to autofill something?

EDIT: The original version of the instructions had opening KeePassDX manually, but that does not seem to help.

drujd avatar Mar 17 '23 09:03 drujd

Just ignore everything I have posted here so far...

KeePassDX seems to behave completely randomly with Fenix on each page refresh. Sometimes the username field works, sometimes it does not. I have now managed to replicate the issue even with the DB open, even though until now I had no problems as long as the DB was opened.

But now, just refreshing reddit.com/login: Sometimes it works, sometimes it doesn't. Works. Refresh. Works. Refresh. Doesn't work...

Weird, weird, weird...

drujd avatar Mar 17 '23 10:03 drujd

I have also now noticed in KP2A change log: 1.09b: "Fix disappearing autofill prompt in Firefox"

Maybe that was the fix for KP2A?

drujd avatar Mar 17 '23 19:03 drujd

Ho, lots of twists and turns in your story. :D

I have also now noticed in KP2A change log: 1.09b: "Fix disappearing autofill prompt in Firefox" Maybe that was the fix for KP2A?

It is possible, it means that there is an instruction applied to bypass a buggy behavior in firefox. We will have to study that.

J-Jamet avatar Mar 18 '23 07:03 J-Jamet

It seems this Keepass2android-issue discusses the same issue, or at least similar.

This comment proposes a workaround for users to set in firefox, which fixes the behaviour.

I have tested it with fenix 111.1, and the autofill-promt shows up for me. Maybe this will help someone in the meantime!

newhinton avatar Apr 13 '23 12:04 newhinton

Thanks, hopefully this helps some people but does not improve popup stability for me on Mull.

TippyLion28 avatar Apr 13 '23 13:04 TippyLion28

I too am experiencing a disappearing auto-fill prompt, and a prompt that only pops up in the password field (and subsequently autofills only the password field). The behaviour has been going on for a couple of years at least. I've resorted to using Magikeyboard, even though it's not an optimal user experience.

The behaviour seems completely random, too. I mean there looks like there is a correlation: if database is already open then the autofill prompt appears correctly in the username field and works as expected, however it's not always the case. I don't have any stats, but it feels like it has a better chance to work correctly if the database is unlocked..

I'll gladly help troubleshooting if I can. Actually, any suggestions for troubleshooting this would be great.

Edit: Forgot to mention that I'm running Android 13 (CalyxOS) and the behaviour is not app-dependent (e.g. all browsers behave similiarly [tested on Chrome, Chromium, Mull, Brave, Firefox] and all other apps with login screens)

Joni-Samanen avatar Oct 25 '23 01:10 Joni-Samanen

I too am experiencing a disappearing auto-fill prompt> I'll gladly help troubleshooting if I can. Actually, any suggestions for troubleshooting this would be great.

First off I'd try e.g. Keepass2android. If you have the same issue, the problem might be the system's autofill implementation rather than the keepass app or the browser...

drujd avatar Oct 25 '23 08:10 drujd

In compatibility mode, the KeePassDX code retrieves the last text field of the form app that is not a password, to put it as a username. It worked when the URL field bar was above, but not when it's below. I've just improved the code to add the check of the password field as condition to add a text field as username, assuming that the username field is always above the password, but it may add other bugs.

J-Jamet avatar Nov 04 '23 12:11 J-Jamet

Fixed in 4.0.3

J-Jamet avatar Nov 06 '23 11:11 J-Jamet

Fixed in 4.0.3

The username field somehow still doesn't work for me? I am using version 4.0.4 and standard chrome browser (119.0.6045.66). The password field works fine though.

Websites I tested

I couldn't find a single website that worked for me.

But I also don't understand, what do you mean by "compatibility mode"? Do I have to enable that somehow?

Dampfwalze avatar Nov 07 '23 15:11 Dampfwalze

The problem is not easy to solve, I know how to modify the algorithm to make it work, but it breaks the recognition of other browsers. It's really not easy to do generic recognition on a non-standardized technology.

J-Jamet avatar Nov 08 '23 18:11 J-Jamet

So, there is a solution that makes it work reliably, but it breaks chromium based browsers? And you (rightly) chose to make chromium the preferred supported browser?

I also guess that there is no way to detect which browser is requesting autotype.

If my assumption is true, would it be possible to make a "Firefox-Compatibilty' setting that uses firefox-preferring algorithms? Usually such a setting is a bad idea, but it seems that there is no easy solution to this.

newhinton avatar Nov 08 '23 18:11 newhinton

Typically people will use just one browser, so I think it's okay to add a setting to choose a detection mode

TippyLion28 avatar Nov 08 '23 19:11 TippyLion28

So, there is a solution that makes it work reliably, but it breaks chromium based browsers? And you (rightly) chose to make chromium the preferred supported browser?

No, it's just that I didn't have it in mind that it would break another implementation, so obviously I didn't do it by choice. The problem is getting the Reddit application to work. https://github.com/Kunzisoft/KeePassDX/issues/1667 The issue to prevent username recognition is here : https://github.com/Kunzisoft/KeePassDX/blob/28ccaffcf51f9da604fa02f0c5072981750fe759/app/src/main/java/com/kunzisoft/keepass/autofill/StructureParser.kt#L144

The aim is to remain generic, so I don't want to favor one browser over another.

J-Jamet avatar Nov 08 '23 19:11 J-Jamet

If my assumption is true, would it be possible to make a "Firefox-Compatibilty' setting that uses firefox-preferring algorithms? Usually such a setting is a bad idea, but it seems that there is no easy solution to this.

If configurations are to be made by browser and form, we'll need to create a library for this, which we'll need to reference with all browsers and forms. It's a huge job. https://github.com/Kunzisoft/KeePassDX/issues/1287

J-Jamet avatar Nov 08 '23 19:11 J-Jamet

https://github.com/Kunzisoft/KeePassDX/commit/fc56db2f839a7fe3ac3cd1c3185074a5c955e4e1 should fix this issue and make everything works

J-Jamet avatar Nov 08 '23 19:11 J-Jamet

Can you tell me if it's OK for everyone with version 4.0.5?

J-Jamet avatar Nov 09 '23 18:11 J-Jamet

For me it works party. As an example: otto.de only works in the password field, the same is true for paypal.

Steam works, kleinanzeigen.de aswell.

So it seems that the username-detection is still spotty, but with my limited testing the password promt regularly and reliably shows up. (Well, except for otto.de, but to me it looks like they do something screwy with that popup) So generally speaking, an improvement to 3.x, where it was hard to use at all. Thanks for your progress!

newhinton avatar Nov 10 '23 20:11 newhinton

I just checked for the otto site, and it doesn't work because for some reason the browser detects the PLZ field as a phone field. So I set the phone detection field to a lower priority and it works. This will be effective in the next release.

J-Jamet avatar Nov 10 '23 21:11 J-Jamet

Can you tell me if it's OK for everyone with version 4.0.5?

Field detection seems perfect now, however I now have a new issue. I get prompted to unlock the database and select and entry, but when it returns to the app/browser the Autofill suggestion gui is not there. I have to minimise the app (not force close) and then bring it back to the foreground before the gui shows up.

TippyLion28 avatar Jan 13 '24 19:01 TippyLion28