Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -85,9 +85,7 @@ · 84 unmodified lines | ||
| 85 | 85 | #include "MIDIEvent.h" |
| 86 | 86 | |
| 87 | 87 | #include "SettingHandle.h" |
| 88 | −// #include "SettingManager.h" | |
| 89 | −// #include "SettingInterface.h" | |
| 90 | −// #include "SettingHelpers.h" | |
| 88 | +#include <AddressManager.h> | |
| 91 | 89 | |
| 92 | 90 | const QString ScriptEngine::_SETTINGS_ENABLE_EXTENDED_EXCEPTIONS { |
| 93 | 91 | "com.highfidelity.experimental.enableExtendedJSExceptions" |
| @@ -2364,10 +2362,18 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 2270 unmodified lines | ||
| 2364 | 2362 | } |
| 2365 | 2363 | else { |
| 2366 | 2364 | // ENTITY SCRIPT WHITELIST STARTS HERE |
| 2365 | + auto nodeList = DependencyManager::get<NodeList>(); | |
| 2366 | + bool isInWhitelist = false; // assume unsafe | |
| 2367 | + bool autoPassList = false; | |
| 2367 | 2368 | QString whitelistPrefix = "[WHITELIST ENTITY SCRIPTS]"; |
| 2368 | − QList<QString> safeURLS = { "" }; | |
| 2369 | + QList<QString> safeURLS = { "file:///", "atp:", "cache:" }; | |
| 2369 | 2370 | safeURLS += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); |
| 2370 | 2371 | |
| 2372 | + // IF WHITELIST IS DISABLED IN SETTINGS | |
| 2373 | + bool whitelistEnabled = Setting::Handle<bool>("private/whitelistEnabled", true).get(); | |
| 2374 | + if (!whitelistEnabled) { | |
| 2375 | + autoPassList = true; | |
| 2376 | + } | |
| 2371 | 2377 | // PULL SAFEURLS FROM INTERFACE.JSON Settings |
| 2372 | 2378 | |
| 2373 | 2379 | QVariant raw = Setting::Handle<QVariant>("private/settingsSafeURLS").get(); |
| @@ -2376,9 +2382,23 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 2 unmodified lines | ||
| 2376 | 2382 | |
| 2377 | 2383 | // END PULL SAFEURLS FROM INTERFACE.JSON Settings |
| 2378 | 2384 | |
| 2379 | − bool isInWhitelist = false; // assume unsafe | |
| 2385 | + // GET CURRENT DOMAIN WHITELIST BYPASS, IN CASE AN ENTIRE DOMAIN IS WHITELISTED | |
| 2386 | + QString currentDomain = DependencyManager::get<AddressManager>()->getDomainURL().host(); | |
| 2387 | + | |
| 2388 | + QString domainSafeIP = nodeList->getDomainHandler().getHostname(); | |
| 2389 | + QString domainSafeURL = "hifi://" + currentDomain; | |
| 2390 | + for (const auto& str : safeURLS) { | |
| 2391 | + if(domainSafeURL.startsWith(str) || domainSafeIP.startsWith(str)) { | |
| 2392 | + qCDebug(scriptengine) << whitelistPrefix << "Whitelist Bypassed. Current Domain Host: " | |
| 2393 | + << nodeList->getDomainHandler().getHostname() | |
| 2394 | + << "Current Domain: " << currentDomain; | |
| 2395 | + isInWhitelist = true; | |
| 2396 | + autoPassList = true; | |
| 2397 | + } | |
| 2398 | + } | |
| 2399 | + // END CURRENT DOMAIN WHITELIST BYPASS | |
| 2380 | 2400 | |
| 2381 | − if (ScriptEngine::getContext() == "entity_server") { | |
| 2401 | + if (ScriptEngine::getContext() == "entity_server" || autoPassList == true) { // If running on the server or waved through, do not engage whitelist. | |
| 2382 | 2402 | isInWhitelist = true; |
| 2383 | 2403 | } else { |
| 2384 | 2404 | for (const auto& str : safeURLS) { |
| @@ -2392,7 +2412,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 7 unmodified lines | ||
| 2392 | 2412 | } |
| 2393 | 2413 | } |
| 2394 | 2414 | |
| 2395 | − if (!isInWhitelist) { | |
| 2415 | + if (!isInWhitelist || autoPassList == false) { | |
| 2396 | 2416 | qCDebug(scriptengine) << whitelistPrefix << "(disabled entity script)" << entityID.toString() << scriptOrURL; |
| 2397 | 2417 | exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0"); |
| 2398 | 2418 | } else { |