Skip to content

Commit 2c3cc82

Browse files
committed
removes default product to avoid accidental cross-product login
1 parent 85c779c commit 2c3cc82

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

services/web/server/src/simcore_service_webserver/products/_middlewares.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import enum
12
import logging
23
from collections import OrderedDict
34

@@ -35,6 +36,14 @@ def _get_app_default_product_name(request: web.Request) -> str:
3536
return product_name
3637

3738

39+
class Sentinel(enum.StrEnum):
40+
UNSET = "UNSET"
41+
UNDEFINED = "UNDEFINED"
42+
43+
44+
_INCLUDE_PATHS: set[str] = {"/static-frontend-data.json", "/socket.io/"}
45+
46+
3847
@web.middleware
3948
async def discover_product_middleware(request: web.Request, handler: Handler):
4049
"""
@@ -45,17 +54,13 @@ async def discover_product_middleware(request: web.Request, handler: Handler):
4554
"""
4655
# - API entrypoints
4756
# - /static info for front-end
48-
if (
49-
request.path.startswith(f"/{API_VTAG}")
50-
or request.path == "/static-frontend-data.json"
51-
or request.path == "/socket.io/"
52-
):
53-
product_name = (
57+
if request.path.startswith(f"/{API_VTAG}") or request.path in _INCLUDE_PATHS:
58+
request[RQ_PRODUCT_KEY] = (
5459
_discover_product_by_request_header(request)
5560
or _discover_product_by_hostname(request)
56-
or _get_app_default_product_name(request)
61+
or Sentinel.UNDEFINED
62+
# FIXME: or _get_app_default_product_name(request)
5763
)
58-
request[RQ_PRODUCT_KEY] = product_name
5964

6065
# - Publications entrypoint: redirections from other websites. SEE studies_access.py::access_study
6166
# - Root entrypoint: to serve front-end apps
@@ -64,11 +69,20 @@ async def discover_product_middleware(request: web.Request, handler: Handler):
6469
or request.path.startswith("/view")
6570
or request.path == "/"
6671
):
67-
product_name = _discover_product_by_hostname(
68-
request
69-
) or _get_app_default_product_name(request)
72+
request[RQ_PRODUCT_KEY] = (
73+
_discover_product_by_hostname(request) or Sentinel.UNDEFINED
74+
)
75+
# FIXME: or _get_app_default_product_name(request)
7076

71-
request[RQ_PRODUCT_KEY] = product_name
77+
msg = "\n".join(
78+
[
79+
f"{request.url=}",
80+
f"{request.host=}",
81+
f"{request.headers=}",
82+
f"{request.get(RQ_PRODUCT_KEY)=}",
83+
]
84+
)
85+
_logger.warning("\n--TESTING->\n%s", msg)
7286

7387
assert request.get(RQ_PRODUCT_KEY) is not None or request.path.startswith( # nosec
7488
"/dev/doc"

services/web/server/tests/unit/isolated/test_products_middlewares.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def mock_app(mock_postgres_product_table: dict[str, Any]) -> web.Application:
7777
("https://ti-solutions.io/", "tis", "tis"),
7878
("https://osparc.io/", None, "osparc"), # e.g. an old front-end
7979
("https://staging.osparc.io/", "osparc", "osparc"),
80+
# new auth of subdomains. SEE https://github.com/ITISFoundation/osparc-simcore/pull/6484
81+
(
82+
"https://34c878cd-f801-433f-9ddb-7dccba9251af.services.s4l-solutions.com/notebooks/lab",
83+
"s4l",
84+
"s4l",
85+
),
8086
],
8187
)
8288
async def test_middleware_product_discovery(

0 commit comments

Comments
 (0)