Skip to content
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

[REF-1943] Backend variables should not be accessible to render #2559

Open
wassafshahzad opened this issue Feb 8, 2024 · 11 comments · Fixed by #2618
Open

[REF-1943] Backend variables should not be accessible to render #2559

wassafshahzad opened this issue Feb 8, 2024 · 11 comments · Fixed by #2618
Labels
linear Created by Linear-GitHub Sync

Comments

@wassafshahzad
Copy link
Contributor

wassafshahzad commented Feb 8, 2024

Description

Working on the issue #1154, we discovered that the backend variables are accessible to the frontend which they should not be.

###Steps to reproduce the behavior:
Run the following code

import random
import reflex as rx

class State(rx.State):

    _private: str = "Should work ?"


def index() -> rx.Component:
    return rx.vstack(
        rx.heading(f"Computed BE {State._private}"),
        spacing="1.5em",
        font_size="2em",
        padding_top="10%",
    )


app = rx.App()
app.add_page(index)

###Expected behavior
Backend vars should not be accessible to frontend

Specifics (please complete the following information):

  • Python Version: 3.12.1
  • Reflex Version: development version
  • OS: Windows
  • Browser (Optional):

Additional context
Linked PR #2540

REF-1943

@benedikt-bartscher
Copy link
Contributor

@wassafshahzad your example code throws an exception: TypeError: cannot pickle 'ComputedVar' object. One could argue that this isn't a nice exception, but it does not seem like a bug.

@wassafshahzad
Copy link
Contributor Author

@wassafshahzad your example code throws an exception: TypeError: cannot pickle 'ComputedVar' object. One could argue that this isn't a nice exception, but it does not seem like a bug.

On the dev version ?

@wassafshahzad
Copy link
Contributor Author

wassafshahzad commented Feb 9, 2024

@wassafshahzad your example code throws an exception: TypeError: cannot pickle 'ComputedVar' object. One could argue that this isn't a nice exception, but it does not seem like a bug.

I updated the example, I was working with his example on my local branch and it had some changes which prevented the above exception. Now the example should run

@benedikt-bartscher
Copy link
Contributor

You are right, your example renders a backend-var to the frontend, which should not be possible. Tested with main branch and reflex v0.3.10

@picklelo picklelo added the linear Created by Linear-GitHub Sync label Feb 12, 2024
@picklelo picklelo changed the title Backend variables should not be accessible to render [REF-1943] Backend variables should not be accessible to render Feb 12, 2024
@picklelo picklelo added this to the v.21 milestone Feb 12, 2024
@wassafshahzad
Copy link
Contributor Author

For prosperity
I believe I have discovered the issue.
I am currently using the following example taken from reflex and as you can see in the attached screenshots the dict function is correctly filtering out private vars. Thus the private state is not sent to the front end. What I believe happens is the following

During compiling the component calls it respective create method and the children passed to it through State and the private var is availble in the dunder dict method , it just returns it as a string literal or any base python type.
In the above example during the create method of stat_label it receives children "APPL" as a string literal since its not a BaseVar However in case of stat_number it receives a BaseVar instance with the respective meta data.

###Solution,
I propose the following solutions

  • We don't allow private variables to be places in the dict of a State on class level effetely making it so it doesn't exist on a class level.
  • The better solution would be to add specific VarDate during creation of backend variables and raise the ap[proriate error during Bare.create method or Var.create method
dict_function example_used final_state_dict_func

@picklelo picklelo modified the milestones: v.21, v.22 Feb 18, 2024
@wassafshahzad
Copy link
Contributor Author

PR is up and awaiting review

@masenf
Copy link
Collaborator

masenf commented Feb 21, 2024

PR seemed to have an issue #2681

@masenf masenf reopened this Feb 21, 2024
@benedikt-bartscher
Copy link
Contributor

@wassafshahzad I added some basic tests which fail against the problematic changes here: #2685
you can run them using pytest integration -k test_state_in

@wassafshahzad
Copy link
Contributor Author

@wassafshahzad I added some basic tests which fail against the problematic changes here: #2685
you can run them using pytest integration -k test_state_in

Thank you, I will fiz it tomorrow or later today

@wassafshahzad
Copy link
Contributor Author

PR seemed to have an issue #2681

Sorry, I will fix it later today

@picklelo picklelo modified the milestones: v.22, v.23 Feb 23, 2024
@masenf
Copy link
Collaborator

masenf commented Mar 1, 2024

Tabling this one for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants