Skip to content

Commit 9bb02ee

Browse files
authored
Merge pull request #6 from TaskarCenterAtUW/tighten-regex
Tighten tenant bypass for tenantless endpoints
2 parents b1290c0 + 8671bc3 commit 9bb02ee

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

api/main.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,13 @@ def get_workspace_repository(
140140
"forwarded",
141141
}
142142

143-
# Define paths that do not require X-Workspace header
144-
AUTH_WHITELIST_PATTERNS = [
145-
re.compile(p)
146-
for p in [
147-
# Creating/deleting workspaces and JOSM path rewriting:
148-
r"^/api/0\.6/workspaces.*$",
149-
# Provisioning users during authentication:
150-
r"^/api/0\.6/user/.*$",
151-
]
143+
# Paths that do not require X-Workspace header, scoped by HTTP method. Each
144+
# entry is a tuple of: (compiled regex, set of allowed methods).
145+
TENANT_BYPASSES: list[tuple[re.Pattern[str], set[str]]] = [
146+
# Creating/deleting a workspace (no tenant context applies):
147+
(re.compile(r"^/api/0\.6/workspaces/\d+$"), {"PUT", "DELETE"}),
148+
# Provisioning users during authentication:
149+
(re.compile(r"^/api/0\.6/user/[^/]+$"), {"PUT"}),
152150
]
153151

154152

@@ -225,7 +223,10 @@ async def catch_all(
225223
detail="You do not have access to this workspace",
226224
)
227225
else:
228-
if not any(p.fullmatch(request.url.path) for p in AUTH_WHITELIST_PATTERNS):
226+
if not any(
227+
p.fullmatch(request.url.path) and request.method in methods
228+
for p, methods in TENANT_BYPASSES
229+
):
229230
raise HTTPException(
230231
status_code=status.HTTP_400_BAD_REQUEST,
231232
detail="No X-Workspace header supplied",

0 commit comments

Comments
 (0)