From d90ac93bf59f52c8ad1441447906d3cf0c0e96b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 27 Mar 2022 02:59:24 +0000 Subject: [PATCH 01/11] Bump minimist from 1.2.5 to 1.2.6 Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60f86b4e..630dc221 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5538,9 +5538,9 @@ } }, "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "node_modules/minimist-options": { @@ -13926,9 +13926,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "minimist-options": { From f338682ffcad5feadaa066458f5328f7d5cf3b78 Mon Sep 17 00:00:00 2001 From: quoid Date: Wed, 25 May 2022 22:36:46 -0400 Subject: [PATCH 02/11] remove superfluous error logs --- extension/Userscripts Extension/Functions.swift | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 57534e8c..1d2d0d0f 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -520,8 +520,6 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]] if fn == filename, let index = manifest.match[pattern]?.firstIndex(of: filename) { manifest.match[pattern]?.remove(at: index) update = true - } else { - err("updateManifestDeclarativeNetRequests failed at (2), \(filename)") } } } @@ -530,8 +528,6 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]] if fn == filename, let index = manifest.excludeMatch[pattern]?.firstIndex(of: filename) { manifest.excludeMatch[pattern]?.remove(at: index) update = true - } else { - err("updateManifestDeclarativeNetRequests failed at (3), \(filename)") } } } @@ -540,8 +536,6 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]] if fn == filename, let index = manifest.include[pattern]?.firstIndex(of: filename) { manifest.include[pattern]?.remove(at: index) update = true - } else { - err("updateManifestDeclarativeNetRequests failed at (4), \(filename)") } } } @@ -550,13 +544,11 @@ func updateManifestDeclarativeNetRequests(_ optionalFilesArray: [[String: Any]] if fn == filename, let index = manifest.exclude[pattern]?.firstIndex(of: filename) { manifest.exclude[pattern]?.remove(at: index) update = true - } else { - err("updateManifestDeclarativeNetRequests failed at (5), \(filename)") } } } if update, !updateManifest(with: manifest) { - err("updateManifestDeclarativeNetRequests failed at (6)") + err("updateManifestDeclarativeNetRequests failed at (2)") return false } } From a30c0613d51451efa51e67d8924785381524f740 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Jun 2022 01:37:12 +0000 Subject: [PATCH 03/11] Bump copy-props from 2.0.4 to 2.0.5 in /etc/app_ios Bumps [copy-props](https://github.com/gulpjs/copy-props) from 2.0.4 to 2.0.5. - [Release notes](https://github.com/gulpjs/copy-props/releases) - [Changelog](https://github.com/gulpjs/copy-props/blob/master/CHANGELOG.md) - [Commits](https://github.com/gulpjs/copy-props/compare/2.0.4...2.0.5) --- updated-dependencies: - dependency-name: copy-props dependency-type: indirect ... Signed-off-by: dependabot[bot] --- etc/app_ios/package-lock.json | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/etc/app_ios/package-lock.json b/etc/app_ios/package-lock.json index b18b9a57..1c121bf7 100644 --- a/etc/app_ios/package-lock.json +++ b/etc/app_ios/package-lock.json @@ -1276,13 +1276,22 @@ } }, "node_modules/copy-props": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/copy-props/-/copy-props-2.0.4.tgz", - "integrity": "sha512-7cjuUME+p+S3HZlbllgsn2CDwS+5eCCX16qBgNC4jgSTf49qR1VKy/Zhl400m0IQXl/bPGEVqncgUUMjrr4s8A==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/copy-props/-/copy-props-2.0.5.tgz", + "integrity": "sha512-XBlx8HSqrT0ObQwmSzM7WE5k8FxTV75h1DX1Z3n6NhQ/UYYAvInWYmG06vFt7hQZArE2fuO62aihiWIVQwh1sw==", "dev": true, "dependencies": { - "each-props": "^1.3.0", - "is-plain-object": "^2.0.1" + "each-props": "^1.3.2", + "is-plain-object": "^5.0.0" + } + }, + "node_modules/copy-props/node_modules/is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", + "dev": true, + "engines": { + "node": ">=0.10.0" } }, "node_modules/core-util-is": { @@ -8905,13 +8914,21 @@ "dev": true }, "copy-props": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/copy-props/-/copy-props-2.0.4.tgz", - "integrity": "sha512-7cjuUME+p+S3HZlbllgsn2CDwS+5eCCX16qBgNC4jgSTf49qR1VKy/Zhl400m0IQXl/bPGEVqncgUUMjrr4s8A==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/copy-props/-/copy-props-2.0.5.tgz", + "integrity": "sha512-XBlx8HSqrT0ObQwmSzM7WE5k8FxTV75h1DX1Z3n6NhQ/UYYAvInWYmG06vFt7hQZArE2fuO62aihiWIVQwh1sw==", "dev": true, "requires": { - "each-props": "^1.3.0", - "is-plain-object": "^2.0.1" + "each-props": "^1.3.2", + "is-plain-object": "^5.0.0" + }, + "dependencies": { + "is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", + "dev": true + } } }, "core-util-is": { From be5d32cc716f79c50c10e119ba1b78117e90667b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Jun 2022 01:37:19 +0000 Subject: [PATCH 04/11] Bump async from 2.6.3 to 2.6.4 in /etc/app_ios Bumps [async](https://github.com/caolan/async) from 2.6.3 to 2.6.4. - [Release notes](https://github.com/caolan/async/releases) - [Changelog](https://github.com/caolan/async/blob/v2.6.4/CHANGELOG.md) - [Commits](https://github.com/caolan/async/compare/v2.6.3...v2.6.4) --- updated-dependencies: - dependency-name: async dependency-type: indirect ... Signed-off-by: dependabot[bot] --- etc/app_ios/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/app_ios/package-lock.json b/etc/app_ios/package-lock.json index b18b9a57..f616e835 100644 --- a/etc/app_ios/package-lock.json +++ b/etc/app_ios/package-lock.json @@ -474,9 +474,9 @@ } }, "node_modules/async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "dependencies": { "lodash": "^4.17.14" @@ -8230,9 +8230,9 @@ "dev": true }, "async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "requires": { "lodash": "^4.17.14" From 12ebd31ee992838e798bcd6c4cad757628deeb65 Mon Sep 17 00:00:00 2001 From: quoid Date: Mon, 13 Jun 2022 22:30:18 -0400 Subject: [PATCH 05/11] bump versions and build --- .../Resources/manifest.json | 2 +- .../Userscripts.xcodeproj/project.pbxproj | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/extension/Userscripts Extension/Resources/manifest.json b/extension/Userscripts Extension/Resources/manifest.json index 563d724c..2dfcae1d 100644 --- a/extension/Userscripts Extension/Resources/manifest.json +++ b/extension/Userscripts Extension/Resources/manifest.json @@ -4,7 +4,7 @@ "default_locale": "en", "name": "__MSG_extension_name__", "description": "__MSG_extension_description__", - "version": "4.2.0", + "version": "4.2.1", "icons": { "48": "images/icon-48.png", "96": "images/icon-96.png", diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index 972f026d..c63cc918 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -663,7 +663,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS/Userscripts-iOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 24; + CURRENT_PROJECT_VERSION = 25; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -679,7 +679,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2; + MARKETING_VERSION = 1.2.1; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -704,7 +704,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS/Userscripts-iOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 24; + CURRENT_PROJECT_VERSION = 25; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -720,7 +720,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2; + MARKETING_VERSION = 1.2.1; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -743,7 +743,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS Extension/Userscripts-iOS Extension.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 24; + CURRENT_PROJECT_VERSION = 25; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -755,7 +755,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.2; + MARKETING_VERSION = 1.2.1; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -776,7 +776,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS Extension/Userscripts-iOS Extension.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 24; + CURRENT_PROJECT_VERSION = 25; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -788,7 +788,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.2; + MARKETING_VERSION = 1.2.1; OTHER_LDFLAGS = ( "-framework", SafariServices, @@ -929,7 +929,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 52; + CURRENT_PROJECT_VERSION = 53; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -939,7 +939,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.0; + MARKETING_VERSION = 4.2.1; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -953,7 +953,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 52; + CURRENT_PROJECT_VERSION = 53; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -963,7 +963,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.0; + MARKETING_VERSION = 4.2.1; PRODUCT_BUNDLE_IDENTIFIER = "com.userscripts.macos.Userscripts-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -980,7 +980,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 52; + CURRENT_PROJECT_VERSION = 53; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -989,7 +989,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.0; + MARKETING_VERSION = 4.2.1; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -1005,7 +1005,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 52; + CURRENT_PROJECT_VERSION = 53; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -1014,7 +1014,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 4.2.0; + MARKETING_VERSION = 4.2.1; PRODUCT_BUNDLE_IDENTIFIER = com.userscripts.macos; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; From 24495caf45ba7a88165f25ed28071e22739da812 Mon Sep 17 00:00:00 2001 From: quoid Date: Mon, 13 Jun 2022 23:18:10 -0400 Subject: [PATCH 06/11] update how css is injected to fix iframe injection #268 --- .../Userscripts Extension/Resources/content.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index 631d0ac1..3ee2a83b 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -90,7 +90,22 @@ function injectJS(name, filename, code, scope, fallback) { function injectCSS(name, code) { console.info(`Injecting ${name} %c(css)`, "color: #60f36c"); - browser.runtime.sendMessage({name: "API_ADD_STYLE_SYNC", css: code}); + // Safari lacks full support for tabs.insertCSS + // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/insertCSS + // specifically frameId and cssOrigin + // if support for those details keys arrives, the method below can be used + // NOTE: manifest V3 does support frameId, but not origin + // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/insertCSS + + // browser.runtime.sendMessage({name: "API_ADD_STYLE_SYNC", css: code}); + + // write the css code to head of the document + let wrapper = "const tag = document.createElement(\"style\");\n"; + wrapper += `tag.textContent = \`${code}\`;`; + wrapper += "\ndocument.head.appendChild(tag);"; + // eval the code directly into the context of the content script (not page context) + // wrapper += "console.log(window.browser)"; // this validates the execution env + eval(wrapper); } function cspFallback(e) { From 3b253f44aff70dd7b1a8659735d0ce03f2f942c1 Mon Sep 17 00:00:00 2001 From: quoid Date: Tue, 21 Jun 2022 21:26:42 -0400 Subject: [PATCH 07/11] changes to `@inject-into` when `@grant` has value #265 --- README.md | 3 ++- extension/Userscripts Extension/Functions.swift | 4 ++-- extension/Userscripts Extension/Resources/content.js | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dd835171..5a9021fd 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,8 @@ Userscripts Safari currently supports the following userscript metadata: - `@exclude` - Functions in a similar way as `@include` but rather than injecting, a match against this key's value will prevent injection - `@inject-into` - allows the user to choose which context to inject the script into - allows the user to choose which context to inject the script into - - values: `auto` (default), `content`, `page` + - values: `auto`, `content` (default), `page` + - `GM` apis are only available when using `content` - works like [violentmonkey](https://violentmonkey.github.io/api/metadata-block/#inject-into) - `@run-at` - allows the user to choose the injection timing diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index 1d2d0d0f..bbaaf9fb 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -1247,12 +1247,12 @@ func getCode(_ filenames: [String], _ isTop: Bool)-> [String: Any]? { weight = normalizeWeight(weight) // get inject-into and set default if missing - var injectInto = metadata["inject-into"]?[0] ?? "auto" + var injectInto = metadata["inject-into"]?[0] ?? "content" let injectVals: Set = ["auto", "content", "page"] let runAtVals: Set = ["context-menu", "document-start", "document-end", "document-idle"] // if either is invalid use default value if !injectVals.contains(injectInto) { - injectInto = "auto" + injectInto = "content" } if !runAtVals.contains(runAt) { runAt = "document-end" diff --git a/extension/Userscripts Extension/Resources/content.js b/extension/Userscripts Extension/Resources/content.js index 3ee2a83b..a138cbc8 100644 --- a/extension/Userscripts Extension/Resources/content.js +++ b/extension/Userscripts Extension/Resources/content.js @@ -19,6 +19,16 @@ browser.runtime.sendMessage({name: "REQ_USERSCRIPTS", uid: uid}, response => { data = response; for (let i = 0; i < data.files.js.length; i++) { const userscript = data.files.js[i]; + if ( + userscript.scriptObject?.grants?.length + && ( + userscript.scriptObject["inject-into"] === "auto" + || userscript.scriptObject["inject-into"] === "page" + ) + ) { + userscript.scriptObject["inject-into"] = "content"; + console.warn(`${userscript.scriptObject.filename} had it's @inject-value automatically set to "content" because it has @grant values - see: https://github.com/quoid/userscripts/issues/252#issuecomment-1136637700`); + } processJS( userscript.scriptObject.name, userscript.scriptObject.filename, From 9985839f31e4458b7983e0899ebcc4946a0f4021 Mon Sep 17 00:00:00 2001 From: quoid Date: Fri, 1 Jul 2022 22:27:44 -0400 Subject: [PATCH 08/11] better updateURL and downloadURL validation #274 --- .../Userscripts Extension/Functions.swift | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/extension/Userscripts Extension/Functions.swift b/extension/Userscripts Extension/Functions.swift index bbaaf9fb..4faa938d 100644 --- a/extension/Userscripts Extension/Functions.swift +++ b/extension/Userscripts Extension/Functions.swift @@ -137,9 +137,34 @@ func openSaveLocation() -> Bool { } func validateUrl(_ urlString: String) -> Bool { + var urlChecked = urlString + // if the url is already encoded, decode it + if isEncoded(urlChecked) { + if let decodedUrl = urlChecked.removingPercentEncoding { + urlChecked = decodedUrl + } else { + err("validateUrl failed at (1), couldn't decode url, \(urlString)") + return false + } + } + // encode all urls strings + if let encodedUrl = urlChecked.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) { + urlChecked = encodedUrl + } else { + err("validateUrl failed at (2), couldn't percent encode url, \(urlString)") + return false + } + guard + let parts = getUrlProps(urlChecked), + let ptcl = parts["protocol"], + let path = parts["pathname"] + else { + err("validateUrl failed at (3) for \(urlString)") + return false + } if - (!urlString.hasPrefix("https://") && !urlString.hasPrefix("http://")) - || (!urlString.hasSuffix(".css") && !urlString.hasSuffix(".js")) + (ptcl != "https:" && ptcl != "http:") + || (!path.hasSuffix(".css") && !path.hasSuffix(".js")) { return false } From 9a38f4433b3e45313b804e6f0aeb08ca2d2cadda Mon Sep 17 00:00:00 2001 From: quoid Date: Fri, 1 Jul 2022 22:29:01 -0400 Subject: [PATCH 09/11] test parsing file contents for remote updates #274 --- .../UserscriptsTests/UserscriptsTests.swift | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/extension/UserscriptsTests/UserscriptsTests.swift b/extension/UserscriptsTests/UserscriptsTests.swift index c1ab95dc..0e8fd27f 100644 --- a/extension/UserscriptsTests/UserscriptsTests.swift +++ b/extension/UserscriptsTests/UserscriptsTests.swift @@ -89,6 +89,34 @@ class UserscriptsTests: XCTestCase { XCTAssert(result.count == urls.count) } + func testFileRemoteUpdate() throws { + let urls = [ + "http://www.k21p.com/example.user.js", + "http://www.k21p.com/example.user.js?foo=bar", // query string + "http://www.k21p.com/example.user.js", // http protocol + "https://greasyfork.org/scripts/416338-redirect-外链跳转/code/redirect 外链跳转.user.js", // non latin chars + "http://www.k21p.com/example.user.jsx" // should fail + + ] + var result = [Int]() + for url in urls { + let content = """ + // ==UserScript== + // @name test + // @match *://*/* + // @version 0.1 + // @updateURL http://www.k21p.com/example.user.js + // @downloadURL \(url) + // ==/UserScript== + """; + let response = getFileRemoteUpdate(content) + if !response.keys.contains("error") { + result.append(1) + } + } + XCTAssert(result.count == (urls.count - 1)) + } + func testMatching() throws { let pattern = "*://www.google.com/*" let urls = [ From 5ccfc997c7091bedf9300ff3b685c421200fa79e Mon Sep 17 00:00:00 2001 From: quoid Date: Fri, 1 Jul 2022 22:30:02 -0400 Subject: [PATCH 10/11] update test urls protocols --- extension/UserscriptsTests/UserscriptsTests.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/UserscriptsTests/UserscriptsTests.swift b/extension/UserscriptsTests/UserscriptsTests.swift index 0e8fd27f..c3e1a608 100644 --- a/extension/UserscriptsTests/UserscriptsTests.swift +++ b/extension/UserscriptsTests/UserscriptsTests.swift @@ -91,11 +91,11 @@ class UserscriptsTests: XCTestCase { func testFileRemoteUpdate() throws { let urls = [ - "http://www.k21p.com/example.user.js", - "http://www.k21p.com/example.user.js?foo=bar", // query string + "https://www.k21p.com/example.user.js", + "https://www.k21p.com/example.user.js?foo=bar", // query string "http://www.k21p.com/example.user.js", // http protocol "https://greasyfork.org/scripts/416338-redirect-外链跳转/code/redirect 外链跳转.user.js", // non latin chars - "http://www.k21p.com/example.user.jsx" // should fail + "https://www.k21p.com/example.user.jsx" // should fail ] var result = [Int]() From b094a8934ec2952d94ca5d6611f65b728c48da26 Mon Sep 17 00:00:00 2001 From: quoid Date: Wed, 13 Jul 2022 09:31:47 -0400 Subject: [PATCH 11/11] update build --- extension/Userscripts.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extension/Userscripts.xcodeproj/project.pbxproj b/extension/Userscripts.xcodeproj/project.pbxproj index c63cc918..a82dbdd5 100644 --- a/extension/Userscripts.xcodeproj/project.pbxproj +++ b/extension/Userscripts.xcodeproj/project.pbxproj @@ -663,7 +663,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS/Userscripts-iOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 26; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -704,7 +704,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS/Userscripts-iOS.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 26; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS/Info.plist"; @@ -743,7 +743,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS Extension/Userscripts-iOS Extension.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 26; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -776,7 +776,7 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CODE_SIGN_ENTITLEMENTS = "Userscripts-iOS Extension/Userscripts-iOS Extension.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 26; DEVELOPMENT_TEAM = J74Q8V8V8N; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Userscripts-iOS Extension/Info.plist"; @@ -929,7 +929,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -953,7 +953,7 @@ CODE_SIGN_ENTITLEMENTS = "Userscripts Extension/Userscripts Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "Userscripts Extension/Info.plist"; @@ -980,7 +980,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist; @@ -1005,7 +1005,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 53; + CURRENT_PROJECT_VERSION = 54; DEVELOPMENT_TEAM = J74Q8V8V8N; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Userscripts/Info.plist;