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

Add webxdc notification handler #4400

Merged
merged 12 commits into from
Dec 16, 2024
Merged

Add webxdc notification handler #4400

merged 12 commits into from
Dec 16, 2024

Conversation

nicodh
Copy link
Contributor

@nicodh nicodh commented Dec 10, 2024

related to #4366
Example for calendar notification

image

click opens webxdc app with href if provided

Internal changes:
new flag isWebxdcInfo for DcNotification

@nicodh nicodh marked this pull request as draft December 10, 2024 07:46
@nicodh nicodh force-pushed the add-webxdc-notification-handler branch from 69dc59f to 55c574b Compare December 10, 2024 07:55
@nicodh nicodh marked this pull request as ready for review December 11, 2024 07:11
@nicodh nicodh requested review from WofWca, Simon-Laux and r10s December 11, 2024 07:11
Copy link
Collaborator

@WofWca WofWca left a comment

Choose a reason for hiding this comment

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

The idea of the feature itself is great, and this MR seems like a good implementation of it code-wise. But design-wise:

I don't like the idea of opening the app on notification click, at least by default.
At the very least a notification should have a separate "Launch app" button to do it.

The "How private are webxdc apps?" section states:

This also means: it can be a privacy risk to open webxdc apps in chats where you don’t trust the members - as you know it from e-mail attachments, where you only open attachments from senders you trust, and not from spammers.

So this is like opening an attachment right from a notification. Especially with real-time channels now enabled by default (which can leak your real IP). I expressed a similar concern in #4366 (comment).
And, correct me if I'm wrong, such notifications would be displayed even from people who aren't on your contact list? Never mind the contact list: with Chatmail, people share their invite codes, which bypasses the "contact request" thing.
And the other person can even completely control the contents of the notification, the text and the icon, judging by the screenshot, which is powerful for phishing.

Exposing your real IP and system info to anyone on the internet at a click of a button is not great.

What do you think?

packages/target-electron/src/notifications.ts Outdated Show resolved Hide resolved
packages/frontend/src/components/RuntimeAdapter.tsx Outdated Show resolved Hide resolved
packages/frontend/src/components/RuntimeAdapter.tsx Outdated Show resolved Hide resolved
@nicodh
Copy link
Contributor Author

nicodh commented Dec 11, 2024

Exposing your real IP and system info to anyone on the internet at a click of a button is not great.

What do you think?

Well it's not "anyone" and the information on the notification is clear. The icon comes from a webxdc app in a shared chat, not just from the message.

I remember there was a discussion on that and assumed the DC_EVENT_INCOMING_WEBXDC_NOTIFY should work like that.
Maybe @r10s knows more.

But we also could restrict the direct access to the case where the webxdc app is already opened.

@r10s
Copy link
Member

r10s commented Dec 11, 2024

on android/ios we're opening the chat with the webxdc-info-message or the webxdc-app-instance instead of opening the app directly.

we thought about opening the app directly, but then did not came to that at the end, idea was, however, to add an explicit "Start" button, but maybe it is also totally fine as it is now. we will know after some experience and real-world use.

so, i would suggest to do the same on desktop, sorry for not being clearer in the issue.

that would postpone that discussion about privacy (where we should also keep in mind, that every normal looking link send in a normal message leaks the IP-address easier. and this does not even discuss the real-world-attack vector of an IP-Address, VPN, realtime-disabled and so on ;)

