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

Fix error when encountering web pushkeys with missing endpoints #288

Merged
merged 4 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 changelog.d/288.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reject web pushkeys with missing endpoints instead of raising an error.
14 changes: 12 additions & 2 deletions sygnal/webpushpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, name: str, sygnal: "Sygnal", config: Dict[str, Any]):
)
self.http_request_factory = HttpRequestFactory()

self.allowed_endpoints = None # type: Optional[List[Pattern]]
self.allowed_endpoints: Optional[List[Pattern[str]]] = None
allowed_endpoints = self.get_config("allowed_endpoints", list)
if allowed_endpoints:
self.allowed_endpoints = list(map(glob_to_regex, allowed_endpoints))
Expand Down Expand Up @@ -149,6 +149,16 @@ async def _dispatch_notification_unlimited(
return []

endpoint = device.data.get("endpoint")
if not isinstance(endpoint, str):
# The pushkey is missing the endpoint for delivery.
logger.warn(
"Rejecting pushkey %s; "
"device.data.endpoint is missing or not a string: %r",
device.pushkey,
endpoint,
)
return [device.pushkey]

auth = device.data.get("auth")
endpoint_domain = urlparse(endpoint).netloc
if self.allowed_endpoints:
Expand Down Expand Up @@ -289,7 +299,7 @@ def _handle_response(
response: IResponse,
response_text: str,
pushkey: str,
endpoint_domain: bytes,
endpoint_domain: str,
) -> bool:
"""
Logs and determines the outcome of the response
Expand Down