Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions browser/html/cool.html.m4
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,14 @@ m4_ifelse(MOBILEAPP,[true],
// would expand the %FOO% things. But it seems that window.versionPath is not used in the
// mobile apps anyway.
// window.versionPath = 'UNKNOWN';
window.accessToken = '';
window.accessTokenTTL = '';
window.accessHeader = '';
m4_ifelse(EMSCRIPTENAPP,[true],
[window.accessToken = '%ACCESS_TOKEN%';
window.accessTokenTTL = '%ACCESS_TOKEN_TTL%';
window.accessHeader = '%ACCESS_HEADER%';],
[window.accessToken = '';
window.accessTokenTTL = '';
window.accessHeader = '';]
)
window.postMessageOriginExt = '';
window.coolLogging = 'true';
window.enableWelcomeMessage = false;
Expand Down
11 changes: 8 additions & 3 deletions browser/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- js-indent-level: 8 -*- */
/* global errorMessages getParameterByName accessToken accessTokenTTL accessHeader createOnlineModule */
/* global app L host idleTimeoutSecs outOfFocusTimeoutSecs _ */
/* global app $ L host idleTimeoutSecs outOfFocusTimeoutSecs _ */
/*eslint indent: [error, "tab", { "outerIIFEBody": 0 }]*/
(function (global) {

Expand Down Expand Up @@ -81,6 +81,11 @@ app.map = map;
app.idleHandler.map = map;

if (window.ThisIsTheEmscriptenApp) {
var docParamsString = $.param(docParams);
// The URL may already contain a query (e.g., 'http://server.tld/foo/wopi/files/bar?desktop=baz') - then just append more params
var docParamsPart = docParamsString ? (docURL.includes('?') ? '&' : '?') + docParamsString : '';
var encodedWOPI = encodeURIComponent(docURL + docParamsPart);

var Module = {
onRuntimeInitialized: function() {
map.loadDocument(global.socket);
Expand All @@ -93,8 +98,8 @@ if (window.ThisIsTheEmscriptenApp) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
arguments_: [docURL],
arguments: [docURL],
arguments_: [docURL, encodedWOPI, isWopi ? 'true' : 'false'],
arguments: [docURL, encodedWOPI, isWopi ? 'true' : 'false'],
};
createOnlineModule(Module);
app.HandleCOOLMessage = Module['_handle_cool_message'];
Expand Down
24 changes: 11 additions & 13 deletions wasm/wasmapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,17 @@ int main(int argc, char* argv_main[])
std::thread(
[&]
{
// const std::string url = "/wasm/" + std::string(argv_main[1]);
// const std::string url =
// "/wasm/"
// "https%3A%2F%2Flocalhost%2Fnextcloud%2Findex.php%2Fapps%2Frichdocuments%2Fwopi%"
// "2Ffiles%2F8725_ocqiesh0cngs%3Faccess_token%3Daz5tjYv83wvhtpVbhuFXrTkss6gB1GDZ%"
// "26access_token_ttl%3D0";

//DOCX
const std::string url =
"/wasm/"
"https%3A%2F%2Flocalhost%2Fnextcloud%2Findex.php%2Fapps%2Frichdocuments%2Fwopi%"
"2Ffiles%2F8991_ocqiesh0cngs%3Faccess_token%3Dz4N7CViCj1pps28EVlG4dmxEMe62P7yo%"
"26access_token_ttl%3D0";
const std::string docURL = std::string(argv_main[1]);
const std::string encodedWOPI = std::string(argv_main[2]);
const std::string isWOPI = std::string(argv_main[3]);

std::string url;
if (isWOPI == "true")
url = "/wasm/" + encodedWOPI;
else
url = docURL + "/contents";

printf("isWOPI is %s: Fetching from url %s\n", isWOPI.c_str(), url.c_str());

emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
Expand Down
13 changes: 10 additions & 3 deletions wsd/FileServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request,
{
response.add("Cross-Origin-Opener-Policy", "same-origin");
response.add("Cross-Origin-Embedder-Policy", "require-corp");
response.add("Cross-Origin-Resource-Policy", "cross-origin");
}

const bool brotli = request.hasToken("Accept-Encoding", "br");
Expand Down Expand Up @@ -1251,13 +1252,19 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request,
"X-XSS-Protection: 1; mode=block\r\n"
"Referrer-Policy: no-referrer\r\n";

// if we have richdocuments with:
// addHeader('Cross-Origin-Opener-Policy', 'same-origin');
// addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
// then we seem to have to have this to avoid
// NS_ERROR_DOM_CORP_FAILED
oss << "Cross-Origin-Opener-Policy: same-origin\r\n";
oss << "Cross-Origin-Embedder-Policy: require-corp\r\n";
oss << "Cross-Origin-Resource-Policy: cross-origin\r\n";

const bool wasm = (relPath.find("wasm") != std::string::npos);
if (wasm)
{
LOG_ASSERT(COOLWSD::WASMState != COOLWSD::WASMActivationState::Disabled);
oss << "Cross-Origin-Opener-Policy: same-origin\r\n";
oss << "Cross-Origin-Embedder-Policy: require-corp\r\n";

csp.appendDirective("script-src", "'unsafe-eval'");
}

Expand Down