Without a password
Not released yet (comes after 1.7.0) The Windows and Mac programs can be used without a password as long as they only answer on the computer they run on. A password is needed as soon as another device should reach them. This page is the design; what the user does is in First steps and Phone and other devices.
Who gets in
Without a password, whoever can ask 127.0.0.1 must not simply be signed in: that is every account on the computer, every website open in the browser, and everything behind a tunnel or a proxy. So LibrePhotos signs in the browser it opened itself.
- When the program starts, the holder of the data folder's lock writes 32 random bytes to
open.keyin the data folder, readable for the owner only (librephotos/open_key.py). They are new at every start. - The program opens the browser at
http://127.0.0.1:8000/#open=<key>. It is always127.0.0.1, whatever the program was started with, and the program holds that address itself (Claim.hold_own_addressinlibrephotos/web_port.py). A browser may takelocalhostfor::1, and a program of another account that listens there would be handed the key. The key is an expiry, a random number and an HMAC of both with that secret. It is good for one hour, for one sign-in and for this start. The second start that only opens the window of a running LibrePhotos reads the same file. - The part after
#is never sent to a server and never logged. The web app takes it out of the address bar before it does anything else, keeps it for this tab, and sends it toPOST /api/own-computer/enter/when it needs to sign in. Log out forgets it, in the other tabs too. A sign-in that only runs out in another tab does not: the tab from before a new start loads again by itself at the moment the new window opens (verification/platform/WindowKey.tla). - The answer is the ordinary pair of tokens of a remembered sign-in, with the ordinary cookies. From there on nothing differs: the same checks, the same expiry, the same way to sign out. Only where LibrePhotos should ask each time, the sign-in ends earlier.
enter refuses the key unless all of this is true (api/accounts/own_computer.py):
- It is the Windows or Mac program. Docker and every other installation have no keys at all.
- The program listens on this computer only: no
--host, and other devices are not let in. - The request comes from this computer: a loopback peer, a loopback name in
Host, our own page inOrigin, and no header of a proxy (api/accounts/this_computer.py). - There is exactly one active account. It is the admin's, it has no password, and it is not connected to a single sign-on.
- It is not a demo site.
An account without a password has Django's unusable password. Nothing else needs to know about it: POST /api/auth/token/obtain/, Basic authentication, the Django admin and the mobile app refuse it the way they refuse a wrong password. An address that is open for other devices can therefore never be entered without a password.
Account menu > Profile sets a first password as well. It normally asks for the current password or a recent sign-in. An account that has none, on its own computer, may set it at any time (chooses_first_password): who is signed in there could have opened a new window anyway.
A second account cannot be made while the first has no password (409 password_first). If one appears in another way, for example with manage.py createuser, or if the program is started with --host, keys stop working and the sign-in page asks for a password first.
Opening a window
When the session has ended, the sign-in page on this computer offers Open LibrePhotos. It asks POST /api/own-computer/open/, and the program opens a window with a new key in the browser of the person whose desktop it runs on. The answer never holds a key. Somebody else who sends that request gets nothing; the owner gets a window.
A forgotten password works the same way, with one step before it: Windows or the Mac asks whether it is the owner. Then the program opens http://127.0.0.1:8000/#password=<uid>.<token>, also after a start with --host: it then listens on 127.0.0.1 next to the address it was given. If somebody else already has that address, no window is offered, and the sign-in page names manage.py changepassword instead. The web app keeps both for this tab and shows /password-reset/program, so the token is in no path and no log. The new password goes through POST /api/auth/password/reset/confirm/ like every other one: it works once, it ends all other sessions, and it is for the first admin. The token is not the one of an e-mail (api/accounts/window_reset.py): it is good for an hour and only on this computer, while a mailed link keeps its three days. Other people's passwords are set by the admin in the Admin area.
Is it the owner?
OwnerCheck.confirm(reason) in librephotos/owner_check.py lets the operating system ask the person at the desktop, and answers confirmed, cancelled, unavailable or busy. Every error is unavailable. open_password_window calls it before it makes a reset token, so a program or a person that only reaches the address gets nothing from it. The request waits for the answer, but five minutes at most, and not when LibrePhotos ends meanwhile. A late answer counts for nothing. There is one prompt at a time (busy for a second one, until the first is closed), five requests a minute, and the text names LibrePhotos and the reason, so a prompt nobody asked for can be recognised. The texts are owner_check.* in app_texts, in the language of the computer.
Windows (windows_owner.py decides, windows_prompts.py calls Windows with ctypes):
- If Windows Hello is set up,
UserConsentVerifierasks for the PIN, the face or the fingerprint. From Windows 11 on it gets the window in front as its owner (IUserConsentVerifierInterop), so that it does not open behind the browser. If Windows ends that with an error, it is asked once more without a window. - Otherwise Windows' own password window opens (
CredUIPromptForWindowsCredentials), for the account LibrePhotos runs in.LogonUserchecks what was typed, and the account it belongs to must be our own. Only a wrong password may be typed again, three times in all; every other error ofLogonUserisunavailable. The password stays in one buffer, which is overwritten right after, and in no log. - An account without a password has nothing to check. The answer is
unavailable, and the page nameslibrephotos.exe manage changepassword.
Mac (macos_owner.py): LAContext with deviceOwnerAuthentication asks for Touch ID, the Apple Watch or the password of the Mac. LibrePhotos never sees any of them.
Not a passkey: a browser gives those out for a domain or https only, not for http://127.0.0.1:8000 and not for an address in the home network. Not a password of our own: it would be the thing that was forgotten.
Asking each time
With ASK_EACH_TIME (a site setting, written by the setup and by POST /api/own-computer/asking/) the key of a window is not enough. POST /api/own-computer/enter/ redeems it, then asks the operating system, and checks afterwards that the rules above still hold. A refused question is 409 with not_confirmed, cannot_ask or already_asking; the key is used up, so one window asks once.
A sign-in from before must not go on for 30 days. Presence (api/runtime/own_computer.py) keeps in memory when each sign-in was last used. is_still_here asks it at every request and every refresh of a token: 15 minutes after the last request the sign-in is over, and after a new start of the program all of them are, also those from before the choice. A visible window asks for the running jobs every 15 seconds (useWorkerQuery), so it never gets there: only a window that was closed, or hidden behind others for that long, asks again. The texts promise no more than that. The cookies are session cookies. Only the account without a password is checked that way; everybody else pays nothing for it.
Turning it on and off, the first password, another e-mail address and the switch to other devices need the same confirmation, otherwise an open window would be enough to get around it. At the first setup the question comes before the account is made, so a computer that cannot ask locks nobody out. The window that confirmed it is let in without a second question.
With a password the setting has no effect. manage changepassword is therefore the way back in when the computer cannot ask anymore. This owner never typed a username, so in the Windows and Mac programs the command needs none: it takes the only active account, and lists the names when there are several (with_account in librephotos/standalone.py). Everywhere else it is Django's own command.
Letting other devices in
POST /api/own-computer/devices/ is for an admin on this computer. The order is what makes it safe:
- The password and the choice (
OTHER_DEVICES, one of the site settings in the database) are stored in one transaction. - Only then a second listener opens the same port on the network (
librephotos/home_network.py). It serves the same application in the same process; the listener for this computer is never closed, so nothing restarts and nothing that goes wrong can lock the user out.
If the program ends in between, the next start finds both or neither. If the address cannot be opened, the choice is taken back and the password stays. The answer is then still 200, with state: "this_computer" and a renewed session, because the new password ended the old one; the page says that other devices cannot connect. Only this computer stores the choice first and closes the listener then.
At every start the choice is read after the server runs. With the choice and an admin who has a password, the address opens again. So Start when the computer starts and a double-click do the same. An explicit --host is left alone: the page only says that LibrePhotos was started that way.
What can happen
| Who | What happens |
|---|---|
| Another website in the same browser | It can send requests to localhost, but not with our Origin; every endpoint above refuses it. The session cookies are SameSite=Lax. |
A website that points its own name at 127.0.0.1 (DNS rebinding) | Host is its own name: refused. Our cookies belong to another name. |
| Another account on the same computer | It reaches 127.0.0.1, but has no key: it sees the sign-in page. It can make a window open on the owner's desktop, at most five times a minute, and make Windows or the Mac ask the owner. Cancelled, nothing happens. Confirmed, the new window opens on the owner's desktop and not for the other account. |
A program of another account that listens on localhost or 127.0.0.1 at the same port | Gets no key and no token: they only go to 127.0.0.1, and only while LibrePhotos holds it. |
| Someone at the same desktop, in the owner's account | Sees the photos while somebody is signed in or there is no password, as with every other program and folder of that account. After Log out they need the password. Where LibrePhotos asks each time, they see the photos in a window that was left open, and for 15 minutes after the last one was closed. They cannot choose a new one without the PIN or password of the computer. The photo files and the data folder are still readable in that account, and manage changepassword still works there. The setup and the user guide say to give other people their own account of the computer. |
| Someone who knows the PIN or password of the computer, or an account that has none | Is the owner for the computer, and so for LibrePhotos. In a Windows account without a password no new password can be chosen from the sign-in page at all. |
| A prompt nobody asked for | Names LibrePhotos and the reason. On Windows it also says to cancel it. |
| The password of Windows typed into our prompt | Goes to LogonUser and is overwritten. It is never stored, logged or sent. |
| A program of the owner's own account | Can read the data folder, and with it the database and the secret key. A password does not change that. |
A data folder that others may read (--data-dir on a shared drive) | They can read open.key, but also the database. Keep the folder private, or use a password. |
An SSH tunnel, cloudflared, a reverse proxy | No key is given to anyone there. With the headers of a proxy, or a name that is not this computer's, also a key would be refused. |
| An old key or reset token from the history of the browser | It worked once and ends after an hour, the key also with the program. |
| Somebody in the network of a hotel, when the owner takes an open computer there | Sees the sign-in page. The password is all that protects the photos then, and the page says to close LibrePhotos for others first. |
| A phone or a script with an API token or a password | Nothing changes: without a password there is none to send, and only this computer can connect. |
| Public links and shared albums | Work as before, for those who can reach the address. |
| Docker, a demo site, single sign-on | No keys. Everything is as before. |
Two things are not new and not solved here. Cookies do not know ports, so another program on localhost that the owner opens in the same browser gets them, with or without a password. And until the first account exists, whoever opens the page first creates it; without a password that now needs a key.
Proof
verification/platform/OwnComputer.tla has the keys, the accounts, the switch and a crash at every step. It shows that the address is never open without a password, that nobody but the owner's browser gets in, that the owner always does, that nobody chooses a new password without the confirmation of Windows or the Mac, that nobody sees the photos after a pause or a new start where the computer asks each time, and that the last choice holds after every start. Eight mutations fail: signing in everybody on this computer, a key that works twice, opening the address before the password is stored, trusting the stored choice alone, not storing it, making a reset token without a confirmation, letting an old sign-in go on where the computer should ask, and letting the key in alone there.