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

Trim the subject before encrypting the subject #383

Merged
merged 1 commit into from Jul 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/Push.php
Expand Up @@ -187,11 +187,18 @@ protected function encryptAndSign(Key $userKey, array $device, int $id, INotific
$data = [
'nid' => $id,
'app' => $notification->getApp(),
'subject' => $notification->getParsedSubject(),
'subject' => '',
'type' => $notification->getObjectType(),
'id' => $notification->getObjectId(),
];

// Max length of encryption is 255, so we need to shorten the subject to be shorter
$subject = $notification->getParsedSubject();
$dataLength = 245 - strlen(json_encode($data));
if (strlen($subject) > $dataLength) {
$data['subject'] = substr($subject, 0, $dataLength) . '…';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the substr not be 1 shorter than the dataLength?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with 245, instead of 255 so we have a little buffer there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok perfect. I wasn't sure if that was maybe for other metadata somewhere.

}

if ($isTalkNotification) {
$priority = 'high';
} else {
Expand Down