From bd066adbf620cae05e246e6b4fa8f2c6705659e2 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Mon, 20 Jan 2020 16:03:48 -0500 Subject: [PATCH 01/13] Whitelist toggle not working c++ side. --- .../security/EntityScriptQMLWhitelist.qml | 168 ++++++++++++------ interface/src/Menu.cpp | 3 +- libraries/script-engine/src/ScriptEngine.cpp | 18 +- 3 files changed, 128 insertions(+), 61 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml index aa30b5d014..ff2f76f2f7 100644 --- a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml +++ b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml @@ -8,7 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// Security Settings for the Entity Script Whitelist +// Security Settings for the Entity Script QML Whitelist import Hifi 1.0 as Hifi import QtQuick 2.8 @@ -21,38 +21,55 @@ import "../../../windows" Rectangle { + id: "parentBody"; + property var checkboxReady: "false"; - function getWhitelistAsText() { - var whitelist = Settings.getValue("private/settingsSafeURLS"); - var arrayWhitelist = whitelist.split(","); - var whitelistText = arrayWhitelist.join("\n"); - return whitelistText; - } + function getWhitelistAsText() { + var whitelist = Settings.getValue("private/settingsSafeURLS"); + var arrayWhitelist = whitelist.split(","); + var whitelistText = arrayWhitelist.join("\n"); + return whitelistText; + } - function setWhitelistAsText(whitelistText) { - Settings.setValue("private/settingsSafeURLS", whitelistText.text); - - var originalSetString = whitelistText.text; - var originalSet = originalSetString.split(' ').join(''); - - var check = Settings.getValue("private/settingsSafeURLS"); - var arrayCheck = check.split(","); - var textCheck = arrayCheck.join("\n"); - - if(textCheck == originalSet) { - setWhitelistSuccess(true); - } else { - setWhitelistSuccess(false); - } - } + function setWhitelistAsText(whitelistText) { + Settings.setValue("private/settingsSafeURLS", whitelistText.text); + + var originalSetString = whitelistText.text; + var originalSet = originalSetString.split(' ').join(''); + + var check = Settings.getValue("private/settingsSafeURLS"); + var arrayCheck = check.split(","); + var textCheck = arrayCheck.join("\n"); + + if (textCheck == originalSet) { + setWhitelistSuccess(true); + } else { + setWhitelistSuccess(false); + } + } - function setWhitelistSuccess(success) { - if(success) { - notificationText.text = "Successfully saved settings."; - } else { - notificationText.text = "Error! Settings not saved."; - } - } + function setWhitelistSuccess(success) { + if (success) { + notificationText.text = "Successfully saved settings."; + } else { + notificationText.text = "Error! Settings not saved."; + } + } + + function toggleWhitelist(enabled) { + Settings.setValue("private/whitelistEnabled", enabled); + console.info("NANI?",enabled); + } + + function initCheckbox() { + var check = Settings.getValue("private/whitelistEnabled"); + + console.info("Triggered init. Val:", check); + if (check == "true") { + whiteListEnabled.checked = "true"; + parentBody.checkboxReady = "true"; + } + } anchors.fill: parent @@ -60,23 +77,51 @@ Rectangle { height: 120; color: "#80010203"; - HifiStylesUit.RalewayRegular { - id: titleText; - text: "Entity Script Whitelist" - // Text size - size: 24; - // Style - color: "white"; - elide: Text.ElideRight; - // Anchors - anchors.top: parent.top; - anchors.left: parent.left; - anchors.leftMargin: 20; - anchors.right: parent.right; - anchors.rightMargin: 20; - height: 60; - } - + HifiStylesUit.RalewayRegular { + id: titleText; + text: "Entity Script / QML Whitelist" + // Text size + size: 24; + // Style + color: "white"; + elide: Text.ElideRight; + // Anchors + anchors.top: parent.top; + anchors.left: parent.left; + anchors.leftMargin: 20; + anchors.right: parent.right; + anchors.rightMargin: 20; + height: 60; + + CheckBox { + Component.onCompleted: { + initCheckbox(); + } + + id: whiteListEnabled; + + anchors.right: parent.right; + anchors.top: parent.top; + anchors.topMargin: 10; + onCheckedChanged: { + console.info("Triggered.0"); + if (parentBody.checkboxReady == "true") { + console.info("Resolved.0"); + toggleWhitelist(whiteListEnabled.checked) + } + } + + Label { + text: "Enabled" + color: "white" + font.pixelSize: 18; + anchors.right: parent.left; + anchors.top: parent.top; + anchors.topMargin: 10; + } + } + } + Rectangle { id: textAreaRectangle; color: "black"; @@ -129,30 +174,39 @@ Rectangle { id: notificationText; text: "" // Text size - size: 14; + size: 16; // Style color: "white"; elide: Text.ElideLeft; // Anchors - anchors.right: parent.right; - anchors.rightMargin: 130; + anchors.right: parent.left; + anchors.rightMargin: 10; } } HifiStylesUit.RalewayRegular { id: descriptionText; - text: "Separate your URLs by line, not commas. Example: - https://google.com/ - https://bing.com/ - https://mydomain.here/ - \nEnsure there are no spaces or whitespace. - \nFor QML files, you can only whitelist each file individually - ending with '.qml'." + text: +"The whitelist checks scripts/QML as it is loaded.
+Therefore, if a script is cached or has no reason to load again,
+then removing it from the whitelist will not be effective until
+it is reloaded.
+Separate your whitelisted domains by line, not commas. e.g. +
+ https://google.com/
+ hifi://the-spot/
+ 127.0.0.1
+ https://mydomain.here/ +
+Ensure there are no spaces or whitespace.

+For QML files, you can only whitelist each file individually
+ending with '.qml'." // Text size size: 16; // Style color: "white"; elide: Text.ElideRight; + textFormat: Text.RichText; // Anchors anchors.top: parent.bottom; anchors.topMargin: 90; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index b0e5bbe8de..6d3e8454ba 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -287,12 +287,13 @@ Menu::Menu() { } }); - // Settings > Entity Script Whitelist + // Settings > Entity Script / QML Whitelist action = addActionToQMenuAndActionHash(settingsMenu, "Entity Script / QML Whitelist"); connect(action, &QAction::triggered, [] { auto tablet = DependencyManager::get()->getTablet("com.highfidelity.interface.tablet.system"); auto hmd = DependencyManager::get(); + DependencyManager::get()->clearCache(); tablet->pushOntoStack("hifi/dialogs/security/EntityScriptQMLWhitelist.qml"); if (!hmd->getShouldShowTablet()) { diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index de7fc488aa..4cefdb0946 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2333,7 +2333,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co if (isURL) { setParentURL(scriptOrURL); } - + // SANITY/PERFORMANCE CHECK USING SANDBOX const int SANDBOX_TIMEOUT = 0.25 * MSECS_PER_SECOND; BaseScriptEngine sandbox; @@ -2369,11 +2369,23 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co QList safeURLPrefixes = { "file:///", "atp:", "cache:" }; safeURLPrefixes += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); - // IF WHITELIST IS DISABLED IN SETTINGS - bool whitelistEnabled = Setting::Handle("private/whitelistEnabled", true).get(); + // ENTITY SCRIPT WHITELIST TOGGLE CHECK + Setting::Handle whitelistEnabledSetting{"private/whitelistEnabled", true}; // Assume it is enabled. + bool whitelistEnabled = whitelistEnabledSetting.get(); + + // QVariant whitelistEnabledExists = Setting::Handle("private/whitelistEnabled", false).get(); + if (whitelistEnabled) { + whitelistEnabledSetting.set(true); + qCDebug(scriptengine) << "Whitelist toggle setting does not exist. Creating setting now."; + } else { + qCDebug(scriptengine) << "Whitelist toggle setting does not exist. Creating setting now."; + whitelistEnabledSetting.set(false); + } + if (!whitelistEnabled) { passList = true; } + qCDebug(scriptengine) << "Whitelist Enabled: " << whitelistEnabled; // PULL SAFEURLS FROM INTERFACE.JSON Settings QVariant raw = Setting::Handle("private/settingsSafeURLS").get(); From 61943d0edbdfee351f861d819e699edbe1ac3564 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Tue, 21 Jan 2020 22:51:30 -0500 Subject: [PATCH 02/13] non-working state --- libraries/script-engine/src/ScriptEngine.cpp | 10 ---------- libraries/script-engine/src/ScriptEngine.h | 2 ++ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 4cefdb0946..4c46210b3c 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2370,18 +2370,8 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co safeURLPrefixes += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); // ENTITY SCRIPT WHITELIST TOGGLE CHECK - Setting::Handle whitelistEnabledSetting{"private/whitelistEnabled", true}; // Assume it is enabled. bool whitelistEnabled = whitelistEnabledSetting.get(); - // QVariant whitelistEnabledExists = Setting::Handle("private/whitelistEnabled", false).get(); - if (whitelistEnabled) { - whitelistEnabledSetting.set(true); - qCDebug(scriptengine) << "Whitelist toggle setting does not exist. Creating setting now."; - } else { - qCDebug(scriptengine) << "Whitelist toggle setting does not exist. Creating setting now."; - whitelistEnabledSetting.set(false); - } - if (!whitelistEnabled) { passList = true; } diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 94381ede02..6bd722e077 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -973,6 +973,8 @@ protected: Setting::Handle _enableExtendedJSExceptions { _SETTINGS_ENABLE_EXTENDED_EXCEPTIONS, true }; + Setting::Handle whitelistEnabledSetting { "DELME/whitelistEnabled", false }; // Set to false if not exist. + QWeakPointer _scriptEngines; }; From 98473abbb4fe95182b53ee8eb050244fc03647c9 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Wed, 22 Jan 2020 11:29:37 -0500 Subject: [PATCH 03/13] QML works, C++ works but does a manual set to true, does not see updates from QML set setting. --- .../security/EntityScriptQMLWhitelist.qml | 59 +++++++++---------- libraries/script-engine/src/ScriptEngine.cpp | 4 +- libraries/script-engine/src/ScriptEngine.h | 5 +- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml index ff2f76f2f7..c9c56bfe81 100644 --- a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml +++ b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml @@ -21,8 +21,7 @@ import "../../../windows" Rectangle { - id: "parentBody"; - property var checkboxReady: "false"; + id: parentBody; function getWhitelistAsText() { var whitelist = Settings.getValue("private/settingsSafeURLS"); @@ -60,14 +59,13 @@ Rectangle { Settings.setValue("private/whitelistEnabled", enabled); console.info("NANI?",enabled); } - + function initCheckbox() { var check = Settings.getValue("private/whitelistEnabled"); console.info("Triggered init. Val:", check); - if (check == "true") { - whiteListEnabled.checked = "true"; - parentBody.checkboxReady = "true"; + if (check == true) { + whitelistEnabled.toggle(); } } @@ -94,32 +92,29 @@ Rectangle { height: 60; CheckBox { - Component.onCompleted: { - initCheckbox(); - } - - id: whiteListEnabled; - - anchors.right: parent.right; - anchors.top: parent.top; - anchors.topMargin: 10; - onCheckedChanged: { - console.info("Triggered.0"); - if (parentBody.checkboxReady == "true") { - console.info("Resolved.0"); - toggleWhitelist(whiteListEnabled.checked) - } - } - - Label { - text: "Enabled" - color: "white" - font.pixelSize: 18; - anchors.right: parent.left; - anchors.top: parent.top; - anchors.topMargin: 10; - } - } + Component.onCompleted: { + initCheckbox(); + } + + id: whitelistEnabled; + + anchors.right: parent.right; + anchors.top: parent.top; + anchors.topMargin: 10; + onToggled: { + console.info("Triggered.0"); + toggleWhitelist(whitelistEnabled.checked) + } + + Label { + text: "Enabled" + color: "white" + font.pixelSize: 18; + anchors.right: parent.left; + anchors.top: parent.top; + anchors.topMargin: 10; + } + } } Rectangle { diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 4c46210b3c..ace379f759 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2370,7 +2370,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co safeURLPrefixes += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); // ENTITY SCRIPT WHITELIST TOGGLE CHECK - bool whitelistEnabled = whitelistEnabledSetting.get(); + bool whitelistEnabled = _whitelistEnabled.get(); + + _whitelistEnabled.set(true); if (!whitelistEnabled) { passList = true; diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 6bd722e077..a00a6999cb 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -973,9 +973,10 @@ protected: Setting::Handle _enableExtendedJSExceptions { _SETTINGS_ENABLE_EXTENDED_EXCEPTIONS, true }; - Setting::Handle whitelistEnabledSetting { "DELME/whitelistEnabled", false }; // Set to false if not exist. - QWeakPointer _scriptEngines; + + Setting::Handle _whitelistEnabled{"private/whitelistEnabled", false }; + }; ScriptEnginePointer scriptEngineFactory(ScriptEngine::Context context, From fd5ee3e1a751a7c40fde902b9ba1c21c3e6d1a2d Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Wed, 22 Jan 2020 14:48:15 -0500 Subject: [PATCH 04/13] Whitelist toggle now works. --- libraries/script-engine/src/ScriptEngine.cpp | 5 ++--- libraries/script-engine/src/ScriptEngine.h | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index ace379f759..d8f65e0506 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2370,10 +2370,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co safeURLPrefixes += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); // ENTITY SCRIPT WHITELIST TOGGLE CHECK + Setting::Handle _whitelistEnabled{"private/whitelistEnabled", false }; bool whitelistEnabled = _whitelistEnabled.get(); - - _whitelistEnabled.set(true); - + if (!whitelistEnabled) { passList = true; } diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index a00a6999cb..fca652d7ad 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -975,8 +975,6 @@ protected: QWeakPointer _scriptEngines; - Setting::Handle _whitelistEnabled{"private/whitelistEnabled", false }; - }; ScriptEnginePointer scriptEngineFactory(ScriptEngine::Context context, From 7a985b445e77dc3183f9c3a5fb0d838d33179c4c Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Wed, 22 Jan 2020 14:53:55 -0500 Subject: [PATCH 05/13] removed extra debug, added debug for user awareness. --- .../qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml | 4 +--- libraries/script-engine/src/ScriptEngine.cpp | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml index c9c56bfe81..3de86c31d9 100644 --- a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml +++ b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml @@ -57,13 +57,12 @@ Rectangle { function toggleWhitelist(enabled) { Settings.setValue("private/whitelistEnabled", enabled); - console.info("NANI?",enabled); + console.info("Toggling Whitelist to:", enabled); } function initCheckbox() { var check = Settings.getValue("private/whitelistEnabled"); - console.info("Triggered init. Val:", check); if (check == true) { whitelistEnabled.toggle(); } @@ -102,7 +101,6 @@ Rectangle { anchors.top: parent.top; anchors.topMargin: 10; onToggled: { - console.info("Triggered.0"); toggleWhitelist(whitelistEnabled.checked) } diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index d8f65e0506..40f43ee22f 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2374,9 +2374,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co bool whitelistEnabled = _whitelistEnabled.get(); if (!whitelistEnabled) { + qCDebug(scriptengine) << "Whitelist Enabled: " << whitelistEnabled; passList = true; } - qCDebug(scriptengine) << "Whitelist Enabled: " << whitelistEnabled; // PULL SAFEURLS FROM INTERFACE.JSON Settings QVariant raw = Setting::Handle("private/settingsSafeURLS").get(); @@ -2391,7 +2391,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co QString domainSafeURL = URL_SCHEME_HIFI + "://" + currentDomain; for (const auto& str : safeURLPrefixes) { if (domainSafeURL.startsWith(str) || domainSafeIP.startsWith(str)) { - qCDebug(scriptengine) << whitelistPrefix << "Whitelist Bypassed. Current Domain Host: " + qCDebug(scriptengine) << whitelistPrefix << "Whitelist Bypassed, entire domain is whitelisted. Current Domain Host: " << nodeList->getDomainHandler().getHostname() << "Current Domain: " << currentDomain; passList = true; From fbaf0ea56bcb887eb6045db3e87073766fadcc88 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Wed, 22 Jan 2020 15:08:26 -0500 Subject: [PATCH 06/13] Remove debugging cache clearer. --- interface/src/Menu.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6d3e8454ba..fbb69842bd 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -293,7 +293,6 @@ Menu::Menu() { auto tablet = DependencyManager::get()->getTablet("com.highfidelity.interface.tablet.system"); auto hmd = DependencyManager::get(); - DependencyManager::get()->clearCache(); tablet->pushOntoStack("hifi/dialogs/security/EntityScriptQMLWhitelist.qml"); if (!hmd->getShouldShowTablet()) { From c121a8ef2a49190c7eab8aa86c84b3bcf9ca9df3 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Thu, 23 Jan 2020 03:06:58 -0500 Subject: [PATCH 07/13] Housekeeping. --- .../security/EntityScriptQMLWhitelist.qml | 86 +++++++++---------- libraries/script-engine/src/ScriptEngine.cpp | 6 +- libraries/script-engine/src/ScriptEngine.h | 1 - 3 files changed, 45 insertions(+), 48 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml index 3de86c31d9..83725e9d4b 100644 --- a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml +++ b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml @@ -21,52 +21,50 @@ import "../../../windows" Rectangle { - id: parentBody; - - function getWhitelistAsText() { - var whitelist = Settings.getValue("private/settingsSafeURLS"); - var arrayWhitelist = whitelist.split(","); - var whitelistText = arrayWhitelist.join("\n"); - return whitelistText; - } - - function setWhitelistAsText(whitelistText) { - Settings.setValue("private/settingsSafeURLS", whitelistText.text); + id: parentBody; - var originalSetString = whitelistText.text; - var originalSet = originalSetString.split(' ').join(''); + function getWhitelistAsText() { + var whitelist = Settings.getValue("private/settingsSafeURLS"); + var arrayWhitelist = whitelist.split(",").join("\n"); + return arrayWhitelist; + } - var check = Settings.getValue("private/settingsSafeURLS"); - var arrayCheck = check.split(","); - var textCheck = arrayCheck.join("\n"); + function setWhitelistAsText(whitelistText) { + Settings.setValue("private/settingsSafeURLS", whitelistText.text); - if (textCheck == originalSet) { - setWhitelistSuccess(true); - } else { - setWhitelistSuccess(false); - } - } - - function setWhitelistSuccess(success) { - if (success) { - notificationText.text = "Successfully saved settings."; - } else { - notificationText.text = "Error! Settings not saved."; - } - } - - function toggleWhitelist(enabled) { - Settings.setValue("private/whitelistEnabled", enabled); - console.info("Toggling Whitelist to:", enabled); - } - - function initCheckbox() { - var check = Settings.getValue("private/whitelistEnabled"); - - if (check == true) { - whitelistEnabled.toggle(); - } - } + var originalSetString = whitelistText.text; + var originalSet = originalSetString.split(' ').join(''); + + var check = Settings.getValue("private/settingsSafeURLS"); + var arrayCheck = check.split(",").join("\n"); + + if (arrayCheck === originalSet) { + setWhitelistSuccess(true); + } else { + setWhitelistSuccess(false); + } + } + + function setWhitelistSuccess(success) { + if (success) { + notificationText.text = "Successfully saved settings."; + } else { + notificationText.text = "Error! Settings not saved."; + } + } + + function toggleWhitelist(enabled) { + Settings.setValue("private/whitelistEnabled", enabled); + console.info("Toggling Whitelist to:", enabled); + } + + function initCheckbox() { + var check = Settings.getValue("private/whitelistEnabled", false); + + if (check) { + whitelistEnabled.toggle(); + } + } anchors.fill: parent @@ -180,7 +178,7 @@ Rectangle { HifiStylesUit.RalewayRegular { id: descriptionText; text: -"The whitelist checks scripts/QML as it is loaded.
+"The whitelist checks scripts & QML as they are loaded.
Therefore, if a script is cached or has no reason to load again,
then removing it from the whitelist will not be effective until
it is reloaded.
diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 40f43ee22f..eaca8c307d 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2333,7 +2333,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co if (isURL) { setParentURL(scriptOrURL); } - + // SANITY/PERFORMANCE CHECK USING SANDBOX const int SANDBOX_TIMEOUT = 0.25 * MSECS_PER_SECOND; BaseScriptEngine sandbox; @@ -2370,8 +2370,8 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co safeURLPrefixes += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); // ENTITY SCRIPT WHITELIST TOGGLE CHECK - Setting::Handle _whitelistEnabled{"private/whitelistEnabled", false }; - bool whitelistEnabled = _whitelistEnabled.get(); + Setting::Handle whitelistEnabled{"private/whitelistEnabled", false }; + bool whitelistEnabled = whitelistEnabled.get(); if (!whitelistEnabled) { qCDebug(scriptengine) << "Whitelist Enabled: " << whitelistEnabled; diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index fca652d7ad..94381ede02 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -974,7 +974,6 @@ protected: Setting::Handle _enableExtendedJSExceptions { _SETTINGS_ENABLE_EXTENDED_EXCEPTIONS, true }; QWeakPointer _scriptEngines; - }; ScriptEnginePointer scriptEngineFactory(ScriptEngine::Context context, From 1979a4bd94876a41628c6325167715ea8c6ffb52 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Thu, 23 Jan 2020 03:15:18 -0500 Subject: [PATCH 08/13] Further housekeeping. :) --- .../qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml index 83725e9d4b..c2bbb43079 100644 --- a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml +++ b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml @@ -38,11 +38,7 @@ Rectangle { var check = Settings.getValue("private/settingsSafeURLS"); var arrayCheck = check.split(",").join("\n"); - if (arrayCheck === originalSet) { - setWhitelistSuccess(true); - } else { - setWhitelistSuccess(false); - } + setWhitelistSuccess(arrayCheck === originalSet); } function setWhitelistSuccess(success) { From d6cf4db930ff072fa025a330703bcdad550f022e Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Sat, 25 Jan 2020 12:48:43 -0500 Subject: [PATCH 09/13] Fixed bug --- libraries/script-engine/src/ScriptEngine.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index eaca8c307d..cc665c80fc 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2371,10 +2371,10 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co // ENTITY SCRIPT WHITELIST TOGGLE CHECK Setting::Handle whitelistEnabled{"private/whitelistEnabled", false }; - bool whitelistEnabled = whitelistEnabled.get(); + bool isWhitelistEnabled = whitelistEnabled.get(); - if (!whitelistEnabled) { - qCDebug(scriptengine) << "Whitelist Enabled: " << whitelistEnabled; + if (!isWhitelistEnabled) { + qCDebug(scriptengine) << "Whitelist Enabled: " << isWhitelistEnabled; passList = true; } From fc73f76ab738495d913f89336e0b3170244628ba Mon Sep 17 00:00:00 2001 From: kasenvr <52365539+kasenvr@users.noreply.github.com> Date: Sat, 25 Jan 2020 19:02:01 -0500 Subject: [PATCH 10/13] Update interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml Co-Authored-By: HifiExperiments <53453710+HifiExperiments@users.noreply.github.com> --- .../qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml index c2bbb43079..7ce80c777a 100644 --- a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml +++ b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml @@ -176,7 +176,7 @@ Rectangle { text: "The whitelist checks scripts & QML as they are loaded.
Therefore, if a script is cached or has no reason to load again,
-then removing it from the whitelist will not be effective until
+removing it from the whitelist will have no effect until
it is reloaded.
Separate your whitelisted domains by line, not commas. e.g.
@@ -203,4 +203,4 @@ ending with '.qml'." anchors.rightMargin: 20; } } -} \ No newline at end of file +} From fe48427d389c1676c70e85a0130ffb3737b66ce6 Mon Sep 17 00:00:00 2001 From: kasenvr <52365539+kasenvr@users.noreply.github.com> Date: Sat, 25 Jan 2020 19:02:12 -0500 Subject: [PATCH 11/13] Update libraries/script-engine/src/ScriptEngine.cpp Co-Authored-By: HifiExperiments <53453710+HifiExperiments@users.noreply.github.com> --- libraries/script-engine/src/ScriptEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index cc665c80fc..a0c8bfc5b8 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2370,7 +2370,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co safeURLPrefixes += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); // ENTITY SCRIPT WHITELIST TOGGLE CHECK - Setting::Handle whitelistEnabled{"private/whitelistEnabled", false }; + Setting::Handle whitelistEnabled {"private/whitelistEnabled", false }; bool isWhitelistEnabled = whitelistEnabled.get(); if (!isWhitelistEnabled) { From 8b03d1bd19f39d8891f68582b47e37564d490044 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Sat, 25 Jan 2020 19:08:56 -0500 Subject: [PATCH 12/13] Removed unnecessary var. --- libraries/script-engine/src/ScriptEngine.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index a0c8bfc5b8..da88e8e689 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2371,10 +2371,8 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co // ENTITY SCRIPT WHITELIST TOGGLE CHECK Setting::Handle whitelistEnabled {"private/whitelistEnabled", false }; - bool isWhitelistEnabled = whitelistEnabled.get(); - if (!isWhitelistEnabled) { - qCDebug(scriptengine) << "Whitelist Enabled: " << isWhitelistEnabled; + if (!whitelistEnabled.get()) { passList = true; } From 428a5b65ff8dc35daa862e4671ed1350ab2eb9c4 Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Mon, 27 Jan 2020 13:13:36 -0500 Subject: [PATCH 13/13] Lint --- .../security/EntityScriptQMLWhitelist.qml | 230 +++++++++--------- libraries/script-engine/src/ScriptEngine.cpp | 16 +- 2 files changed, 123 insertions(+), 123 deletions(-) diff --git a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml index 7ce80c777a..9e0b6ba4cf 100644 --- a/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml +++ b/interface/resources/qml/hifi/dialogs/security/EntityScriptQMLWhitelist.qml @@ -63,41 +63,41 @@ Rectangle { } - anchors.fill: parent - width: parent.width; - height: 120; - color: "#80010203"; + anchors.fill: parent + width: parent.width; + height: 120; + color: "#80010203"; - HifiStylesUit.RalewayRegular { - id: titleText; - text: "Entity Script / QML Whitelist" - // Text size - size: 24; - // Style - color: "white"; - elide: Text.ElideRight; - // Anchors - anchors.top: parent.top; - anchors.left: parent.left; - anchors.leftMargin: 20; - anchors.right: parent.right; - anchors.rightMargin: 20; - height: 60; + HifiStylesUit.RalewayRegular { + id: titleText; + text: "Entity Script / QML Whitelist" + // Text size + size: 24; + // Style + color: "white"; + elide: Text.ElideRight; + // Anchors + anchors.top: parent.top; + anchors.left: parent.left; + anchors.leftMargin: 20; + anchors.right: parent.right; + anchors.rightMargin: 20; + height: 60; - CheckBox { + CheckBox { Component.onCompleted: { initCheckbox(); } - + id: whitelistEnabled; - + anchors.right: parent.right; anchors.top: parent.top; anchors.topMargin: 10; onToggled: { toggleWhitelist(whitelistEnabled.checked) } - + Label { text: "Enabled" color: "white" @@ -107,100 +107,100 @@ Rectangle { anchors.topMargin: 10; } } - } + } - Rectangle { - id: textAreaRectangle; - color: "black"; - width: parent.width; - height: 250; - anchors.top: titleText.bottom; - - ScrollView { - id: textAreaScrollView - anchors.fill: parent; - width: parent.width - height: parent.height - contentWidth: parent.width - contentHeight: parent.height - clip: false; - - TextArea { - id: whitelistTextArea - text: getWhitelistAsText(); - onTextChanged: notificationText.text = ""; + Rectangle { + id: textAreaRectangle; + color: "black"; width: parent.width; - height: parent.height; - font.family: "Ubuntu"; - font.pointSize: 12; - color: "white"; - } - } + height: 250; + anchors.top: titleText.bottom; - Button { - id: saveChanges - anchors.topMargin: 5; - anchors.leftMargin: 20; - anchors.rightMargin: 20; - x: textAreaRectangle.x + textAreaRectangle.width - width - 15; - y: textAreaRectangle.y + textAreaRectangle.height - height; - contentItem: Text { - text: saveChanges.text - font.family: "Ubuntu"; - font.pointSize: 12; - opacity: enabled ? 1.0 : 0.3 - color: "black" - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - } - text: "Save Changes" - onClicked: setWhitelistAsText(whitelistTextArea) - - HifiStylesUit.RalewayRegular { - id: notificationText; - text: "" - // Text size - size: 16; - // Style - color: "white"; - elide: Text.ElideLeft; - // Anchors - anchors.right: parent.left; - anchors.rightMargin: 10; - } + ScrollView { + id: textAreaScrollView + anchors.fill: parent; + width: parent.width + height: parent.height + contentWidth: parent.width + contentHeight: parent.height + clip: false; + + TextArea { + id: whitelistTextArea + text: getWhitelistAsText(); + onTextChanged: notificationText.text = ""; + width: parent.width; + height: parent.height; + font.family: "Ubuntu"; + font.pointSize: 12; + color: "white"; + } + } + + Button { + id: saveChanges + anchors.topMargin: 5; + anchors.leftMargin: 20; + anchors.rightMargin: 20; + x: textAreaRectangle.x + textAreaRectangle.width - width - 15; + y: textAreaRectangle.y + textAreaRectangle.height - height; + contentItem: Text { + text: saveChanges.text + font.family: "Ubuntu"; + font.pointSize: 12; + opacity: enabled ? 1.0 : 0.3 + color: "black" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + text: "Save Changes" + onClicked: setWhitelistAsText(whitelistTextArea) + + HifiStylesUit.RalewayRegular { + id: notificationText; + text: "" + // Text size + size: 16; + // Style + color: "white"; + elide: Text.ElideLeft; + // Anchors + anchors.right: parent.left; + anchors.rightMargin: 10; + } + } + + HifiStylesUit.RalewayRegular { + id: descriptionText; + text: + "The whitelist checks scripts and QML as they are loaded.
+ Therefore, if a script is cached or has no reason to load again,
+ removing it from the whitelist will have no effect until
+ it is reloaded.
+ Separate your whitelisted domains by line, not commas. e.g. +
+ https://google.com/
+ hifi://the-spot/
+ 127.0.0.1
+ https://mydomain.here/ +
+ Ensure there are no spaces or whitespace.