if a chat is a contact request, so "untrusted", i would not send a notification at all (tbh, not totally sure if that is already the case on android, but otherwise, that'd might be regarded as a bug)

@nicodh
Copy link
Contributor Author

nicodh commented Dec 11, 2024

Ok so instead calling openwebxdc we just jump to the message as usual.

@r10s
Copy link
Member

r10s commented Dec 11, 2024

yes, that seems to be the easier thing for now

resolves #4366

- add new param isWebxdcInfo to DcNotification
- openWebxdc on click
@nicodh nicodh force-pushed the add-webxdc-notification-handler branch from 5b46284 to 3edca1f Compare December 11, 2024 14:17
@WofWca
Copy link
Collaborator

WofWca commented Dec 11, 2024

Well it's not "anyone" and the information on the notification is clear. The icon comes from a webxdc app in a shared chat, not just from the message.

Anyone can send an email, and they can make an app with whatever name and icon they like.

if a chat is a contact request, so "untrusted"

In my experience, contacts don't get marked as "requests" if they have your invite link, and invite links are supposedly not considered sensitive info: For example, people post their invite links in https://deltachat-bot.github.io/public-bots/#/home

i would suggest to do the same on desktop

Yes, that's better.

packages/target-electron/static/webxdc-preload.js Outdated Show resolved Hide resolved
packages/frontend/src/system-integration/notifications.ts Outdated Show resolved Hide resolved
packages/shared/shared-types.d.ts Show resolved Hide resolved
packages/target-electron/runtime-electron/runtime.ts Outdated Show resolved Hide resolved
packages/target-browser/runtime-browser/runtime.ts Outdated Show resolved Hide resolved
packages/target-browser/runtime-browser/runtime.ts Outdated Show resolved Hide resolved
packages/frontend/src/system-integration/notifications.ts Outdated Show resolved Hide resolved
packages/frontend/src/system-integration/notifications.ts Outdated Show resolved Hide resolved
packages/frontend/src/system-integration/notifications.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@WofWca WofWca left a comment

Choose a reason for hiding this comment

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

I did some testing. There seems to be a problem with when we call flushNotifications(), which is the only function that calls showNotification(). flushNotifications() is only called from the IncomingMsgBunch event handler.

Reproduction steps:

  1. Create two accounts, and create a group with those two accounts.
  2. Send the Calendar app to the group
  3. Send a regular message to the group. You'll get a notification on another account.
  4. Create an event in the calendar.
    You won't get a notification, but I assume you should.
  5. Create another event in the calendar.
    You will get a notification for the previous event!
  6. Send a regular message.
    You'll first get a notification for the second calendar event, and then a notification for the regular message!

Update: otherwise this looks better than the previous version, much simpler.

@nicodh
Copy link
Contributor Author

nicodh commented Dec 13, 2024

I did some testing. There seems to be a problem with when we call flushNotifications(), which is the only function that calls showNotification(). flushNotifications() is only called from the IncomingMsgBunch event handler.

Well when debugging it seems that in the group the IncomingWebxdcNotify event is not triggered at all. If you set a break point on frontend/../notifications in line 28
BackendRemote.on('IncomingWebxdcNotify', (accountId, { msgId, text }) => {
incomingWebxdcEventHandler(accountId, msgId, text)
})
Then you see there is no IncomingWebxdcNotify event triggered in the group, while in a 1:1 chat it is

@WofWca
Copy link
Collaborator

WofWca commented Dec 13, 2024

Well when debugging it seems that in the group the IncomingWebxdcNotify event is not triggered at all

Are you sure? It's not the case for me. IncomingWebxdcNotify gets triggered, but the notification is not there.

2024-12-13-bYubjUH2As.mp4

I got it. It's because the handler is slow now, so pushing to the notifications queue happens after the IncomingMsgBunch event.

IncomingWebxdcNotify 2 1 created "29" on Jan 25, 2025
22:22:54.855 notifications.ts:31 IncomingMsgBunch
22:22:54.856 notifications.ts:87 queuedNotifications[accountId].push

@nicodh
Copy link
Contributor Author

nicodh commented Dec 13, 2024

I got it. It's because the handler is slow now, so pushing to the notifications queue happens after the IncomingMsgBunch event.

Not for me. I found that the missing IncomingWebxdcNotify was caused by a calendar that was added to the group before the other test user was added. So that was correct.

But I can't reproduce your issue...?

@nicodh
Copy link
Contributor Author

nicodh commented Dec 13, 2024

But it is easly to imagine that fetching messages takes some time...

@nicodh
Copy link
Contributor Author

nicodh commented Dec 14, 2024

Added a solution for the queue. Based on https://stackoverflow.com/questions/53540348/js-async-await-tasks-queue (which is a very profound investigation of the queue topic). Would be much easier with rxjs (just call next() on a Subject() while others can subscribe to it) but not worth to introduce a new library here

@nicodh
Copy link
Contributor Author

nicodh commented Dec 14, 2024

Removed the event queue in favor of a more simple solution

const summaryText = eventText ?? notificationInfo.summaryText
const chatName = notificationInfo.chatName
let icon = getNotificationIcon(notificationInfo)
if (isWebxdcInfo && chatId === -1) {
Copy link
Member

Choose a reason for hiding this comment

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

why is chatID -1 here?

Copy link
Member

Choose a reason for hiding this comment

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

ah because it isn't there yet.... I'd rather use null or undefined to represent that state.
Or add the chat id to the IncomingWebxdcNotify event in core.

Copy link
Member

@Simon-Laux Simon-Laux Dec 14, 2024

Choose a reason for hiding this comment

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

thinking about it more it makes sense to add it to the event, because It already has contact id.

https://github.com/deltachat/deltachat-core-rust/blob/191eb7efdd2765af0b9440a1316e850ed321b2b2/src/events/payload.rs#L111-L123

Copy link
Member

@Simon-Laux Simon-Laux left a comment

Choose a reason for hiding this comment

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

code looks ok, didn't test.

Co-authored-by: Simon Laux <[email protected]>
Copy link
Collaborator

@WofWca WofWca left a comment

Choose a reason for hiding this comment

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

Would be nice to clean up commit history in order to do a fast-forward merge so that refactoring changes and different functional changes are not mixed, but it's not super important.

I tested this for a bit. Works alright, and the issues are resolved!

@@ -174,6 +247,14 @@ async function flushNotifications(accountId: number) {
let notifications = [...queuedNotifications[accountId]]
queuedNotifications = []

for await (const n of notifications) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

for await is no better than a regular for of here, right?

@nicodh nicodh merged commit d90e328 into main Dec 16, 2024
14 checks passed
@nicodh nicodh deleted the add-webxdc-notification-handler branch December 16, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants