From 213aca81fb28f21ed2d78376af14a19df21f635f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 7 Jun 2024 11:22:25 +0200 Subject: [PATCH] cool#9219 clipboard: support URLs in the payload of the setclipboard command Copying the full clipboard (including ODF) from a remote server into the JS client failed with: Refused to connect to '...' because it violates the following Content Security Policy directive: "connect-src ..." If this happens, still send the original URL to the server, so it can download the full clipboard, which gives better result for pasting, compared to going via HTML only. Not done in this commit: 1) the JS still tries to get the clipboard itself, we download on the server only on failure and 2) the server does a blocking HTTP download, which may not be wanted. Signed-off-by: Miklos Vajna Change-Id: I9ed8c8050f9dbe71dc8fcd36c9d8fa6e8bba44f6 --- browser/src/map/Clipboard.js | 6 +++--- wsd/ClientSession.cpp | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/browser/src/map/Clipboard.js b/browser/src/map/Clipboard.js index 27e306019..f22672b72 100644 --- a/browser/src/map/Clipboard.js +++ b/browser/src/map/Clipboard.js @@ -354,15 +354,15 @@ L.Clipboard = L.Class.extend({ } var formData = new FormData(); - formData.append('data', new Blob([fallbackHtml]), 'clipboard'); + formData.append('data', new Blob([src]), 'clipboard'); that._doAsyncDownload( 'POST', dest, formData, false, function() { if (that._checkAndDisablePasteSpecial()) { - window.app.console.log('up-load of fallback done, now paste special'); + window.app.console.log('up-load of URL done, now paste special'); app.socket.sendMessage('uno .uno:PasteSpecial'); } else { - window.app.console.log('up-load of fallback done, now paste'); + window.app.console.log('up-load of URL done, now paste'); app.socket.sendMessage('uno .uno:Paste'); } diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 7a791258e..b5c172393 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -318,7 +318,24 @@ void ClientSession::handleClipboardRequest(DocumentBroker::ClipboardRequest if (data.get()) { preProcessSetClipboardPayload(*data); - docBroker->forwardToChild(client_from_this(), "setclipboard\n" + *data, true); + + if (data->starts_with("http")) + { + // We got a URL, download that and set the result as the clipboard. + std::shared_ptr httpSession = http::Session::create(*data); + std::shared_ptr httpResponse = + httpSession->syncRequest(http::Request(Poco::URI(*data).getPathAndQuery())); + if (httpResponse->statusLine().statusCode() == http::StatusCode::OK) + { + std::string body = httpResponse->getBody(); + docBroker->forwardToChild(client_from_this(), "setclipboard\n" + body, true); + } + } + else + { + // List of mimetype-size-data tuples, pass that over as-is. + docBroker->forwardToChild(client_from_this(), "setclipboard\n" + *data, true); + } // FIXME: work harder for error detection ? std::ostringstream oss;