-
Notifications
You must be signed in to change notification settings - Fork 153
Check if default_payload
is a dict before using it as a dict
#292
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ce39916
check if default_payload is a dict before using it as a dict
H-Shay fb3fef3
newfragment
H-Shay f4f00bd
update newsfrag number
H-Shay e614955
reword newsfragement
H-Shay 9326ad6
reject pushkey if default_payload is malformed
H-Shay d37df57
add tests to ensure that pushkey is being rejected in case where defa…
H-Shay 9c23331
Merge branch 'shay/fix_type_error' of https://github.com/matrix-org/s…
H-Shay 816d29a
lints
H-Shay dda2a70
lint
H-Shay 246c040
reword message to avoid conflict between black and flake8
H-Shay 8ced381
flake8
H-Shay 83a1bf0
isort
H-Shay 4dcd56f
requested changes
H-Shay e3be4c6
requested changes
H-Shay d349c18
refactor
H-Shay 1d80bc9
appease mypy god
H-Shay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a bug introduced in Sygnal 0.7.0 where a malformed `default_payload` could cause an internal server error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
8000
|
@@ -283,10 +283,22 @@ async def _dispatch_notification_unlimited( | |
with self.sygnal.tracer.start_span( | ||
"apns_dispatch", tags=span_tags, child_of=context.opentracing_span | ||
) as span_parent: | ||
# Before we build the payload, check that the default_payload is not | ||
# malformed and reject the pushkey if it is | ||
|
||
default_payload = {} | ||
|
||
if device.data: | ||
default_payload = device.data.get("default_payload", {}) | ||
if not isinstance(default_payload, dict): | ||
log.error( | ||
"default_payload is malformed, this value must be a dict." | ||
) | ||
return [device.pushkey] | ||
|
||
if n.event_id and not n.type: | ||
payload: Optional[Dict[str, Any]] = self._get_payload_event_id_only( | ||
n, device | ||
n, default_payload | ||
) | ||
else: | ||
payload = self._get_payload_full(n, device, log) | ||
|
@@ -336,7 +348,7 @@ async def _dispatch_notification_unlimited( | |
raise NotificationDispatchException("Retried too many times.") | ||
|
||
def _get_payload_event_id_only( | ||
self, n: Notification, device: Device | ||
self, n: Notification, default_payload: Dict[str, Any] | ||
) -> Dict[str, Any]: | ||
""" | ||
Constructs a payload for a notification where we know only the event ID. | ||
|
@@ -350,8 +362,7 @@ def _get_payload_event_id_only( | |
""" | ||
payload = {} | ||
|
||
if device.data: | ||
payload.update(device.data.get("default_payload", {})) | ||
payload.update(default_payload) | ||
|
||
if n.room_id: | ||
payload["room_id"] = n.room_id | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this will go on to attempt delivery anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sure does look like that-which probably doesn't make sense. I can fix that along with downgrading the error to a warning.