mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-23 23:20:51 +01:00
Investigate user.db fields and their purpose #210
Labels
No labels
area:database
awaiting-feedback
backend
blocked
breaking change: web api
bug
build
ci
confirmed
discussion needed
dotnet future
downstream
duplicate
EFjellyfin.db
enhancement
feature
future
github-actions
good first issue
hdr
help wanted
invalid
investigation
librarydb
live-tv
lyrics
media playback
music
needs testing
nuget
performance
platform
pull-request
question
regression
release critical
requires-web
roadmap
security
security
stale
support
syncplay
ui & ux
upstream
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: starred/jellyfin#210
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sparky8251 on GitHub (Jan 6, 2019).
This is part of #42, potentially #302, and maybe even #422 .
So far, this is what I've found:
The
users.dbhas 3 fields in theLocalUsersv2table.Id, which contains anINTEGERrepresentation of your user Id. This is the master key.guid, which contains aGUIDthat upon initial investigation is derived from theIddata, which contains aBLOBthat really should be more individual fields.The data blob itself contains a lot of fields. Extracted from my own db and prettyfied, it looks like this:
Of all these fields so far, the following warrant some degree of further investigation:
guidHow is it generated and what is it actually used for? Can it be removed? If it cannot, can we convert it to the sqlite typeINTEGER?UsesIdForConfigurationPathWhat does it toggle if set to false? Can it be removed?ImageInfosWhy is it a vector? If it can be converted to a single element, we should be able to break out more of the blob into its own fields.PathWe should find how it generates the random bit and fix the FQPNs so the database is more portable.TypeIs this whyImageInfosa vector? Can you have second or third photos attached to your user account? Can it be removed?DateModifiedWhy do we need to know when an image was set? Can it be removed?WidthI have an image set but this is still 0. Why? Can it be removed?HeightI have an image set but this is still 0. Why? Can it be removed?InternalIdis this always set to be identical to theIdfield? Can it be removed?RemoteTrailersWhat is this? Why is it attached to user accounts? Why is it a vector? Can it be removed?IsHDWhat is this? Why is it attached to user accounts? Can it be removed?IsShortcutWhat is this? Why is it attached to user accounts? Can it be removed?WidthWhy is this repeating and set to 0 even though I have an icon set? Can it be removed?HeightWhy is this repeating and set to 0 even though I have an icon set? Can it be removed?ExtraIdsWhat is this? Why is it a vector? Can it be removed?SupportsExternalTransferWhat is this? Can it be removed?As we track down where and why these things exist, we should look at creating a
LocalUsersv3table format that doesn't rely on a single large blob. Will make future migrations to new formats much easier. When this eventually leads to a new table format, we should make ajellyfin.dbfile to store the new table and eventually roll the other dbs into it.@ploughpuff commented on GitHub (Jan 10, 2019):
A little digging into the use of GUID in users table.
To quote Microsoft (docs here):
A GUID is created for each new user but this 8-4-4-4-12 representation of it is never seen/used.
Instead, the GUID stored in 'guid' element of the table is the 16-byte encoding of it (GUID.ToByteArray).
Other uses are the hyphen-less representation (GUID.ToString("N"), see docs). An example can be seen when editing your profile. Here it's called userId:
http://localhost:8096/web/index.html#!/myprofile.html?userId=61f49567708f4c1b9905b4bd70799f8e
This hyphen-less GUID is also used to create a folder under /etc/jelly/users (-configdir/users), where the users profile picture, profile xml and config files are stored.
The GUID is not based on Id. My understanding being it uses date/timestamp to generate a unique number. Create a user, delete user, and create again and you'll get a different GUID.
Yes, we could remove it. The first field in the table 'Id' is unique and identifies the user sufficiently. The same could be argued for the user name as that's unique too.. My only question before removal would be what benefits does a 32 letter identifier offer us?
@sparky8251 commented on GitHub (Jan 10, 2019):
Thank you @ploughpuff ! These kinds of write ups right here is what I was hoping for if I opened these database investigation issues.
I see the the GUID is used as a string in other DBs tables (like user prefs and library), so at the very least removing it would touch more than this one DB. Might be why it was made in the first place.
If it really isnt required for the other DBs, could the psuedorandomness of the GUID be a useful security layer or is it just needless obscuration?
@sparky8251 commented on GitHub (Jan 10, 2019):
One thing of note here, the GUID key and the user GUID you specifically mentioned are different in my case.
Opening the db up, the raw hex for the GUID key is
b7cd3fe228571d4194fe4e498ad00ea3while the guid used in the user specific pages and image path ise23fcdb75728411d94fe4e498ad00ea3.Is the
e23derived from the "master" GUID key? If so, why? Can we just remove one and keep the other? Etc.@ploughpuff commented on GitHub (Jan 10, 2019):
They are the same :)
https://dotnetfiddle.net/2MYiW4
The GUID "b7cd3fe228571d4194fe4e498ad00ea3" is the 16 element byte array:
https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray?view=netframework-4.7.2
@sparky8251 commented on GitHub (Jan 10, 2019):
Good lord that is confusing... Thanks for looking into it! Still got a long ways to go...
@LogicalPhallacy commented on GitHub (Feb 1, 2019):
Replacing GUIDs with integers would likely result in a perf increase (MS SQL Server and some of the other bigger SQL implementations have a GUID typing, but the way jellyfin handles them int will almost always be cleaner). It would require a bit of db conversion type things, it offers no security benefit due to the way auth is implemented.
I think there is a valid argument for keeping the blob format for a users table as it greatly insulates against injection, but the work to port to entity framework would do so as well.
@cvium commented on GitHub (Feb 1, 2019):
Doesn't it already use some (probably bastardized) version of prepared statements? So I think we're OK wrt. injection?
@sparky8251 commented on GitHub (Feb 1, 2019):
Well, I'd say if the case for JSON blobs in the database is "Well, what about injection?" we should seek to solve the injection issues higher up the stack.
@stale[bot] commented on GitHub (Jul 29, 2019):
Issues go stale after 60d of inactivity. Mark the issue as fresh by adding a comment or commit. Stale issues close after an additional 7d of inactivity. If this issue is safe to close now please do so. If you have any questions you can reach us on Matrix or Social Media.