-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support automatic server-side encryption of Dash props #262
Comments
@nicolaskruchten Can this be closed now that dash-core-components has a new |
No, because the data stored there is still unencrypted :) |
Hi guys, Nice to see this discussion. This is exactly what I am looking for, a dcc.Store that has the capability to encrypt and decrypt its data, and it will probably help a lot of developers |
@AnnMarieW will |
No, this feature is still not available, but I could see how it could be useful. |
Gonna pop in here, encryption is a good thought, but what has to do the decrypting?
A couple of notes:
|
cc @ndrezn what do you think? |
@nicolaskruchten could you explain your Though to be honest I'm not totally sure whether automatic encryption of The use case I can imagine is if you want to store your complete dataset in Here's a small example showing something similar to @nicolaskruchten's PR implementation but in this case using callbacks + Code snippetfrom dash import dcc, html, Input, Output, State, callback, Dash, no_update
from cryptography.fernet import Fernet
import base64
# Generate a key for encryption and decryption
key = Fernet.generate_key()
cipher_suite = Fernet(key)
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Input(
id="input-data",
type="text",
placeholder="Enter data to encrypt",
style={"marginBottom": "10px"},
),
html.Button("Submit", id="submit-button", n_clicks=0),
dcc.Store(id="encrypted-store"),
html.Div(id="output"),
]
)
@callback(
Output("encrypted-store", "data"),
Input("submit-button", "n_clicks"),
State("input-data", "value"),
)
def encrypt_data(n_clicks, value):
if n_clicks > 0 and value:
encrypted_data = cipher_suite.encrypt(value.encode())
# Encode to base64 to store in dcc.Store
encoded_data = base64.b64encode(encrypted_data).decode()
return encoded_data
return no_update
@callback(Output("output", "children"), Input("encrypted-store", "data"))
def decrypt_data(encoded_data):
if encoded_data:
# Decode from base64 and decrypt
encrypted_data = base64.b64decode(encoded_data)
decrypted_data = cipher_suite.decrypt(encrypted_data).decode()
return f"Encrypted data: {encoded_data}\n Decrypted data: {decrypted_data}"
return "No data stored"
if __name__ == "__main__":
app.run_server(debug=True) |
the transform/inverse thing was in a comment from Chris in my initial PR #254 |
The idea here was to provide a first-class/recommended way of doing things that doesn't require users to copy-paste boilerplate around. |
For my own reference, @chriddyp puts the use case well in: https://community.plotly.com/t/writing-secure-dash-apps-community-thread/54619
|
What if Plotly added support for Server Side stores, much like Also, another thing to point out for a dcc.Store and encrypting on the server, you wouldnt be able to utilize the data on the browser via a clientside callback. So, the point of even having the data go to the client doesnt make much sense. This of course would be different if for some reason you wanted to send the data via an api call by the client... |
Enable e.g.
dcc.Store
to encrypt/decrypt itsdata-*
props on the server, and possibly expand to other components.#254 was a first cut at implementing this in
dash.py
and some design discussion is available there. It seems like the way forward here is to make the base component class extensible with server-sidetransform
/inverse_transform
extension points.@chriddyp is there an existing issue that captures other needs/thoughts around the base component extension idea?
The text was updated successfully, but these errors were encountered: