History

merged 0.80.0-kasen into 0.81.0-kasen, 0.81.0-kasen source ready for build.

various changes, idk, added a whitelist filter to ent script filter

Revofire committed 7 years ago

Commit 47af4061 parent 576f41f7 files · +89 −32Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 7 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+56−7
@@ -252,7 +252,7 @@ QString ScriptEngine::getContext() const { · 251 unmodified lines
252 return "unknown";252 return "unknown";
253}253}
254 254
255bool ScriptEngine::isDebugMode() const { 255bool ScriptEngine::isDebugMode() const {
256#if defined(DEBUG)256#if defined(DEBUG)
257 return true;257 return true;
258#else258#else
@@ -769,6 +769,11 @@ void ScriptEngine::init() { · 510 unmodified lines
769#if DEV_BUILD || PR_BUILD769#if DEV_BUILD || PR_BUILD
770 registerGlobalObject("StackTest", new StackTestScriptingInterface(this));770 registerGlobalObject("StackTest", new StackTestScriptingInterface(this));
771#endif771#endif
772
773 globalObject().setProperty("KALILA", "isWaifu");
774 globalObject().setProperty("Kute", newFunction([](QScriptContext* context, QScriptEngine* engine) -> QScriptValue {
775 return context->argument(0).toString().toLower() == "kalila" ? true : false;
776 }));
772}777}
773 778
774void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {779void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
@@ -2252,6 +2257,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 1477 unmodified lines
2252 BaseScriptEngine sandbox;2257 BaseScriptEngine sandbox;
2253 sandbox.setProcessEventsInterval(SANDBOX_TIMEOUT);2258 sandbox.setProcessEventsInterval(SANDBOX_TIMEOUT);
2254 QScriptValue testConstructor, exception;2259 QScriptValue testConstructor, exception;
2260 if (atoi(getenv("UNSAFE_ENTITY_SCRIPTS") ? getenv("UNSAFE_ENTITY_SCRIPTS") : "0"))
2255 {2261 {
2256 QTimer timeout;2262 QTimer timeout;
2257 timeout.setSingleShot(true);2263 timeout.setSingleShot(true);
@@ -2274,13 +2280,57 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 16 unmodified lines
2274 exception = testConstructor;2280 exception = testConstructor;
2275 }2281 }
2276 }2282 }
2283 else {
2284 // IF YOU FUCK UP, DELETE FROM HERE TO...
2285 QList<QString> safeURLS = { "https://animedeck.com/", "http://animedeck.com/" };
2286 safeURLS += qEnvironmentVariable("EXTRA_WHITELIST").split(QRegExp("\\s*,\\s*"), QString::SkipEmptyParts);
2287
2288 bool isInWhitelist = false; // assume unsafe
2289 for (const auto& str : safeURLS) {
2290 // qDebug() << "CHECKING" << entityID.toString() << scriptOrURL << "AGAINST" << str;
2291 qDebug() << "SCRIPTOURL STARTSWITH" << scriptOrURL << "TESTING AGAINST" << str << "RESULTS IN"
2292 << scriptOrURL.startsWith(str);
2293 if (scriptOrURL.startsWith(str)) {
2294 isInWhitelist = true;
2295 break; // bail early since we found a match
2296 }
2297 }
2298 if (!isInWhitelist) {
2299 qDebug() << "(disabled entity script)" << entityID.toString() << scriptOrURL;
2300 exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0");
2301 } else {
2302 QTimer timeout;
2303 timeout.setSingleShot(true);
2304 timeout.start(SANDBOX_TIMEOUT);
2305 connect(&timeout, &QTimer::timeout, [=, &sandbox] {
2306 qCDebug(scriptengine) << "ScriptEngine::entityScriptContentAvailable timeout";
2307
2308 // Guard against infinite loops and non-performant code
2309 sandbox.raiseException(
2310 sandbox.makeError(QString("Timed out (entity constructors are limited to %1ms)").arg(SANDBOX_TIMEOUT)));
2311 });
2312
2313 testConstructor = sandbox.evaluate(program);
2314
2315 if (sandbox.hasUncaughtException()) {
2316 exception = sandbox.cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));
2317 sandbox.clearExceptions();
2318 } else if (testConstructor.isError()) {
2319 exception = testConstructor;
2320 }
2321 }
2322 // DELETE UP TO HERE, THEN UNCOMMENT BELOW.
2323
2324 // qDebug() << "(disabled entity script)" << entityID.toString() << scriptOrURL;
2325 // exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0");
2326 }
2277 2327
2278 if (exception.isError()) {2328 if (exception.isError()) {
2279 // create a local copy using makeError to decouple from the sandbox engine2329 // create a local copy using makeError to decouple from the sandbox engine
2280 exception = makeError(exception);2330 exception = makeError(exception);
2281 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);2331 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);
2282 emit unhandledException(exception);2332 emit unhandledException(exception);
2283 return;2333 return;
2284 }2334 }
2285 2335
2286 // CONSTRUCTOR VIABILITY2336 // CONSTRUCTOR VIABILITY
@@ -2648,4 +2698,3 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 361 unmodified lines
2648 }2698 }
2649 }2699 }
2650}2700}
2651