Skip to content

Commit ed3eef0

Browse files
authored
Disable XSRF protection in StreamlitFrontend to support upload in localhost (#15684)
* Enable CORS in StreamlitFrontend to support upload * Only disable XSRF when running on localhost * Update test * Use utility fn to detect if localhost Co-authored-by: Luca Antiga <[email protected]>
1 parent aef94ce commit ed3eef0

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/lightning_app/frontend/stream_lit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import lightning_app
88
from lightning_app.frontend.frontend import Frontend
9+
from lightning_app.utilities.cloud import is_running_in_cloud
910
from lightning_app.utilities.imports import requires
1011
from lightning_app.utilities.log import get_logfile
1112

@@ -83,6 +84,8 @@ def start_server(self, host: str, port: int) -> None:
8384
self.flow.name,
8485
"--server.headless",
8586
"true", # do not open the browser window when running locally
87+
"--server.enableXsrfProtection",
88+
"true" if is_running_in_cloud() else "false",
8689
],
8790
env=env,
8891
stdout=stdout,

tests/tests_app/frontend/test_stream_lit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def test_streamlit_frontend_start_stop_server(subprocess_mock):
5454
"root.my.flow",
5555
"--server.headless",
5656
"true",
57+
"--server.enableXsrfProtection",
58+
"false",
5759
]
5860

5961
assert env_variables["LIGHTNING_FLOW_NAME"] == "root.my.flow"

0 commit comments

Comments
 (0)