Skip to content

Commit

Permalink
Un-hardcode auth cookie domain
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Oct 3, 2023
1 parent e5e18dd commit 02a0c8f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions superset/utils/machine_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import logging
from typing import Any, Callable, TYPE_CHECKING
from urllib.parse import urlparse

from flask import current_app, Flask, request, Response, session
from flask_login import login_user
Expand All @@ -45,8 +46,10 @@ def __init__(
auth_webdriver_func_override: Callable[[WebDriver, User], WebDriver],
auth_context_func_override: Callable[[BrowserContext, User], BrowserContext],
):
# This is here in order to allow for the authenticate_webdriver func to be
# overridden via config, as opposed to the entire provider implementation
# This is here in order to allow for the authenticate_webdriver
# or authenticate_browser_context (if PLAYWRIGHT_REPORTS_AND_THUMBNAILS is
# enabled) func to be overridden via config, as opposed to the entire
# provider implementation
self._auth_webdriver_func_override = auth_webdriver_func_override
self._auth_context_func_override = auth_context_func_override

Expand Down Expand Up @@ -82,6 +85,8 @@ def authenticate_browser_context(
if self._auth_context_func_override: # type: ignore
return self._auth_context_func_override(browser_context, user)

url = urlparse(current_app.config["WEBDRIVER_BASEURL"])

# Setting cookies requires doing a request first
page = browser_context.new_page()
page.goto(headless_url("/login/"))
Expand All @@ -94,7 +99,7 @@ def authenticate_browser_context(
{
"name": cookie_name,
"value": cookie_val,
"domain": "0.0.0.0",
"domain": url.netloc,
"path": "/",
"sameSite": "Lax",
"httpOnly": True,
Expand Down

0 comments on commit 02a0c8f

Please sign in to comment.