Open snianu opened 2 years ago
The Web Editing Working Group just discussed async clipboard read and race conditions
.
Cocoa platforms have a very similar concept to sequence numbers, called changeCount. If this value changes between when the clipboard access is "approved" by the user and when the clipboard data is actually read, WebKit will currently reject the promise.
@whsieh Re: changeCount, does it change when the clipboard content changes or does it only change whenever there is an ownership change? On Windows, the sequence numbers changes whenever the clipboard content changes.
@whsieh Re: changeCount, does it change when the clipboard content changes or does is it only change whenever there is an ownership change? On Windows, the sequence numbers changes whenever the clipboard content changes.
I see — yeah, changeCount
is only changed when the pasteboard owner changes. That said, there may be other system APIs that would allow us to determine when the pasteboard contents change on macOS and iOS (on macOS, it's possible to read the generation count, whereas on iOS, a global notification is dispatched when the clipboard changes content).
The Web Editing Working Group just discussed async clipboard read & race conditions
.
In what kind of scenarios can this happen? When there is another app writing to the clipboard or the end user is lightning fast?
Thinking through possible scenarios a bit I think I agree with @smaug----'s remark that there's always a possibility for races here and not all of them you will be able to detect.
It seems fine to allow an exception in case something is considered amiss, but I would expect this kind of thing to not be common except on a system that's compromised in some manner.
In Chromium browsers, the data from the system clipboard is accessed asynchronously from Browser process (that calls the system clipboard APIs). When the browser reads the clipboard data, it will send that to the renderer, which will sanitize (if necessary) the data before sending it to JS. If the contents change between the browser read and the renderer sending to JS (sanitization can take some time), we do NOT notice this and pass this (outdated) clipboard data to JS. What should be the right behavior here? Should async clipboard APIs reject the promise if the clipboard data changed between the read call and the data that is returned after the read is executed successfully? On Windows, we could detect changes to the system clipboard by checking for the sequence numbers, or is it OK to send data that may not be in the clipboard at the time of read in JS? @annevk @whsieh @BoCupp-Microsoft