[Bug]: QR codes not working perfectly
Before reporting
- [x] I am running the latest version of DVinyl.
- [x] I searched the existing issues and did not find a duplicate.
What happened?
The QR codes option has a few issues.
- In the vinyl collection it generates a QR code but the url starts with "http" this should be "https" in ( I hope) most cases. I have set the environment variable to production since I am using https (behind a proxy server).
- In the custom made collections the problem is a little different. It also creates a "http" url but also the qr code image is not a valid image.
- In the custom collections the QR link can not be deleted. It display a "404" error.
Furthermore I noticed only admins can generate a QR code. I normally never use the program as an admin. The admin account is only used to change the database setup. Under normal circumstances I usually work as an editor (in all programs) to avoid catastrophic unintended mistakes. So it would be great if regular users could also create an QR code.
Steps to reproduce
Make an QR code as descibed.
Expected behavior
No response
DVinyl version
3.1.3
How are you running DVinyl?
Docker (pre-built image)
Affected media type or plugin
No response
Browser and device
No response
Logs or screenshots
Hi,
Thanks for the report!
I will look at this asap
Dug into this - opened a fix in #113.
Root cause
The share link / QR code URL is built with req.protocol
(routes/adminRoutes.ts), which only reports https when:
- Express
trust proxyis set (this app only does that whenPROD=true, seeapp.ts), and - the reverse proxy in front of the app actually sends an
X-Forwarded-Proto: httpsheader on every request.
If either of those isn't true, req.protocol silently falls back to
http - even though the site is genuinely served over HTTPS. #113
makes the app trust PROD=true directly instead of depending on the
forwarded header, so this can't happen anymore regardless of proxy
config.
How to set up HTTPS correctly (for anyone hitting this)
In .env:
PROD=true
Note it must be the literal string true, not production or
anything else - the app does a strict === 'true' check.
If you're behind a reverse proxy (nginx, Caddy, Traefik, etc.), make sure it forwards the original protocol, e.g. for nginx:
proxy_set_header X-Forwarded-Proto $scheme;
This is already called out in docs/getting-started.md, but easy to
miss.
The other two symptoms in this issue
I could not reproduce the "QR code image is not a valid image" or the
"404 on deleting a QR link" for custom (non-default) collections
against current main. Set up a local test instance (in-memory
MongoDB, fresh DB) and created a second custom collection alongside
the default one specifically to check this - share link creation,
QR code, and delete all worked normally on the custom collection.
My best guess is these were already fixed by earlier commits
(fbe3e58 "stop serving the QR code of a share link that was switched
off", 0fdc5c3 "report a delete that removed nothing") that landed
after whatever version you were testing on. If you still see either of
those two on latest main, could you post the exact repro steps and,
if possible, the HTTP status code + response body from the browser's
Network tab for the failing request? That'll make it much faster to
track down if it's still there.
Thank you!!
The X-Forwarded-Proto: https fixed the first problem. So thanks for that one.
The other problem still exists though. I will try to reproduce it with an temporary collection. And YES the "whatever version you were testing on" is the latest version 3.1.3 as stated in the bug report above.
What is the 'other problem'? I'll take a look!
I hadn't noticed the note that “only user admins can generate links.” Personally, I think it’s too risky to let regular “editors” generate these links. There’s also a big difference between a collection admin and an instance-wide admin.. The latter can indeed be dangerous! you're 100% right to not use this account. The thing is, collection admins don’t have enough permissions to perform irreversible actions across the entire app.. I think it's up to them to create the links: they own their collection, so they're the ones who decide whether or not to share it 🤷♂️
The other problem is point 2 & 3 Siebe-Uy could not reproduce. As far as I can tell it has something to do with the X-Forwarded-Proto as well. I could reproduce the error with the the QR image exactly one more time. After that is seems to be working fine. The strange thing is that remains: I have two collections with the broken QR image. Those can not be deleted, it results in the error as mentioned in point 3. I guess it has something to do with the fact that the server tries to delete the broken image? Guess I have revert to a backup to fix this.
The admin point is arguably valid. I had not realized the "instance admin" is different from the "collection admin". They both are listed as admin in the user list. I will change some users to "collection admin"
I'll look into it. Since I didn't write this feature, I'll need a little more time to debug it xD
Oh and normally, an admin at the instance level has a little badge! I hope that helps
Found it! and it's a bug, nothing to do with the proxy this time. Share links get a random code, and every now and then that code happens to contain two letters that DVinyl mistakes for one of its sections. When that section is turned off in the collection you're browsing, the QR image and the delete button both land on a 404. That's exactly why it only hit some of your links and not others.
The same thing can happen to a collection you're trying to delete, which explains your two stuck ones
I'm fixing it for the next release. No need to revert to a backup, they'll delete just fine once it's in! Thanks again
Thanks for pinpointing this so fast.
And I did notice the "instance" badge but did not link it to the difference in admin rights.
Found it! and it's a bug, nothing to do with the proxy this time. Share links get a random code, and every now and then that code happens to contain two letters that DVinyl mistakes for one of its sections. When that section is turned off in the collection you're browsing, the QR image and the delete button both land on a 404. That's exactly why it only hit some of your links and not others.
The same thing can happen to a collection you're trying to delete, which explains your two stuck ones
I'm fixing it for the next release. No need to revert to a backup, they'll delete just fine once it's in! Thanks again
Oh wow that is an insanely simple bug but hard to spot, great job fixing :)
Hi! I just released version 3.1.4, and all three of these are fixed :D
Feel free to reopen the issue if you run into any problems!!
I can confirm, all issues are resolved. Thanks, great work.