Skip to content

[test] Guard server cookie names against Community Cloud cookie filtering#15474

Open
sfc-gh-kmcgrady wants to merge 3 commits into
developfrom
add-cookie-allowlist-guard-test
Open

[test] Guard server cookie names against Community Cloud cookie filtering#15474
sfc-gh-kmcgrady wants to merge 3 commits into
developfrom
add-cookie-allowlist-guard-test

Conversation

@sfc-gh-kmcgrady

Copy link
Copy Markdown
Contributor

Describe your changes

The Streamlit Community Cloud proxy only forwards an allowlist of known cookies to the app; any cookie not on that allowlist is stripped from the request before it reaches the app pod. A newly added server cookie therefore works locally but silently breaks on Community Cloud — which is exactly what happened to st.login once the OAuth handshake started relying on the _streamlit_session cookie (issue #15455).

This PR adds a lightweight regression guard so the coupling is caught at PR time instead of in production:

  • Guard test (starlette_server_config_test.py): asserts the set of server cookie names matches an explicit expected set. Adding or renaming a cookie fails the test with a message telling the developer to ensure the new cookie is allowlisted by the Community Cloud proxy first.
  • Comment at the cookie-name definitions in starlette_server_config.py documenting the requirement.

No behavior change — this is test/documentation only. The actual Community Cloud allowlist update for _streamlit_session is handled separately in the Cloud infra repo.

Cookie inventory (current Starlette server)

Cookie Type
_streamlit_user chunked
_streamlit_user_tokens chunked
_streamlit_xsrf single
_streamlit_session single

GitHub Issue Link (if applicable)

Related to #15455

Testing Plan

  • New unit test test_server_cookie_names_match_cloud_allowlist passes; lint/format clean.

…ring

The Streamlit Community Cloud proxy only forwards an allowlist of known
cookies to the app; any cookie not on it is stripped before reaching the
app. A newly added cookie therefore works locally but silently breaks on
Community Cloud, which is what broke st.login via the _streamlit_session
cookie.

Add a guard test that fails when the set of server cookie names changes,
plus a comment at the cookie definitions, so the allowlist requirement is
caught at PR time instead of in production.
@snyk-io

snyk-io Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-15474/streamlit-1.58.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-15474.streamlit.app (☁️ Deploy here if not accessible)

@kmcgrady kmcgrady added impact:internal PR changes only affect internal code change:chore PR contains maintenance or housekeeping change labels Jun 8, 2026
The guard previously listed the cookie constants by hand, so it only
caught renames -- a newly added *_COOKIE_NAME constant would not appear
in the actual set and the test would still pass. Discover every
*_COOKIE_NAME constant from the module instead, and document the
convention at the definitions.
@kmcgrady kmcgrady marked this pull request as ready for review June 8, 2026 22:49
Copilot AI review requested due to automatic review settings June 8, 2026 22:49
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a regression guard to catch server cookies that aren't on the Community Cloud proxy allowlist. It is a test-and-comment-only change with no behavior impact.

  • Guard test (starlette_server_config_test.py): introspects the starlette_server_config module at test time, collects every *_COOKIE_NAME constant via vars(), and asserts exact equality against the known-allowlisted set — catching any addition or rename at PR time.
  • Source comment (starlette_server_config.py): documents the naming convention and the Cloud-proxy requirement so future contributors understand why every new cookie name must be defined there and checked against the allowlist before being merged.

Confidence Score: 5/5

Test-and-comment-only change; no production code paths are modified.

The change is purely additive — a new test file and a source comment. The guard logic (introspecting module constants via vars()) is correct, and the expected cookie set matches the four constants actually defined in the module. There are no runtime behavior changes and no risk of regression.

No files require special attention.

Important Files Changed

Filename Overview
lib/streamlit/web/server/starlette/starlette_server_config.py Adds an explanatory comment block documenting the Community Cloud cookie allowlist requirement; no functional changes.
lib/tests/streamlit/web/server/starlette/starlette_server_config_test.py New test file: discovers all *_COOKIE_NAME constants in the module via vars() and asserts they match an explicit expected set, guarding against unallowlisted cookies slipping through on Community Cloud.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Developer adds a cookie in starlette_server_config.py] --> B{Uses COOKIE_NAME suffix?}
    B -->|Yes| C[Guard test discovers it via vars]
    B -->|No| G[Guard misses it - covered by docstring convention]
    C --> D{Name in expected_cookie_names?}
    D -->|Yes| E[Test PASSES]
    D -->|No| F[Test FAILS - prompts dev to update Cloud allowlist first]
    F --> H[Dev confirms allowlist updated in Cloud infra repo]
    H --> I[Update expected_cookie_names and merge]
Loading

Reviews (2): Last reviewed commit: "Reword cookie-allowlist comment to remov..." | Re-trigger Greptile

Comment thread lib/streamlit/web/server/starlette/starlette_server_config.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a regression guard to prevent new/renamed Starlette server cookies from silently breaking on Streamlit Community Cloud due to proxy cookie allowlisting, by pinning the expected set of server cookie names in a unit test and documenting the convention in the server config module.

Changes:

  • Added a unit test that discovers all *_COOKIE_NAME constants in starlette_server_config and asserts they match an explicit expected set.
  • Documented the “define cookie names here + ensure Cloud proxy allowlist” requirement next to the cookie-name constants.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/tests/streamlit/web/server/starlette/starlette_server_config_test.py Adds a guard test that fails when server cookie names change, prompting Cloud allowlist verification.
lib/streamlit/web/server/starlette/starlette_server_config.py Adds an inline comment documenting the cookie-name convention and the Community Cloud proxy constraint.

Comment on lines +58 to +62
assert actual_cookie_names == expected_cookie_names, (
"Server cookie names changed. Ensure the new cookie is allowlisted by "
"the Streamlit Community Cloud proxy before updating this test, or it "
"will be stripped on Cloud."
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified this isn't the case with pytest 9.x: a custom message and the set-diff introspection both appear on failure (e.g. Extra items in the left set: '_streamlit_foo'). The message isn't suppressing the diff — it adds the actionable allowlist guidance on top of it, so keeping it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:chore PR contains maintenance or housekeeping change impact:internal PR changes only affect internal code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants