On the session id type and overriding it's value #192
Replies: 2 comments 2 replies
-
Because there's no guarantee that an ID will be securely generated. Put another way: any
As in this case, it entirely depends on the secure nature of the database's UUID generation method: UUIDv4 does not require its random bits be securely generated and so this will depend on the specific implementation. Whereas calling In the interest of promoting better security, we'll likely make this field private and only available via an accessor in the future. |
Beta Was this translation helpful? Give feedback.
-
It seems most stores in |
Beta Was this translation helpful? Give feedback.
-
Hi,
I've started implementing a store for tokio-postgres.
Internally tower-sessions session id is a i128, which altough it's behind a newtype, the inner value is accessible. We use UUID primary keys in our databases, which are also 128-bit. When create() is called by tower-sessions I insert the record letting the database generate a uuid primary key, which I then in rust convert to a i128 and replace the session id with. That way when load() or save() is called I can convert the session id to a UUID again and query the database using the primary key.
This approach should avoid the id collision issue, and reduces the complexity of the database table. But I noted the todo comment in
tower-sessions-core/session.rs:876
mentioning that the store being able to override the id is undesireable.Should I expect this approach to not be compatible with future releases of tower-session? Why is it undesirable to let the store implementer pick the session id? I thought it was a rather neat way to do it.
Beta Was this translation helpful? Give feedback.
All reactions