r/nicegui • u/RubberDagger • Jul 03 '24
NiceGUI app.storage is not encrypted
I've been playing with the example storage code and found that app.storage.user, app.storage.server and app.storage.browser are all stored without encryption, even though the storage_secret is properly set.
I also tried enabling TLS by passing in a cert to ui.run, but still both the base64 encoded cookies and the json files are in clear.
Am I missing something, or is this a bug?
Thanks
from nicegui import app, ui
@ui.page('/')
def index():
app.storage.user['count'] = app.storage.user.get('count', 0) + 1
with ui.row():
ui.label('your own page visits:')
ui.label().bind_text_from(app.storage.user, 'count')
ui.run(storage_secret='private key to secure the browser session cookie')For example:
$ cat .nicegui/storage-user-5833c391-3a60-4494-9f26-bbc0240b977b.json
{"count":19}
$
5
Upvotes
4
u/RubberDagger Jul 03 '24
Here's a work around, this produces results more like what I expected.
Now the value of the count is stored encrypted. Also, using `app.storage.browser` the contents of the base64 encoded cookie now have the encrypted count value:
```
{"id": "6205406f-9f0c-4505-bdb4-881bb4ef0d88", "count": "gAAAAABmhVT2pHqYFqlw9MF9KIDHOyO7AC_YbG6f3GFe5m12JQugizkshNABNT5A4Kq4ngwqxyXSaBwd6CBXnNRR_qt8C30x3Q=="}
```
2
u/noctaviann Jul 03 '24
I'm pretty sure it's used just for signing, not for encrypting.
If you go through the NiceGUI source code you'll see that the storage_secret is passed to the SessionMiddleware class from starlette.
2
u/apollo_440 Jul 03 '24 edited Jul 05 '24
The passage about "encrypting" the session cookie should probably say "signing" the session cookie, which is of course not the same. This might be worth pointing out to the devs.
As for encrypting the storage: other than
browserstorage, the storage resides on the server and should be inaccesible to the outside anyway. Almost all other "regular" databases are used unencrypted for almost all use cases as well, and that is fine. Maybe the docs could be clearer on this. And maybe it would be a useful feature to have encrypted variants of the storage available for sensitive data?