Skip to content

Commit 3d927c1

Browse files
committed
fix: sanitize null origin
1 parent f1731eb commit 3d927c1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fastapi_sio/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
import re
55

66

7+
def match_origin(origin: str | None, pattern: str) -> bool:
8+
"""
9+
Matches origin against a pattern.
10+
"""
11+
return origin is not None and re.match(pattern, origin) is not None
12+
13+
14+
715
def find_cors_configuration(app: FastAPI, default: Any) -> Any:
816
"""
917
Looks through FastAPI's middlewares to figure
@@ -23,6 +31,6 @@ def find_cors_configuration(app: FastAPI, default: Any) -> Any:
2331

2432
origins_regex = middleware.options.get("allow_origin_regex")
2533
if origins_regex:
26-
return lambda value: re.match(origins_regex, value) is not None
34+
return lambda origin: match_origin(origin, origins_regex)
2735

2836
return default

0 commit comments

Comments
 (0)