History

Guard against meaningless query and fragment parts.

howard-stearns committed 10 years ago

Commit f35c59c1 parent 1de3aaf1 file · +6 −3Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+6−3
@@ -898,6 +898,9 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 897 unmodified lines
898898 return sensitivity;
899899 };
900900
901+ // Guard against meaningless query and fragment parts.
902+ // Do NOT use PreferLocalFile as its behavior is unpredictable (e.g., on defaultScriptsLocation())
903+ const auto strippingFlags = QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment;
901904 for (QString file : includeFiles) {
902905 QUrl thisURL { resolvePath(file) };
903906 if (!_includedURLs.contains(thisURL)) {
@@ -905,13 +908,13 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 1 unmodified line
905908 (
906909 (currentSandboxURL.scheme() != "file") ||
907910 (
908− !thisURL.toString(QUrl::RemoveFilename).startsWith(defaultScriptsLocation().toString(), getSensitivity()) &&
909− !thisURL.toString(QUrl::RemoveFilename).startsWith(currentSandboxURL.toString(QUrl::RemoveFilename), getSensitivity())
911+ !thisURL.toString(strippingFlags).startsWith(defaultScriptsLocation().toString(), getSensitivity()) &&
912+ !thisURL.toString(strippingFlags).startsWith(currentSandboxURL.toString(strippingFlags), getSensitivity())
910913 )
911914 )
912915 ) {
913916 qCWarning(scriptengine) << "Script.include() ignoring file path" << thisURL << "outside of original entity script" << currentSandboxURL;
914− } else {
917+ } else {
915918 // We could also check here for CORS, but we don't yet.
916919 // It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here.
917920 urls.append(thisURL);