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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable XSRF protection in StreamlitFrontend to support upload in localhost #15684

Merged
merged 9 commits into from Nov 22, 2022
3 changes: 3 additions & 0 deletions src/lightning_app/frontend/stream_lit.py
Expand Up @@ -62,6 +62,7 @@ def __init__(self, render_fn: Callable) -> None:

def start_server(self, host: str, port: int) -> None:
env = os.environ.copy()
is_localhost = "LIGHTNING_APP_STATE_URL" not in env
awaelchli marked this conversation as resolved.
Show resolved Hide resolved
env["LIGHTNING_FLOW_NAME"] = self.flow.name
env["LIGHTNING_RENDER_FUNCTION"] = self.render_fn.__name__
env["LIGHTNING_RENDER_MODULE_FILE"] = inspect.getmodule(self.render_fn).__file__
Expand All @@ -83,6 +84,8 @@ def start_server(self, host: str, port: int) -> None:
self.flow.name,
"--server.headless",
"true", # do not open the browser window when running locally
"--server.enableXsrfProtection",
"false" if is_localhost else "true",
],
env=env,
stdout=stdout,
Expand Down
2 changes: 2 additions & 0 deletions tests/tests_app/frontend/test_stream_lit.py
Expand Up @@ -54,6 +54,8 @@ def test_streamlit_frontend_start_stop_server(subprocess_mock):
"root.my.flow",
"--server.headless",
"true",
"--server.enableXsrfProtection",
"false",
]

assert env_variables["LIGHTNING_FLOW_NAME"] == "root.my.flow"
Expand Down