+ For QML files, you can only whitelist each file individually
+ ending with '.qml'." + // Text size + size: 16; + // Style + color: "white"; + elide: Text.ElideRight; + textFormat: Text.RichText; + // Anchors + anchors.top: parent.bottom; + anchors.topMargin: 90; + anchors.left: parent.left; + anchors.leftMargin: 20; + anchors.right: parent.right; + anchors.rightMargin: 20; + } } - - HifiStylesUit.RalewayRegular { - id: descriptionText; - text: -"The whitelist checks scripts & QML as they are loaded.
-Therefore, if a script is cached or has no reason to load again,
-removing it from the whitelist will have no effect until
-it is reloaded.
-Separate your whitelisted domains by line, not commas. e.g. -
- https://google.com/
- hifi://the-spot/
- 127.0.0.1
- https://mydomain.here/ -
-Ensure there are no spaces or whitespace.

-For QML files, you can only whitelist each file individually
-ending with '.qml'." - // Text size - size: 16; - // Style - color: "white"; - elide: Text.ElideRight; - textFormat: Text.RichText; - // Anchors - anchors.top: parent.bottom; - anchors.topMargin: 90; - anchors.left: parent.left; - anchors.leftMargin: 20; - anchors.right: parent.right; - anchors.rightMargin: 20; - } - } } diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index da88e8e689..98f1f3082f 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2369,20 +2369,20 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co QList safeURLPrefixes = { "file:///", "atp:", "cache:" }; safeURLPrefixes += qEnvironmentVariable("EXTRA_WHITELIST").trimmed().split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts); - // ENTITY SCRIPT WHITELIST TOGGLE CHECK + // Entity Script Whitelist toggle check. Setting::Handle whitelistEnabled {"private/whitelistEnabled", false }; if (!whitelistEnabled.get()) { passList = true; } - // PULL SAFEURLS FROM INTERFACE.JSON Settings + // Pull SAFEURLS from the Interface.JSON settings. QVariant raw = Setting::Handle("private/settingsSafeURLS").get(); QStringList settingsSafeURLS = raw.toString().trimmed().split(QRegExp("\\s*[,\r\n]+\\s*"), QString::SkipEmptyParts); safeURLPrefixes += settingsSafeURLS; - // END PULL SAFEURLS FROM INTERFACE.JSON Settings + // END Pull SAFEURLS from the Interface.JSON settings. - // GET CURRENT DOMAIN WHITELIST BYPASS, IN CASE AN ENTIRE DOMAIN IS WHITELISTED + // Get current domain whitelist bypass, in case an entire domain is whitelisted. QString currentDomain = DependencyManager::get()->getDomainURL().host(); QString domainSafeIP = nodeList->getDomainHandler().getHostname(); @@ -2395,9 +2395,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co passList = true; } } - // END CURRENT DOMAIN WHITELIST BYPASS + // END bypass whitelist based on current domain. - // START CHECKING AGAINST THE WHITELIST + // Start processing scripts through the whitelist. if (ScriptEngine::getContext() == "entity_server") { // If running on the server, do not engage whitelist. passList = true; } else if (!passList) { // If waved through, do not engage whitelist. @@ -2407,11 +2407,11 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co if (!str.isEmpty() && scriptOrURL.startsWith(str)) { passList = true; qCDebug(scriptengine) << whitelistPrefix << "Script approved."; - break; // bail early since we found a match + break; // Bail early since we found a match. } } } - // END CHECKING AGAINST THE WHITELIST + // END processing of scripts through the whitelist. if (!passList) { // If the entity failed to pass for any reason, it's blocked and an error is thrown. qCDebug(scriptengine) << whitelistPrefix << "(disabled entity script)" << entityID.toString() << scriptOrURL;