From ecf98bf7f85fcfaae6046d043b740e200dc2bf6f Mon Sep 17 00:00:00 2001
From: Alan Grainger <16197738+alangrainger@users.noreply.github.com>
Date: Mon, 26 Jan 2026 21:01:58 +1300
Subject: [PATCH] #176 fix slug links with password protection
---
README.md | 2 +-
app/package.json | 2 +-
app/src/immich.ts | 15 ++++++++-------
app/src/index.ts | 12 ++++--------
4 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 3e4cec2..229df42 100644
--- a/README.md
+++ b/README.md
@@ -154,7 +154,7 @@ Alternatively, you can [pass the configuration inline](docs/inline-configuration
| `responseHeaders` | `object` | Change the headers sent with your web responses. By default there is `cache-control` and CORS added. |
| `singleImageGallery` | `bool` | By default a link to a single image will directly open the image file. Set to `true` if you want to show a gallery page instead for a single item. |
| `downloadOriginalPhoto` | `bool` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. |
-| `downloadedFilename` | `int` | The filename of the downloaded image.
`0` for the original filename if available, falling back to the Immich asset ID
`1` for the Immich asset ID number
`2` for a sanitised version of the asset ID: `img_` plus the first 8 characters of the asset ID |
+| `downloadedFilename` | `int` | The filename of the downloaded image.
`0` for the original filename if available, falling back to the Immich asset ID
`1` for the Immich asset ID number
`2` for a shortened version of the asset ID: `img_` plus the first 8 characters of the asset ID |
| `showGalleryTitle` | `bool` | Show a title on the gallery page. |
| `allowDownloadAll` | `int` | Allow visitors to download all files as a zip.
`0` disable downloads
`1` follow Immich setting per share ([example](https://github.com/user-attachments/assets/79ea8c08-71ce-42ab-b025-10aec384938a))
`2` always allowed |
| `allowSlugLinks` | `bool` | Enable/disable the custom URL links. |
diff --git a/app/package.json b/app/package.json
index d988bb3..d4bf3a8 100644
--- a/app/package.json
+++ b/app/package.json
@@ -1,6 +1,6 @@
{
"name": "immich-public-proxy",
- "version": "1.15.0",
+ "version": "1.15.1",
"scripts": {
"dev": "ts-node src/index.ts",
"build": "npx tsc",
diff --git a/app/src/immich.ts b/app/src/immich.ts
index 5668167..aa69c09 100644
--- a/app/src/immich.ts
+++ b/app/src/immich.ts
@@ -14,6 +14,7 @@ import { addResponseHeaders, canDownload, getConfigOption, log } from './functio
import render from './render'
import { Response } from 'express-serve-static-core'
import { respondToInvalidRequest } from './invalidRequestHandler'
+import { encrypt } from './encrypt'
class Immich {
/**
@@ -104,13 +105,13 @@ class Immich {
}
const link = sharedLinkRes.link
- // Make sure there are some photo/video assets for this link
- /*
- if (!link.assets.length) {
- log('No assets for key ' + request.key)
- respondToInvalidRequest(res, 404)
- return
- } */
+ // If this was a slug link, we need to also store session information for the ID-based key
+ if (request.req.session && !request.req.session[link.key]) {
+ request.req.session[link.key] = encrypt(JSON.stringify({
+ password: request.password,
+ expires: dayjs().add(1, 'hour').format()
+ }))
+ }
// Everything is ok - output the shared link data
diff --git a/app/src/index.ts b/app/src/index.ts
index 7c7a676..8f79885 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -95,6 +95,10 @@ app.get('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, async (req,
* [ROUTE] Receive an unlock request from the password page
* Stores a cookie with an encrypted payload which expires in 1 hour.
* After that time, the visitor will need to provide the password again.
+ *
+ * The data is encrypted/decrypted on the server as a db-less way of
+ * managing user session data. The data is provided to the server by the
+ * user's browser in its encrypted state.
*/
app.post('/share/unlock', async (req, res) => {
if (req.session && req.body.key) {
@@ -125,13 +129,6 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r
return
}
- /*
- This was the change made in PR https://github.com/alangrainger/immich-public-proxy/pull/174
- I have had to remove this because it was preventing password-protected slug albums
- from working.
-
- This will be added back in once the slug issue is solved.
-
// Validate share link and check password before serving assets
// This prevents direct URL access from bypassing password protection
// The password is provided from the encrypted session cookie (if set)
@@ -153,7 +150,6 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r
respondToInvalidRequest(res, 404, 'Asset not found in share')
return
}
- */
const request = {
req,