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

Added a httponly option for HTMLResponse.set_cookie #876

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions solara/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Config:

class Session(BaseSettings):
secret_key: str = SESSION_SECRET_KEY_DEFAULT
http_only: bool = False
https_only: Optional[bool] = None
same_site: str = "lax"

Expand Down
2 changes: 2 additions & 0 deletions solara/server/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ async def root(request: Request, fullpath: str = ""):
session_id = request.cookies.get(server.COOKIE_KEY_SESSION_ID) or str(uuid4())
samesite = "lax"
secure = False
httponly = settings.session.http_only
# we want samesite, so we can set a cookie when embedded in an iframe, such as on huggingface
# however, samesite=none requires Secure https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
# when hosted on the localhost domain we can always set the Secure flag
Expand All @@ -469,6 +470,7 @@ async def root(request: Request, fullpath: str = ""):
expires="Fri, 01 Jan 2038 00:00:00 GMT",
samesite=samesite, # type: ignore
secure=secure, # type: ignore
httponly=httponly, # type: ignore
) # type: ignore
return response

Expand Down