Skip to content

GitHub Optional chaining resurgent #29

Closed as not planned
Closed as not planned
@dirkf

Description

@dirkf

See JustOff/github-wc-polyfill#68 (comment) for an example of this nonsense.

So I thought it should be possible to apply an edit to the GH scripts using this nice extension. If they say a.b.c?.d, we should be able to replace that with ((_x=>(_x==null)?undefined:_x.d)(a.b.c)). There was already a minor example in the gh-script-optchain fix (which I renamed below after removing that).

I edited lib/main.js, also removing an undefined diagnostic for fixes.a:

--- a/lib/main.js
+++ b/lib/main.js
@@ -78,10 +78,14 @@ function evaluateFix(fix, script, csp, contentReplace) {
                           "data-module-id": "./chunk-index2.js",
                           "data-src": "https://github.githubassets.com/assets/chunk-index2-a3fdc9f7.js"});
             break;
-        case "gh-script-optchain":
+        case "gh-script-nullish":
             // works only for this specific minimizer output...
-            contentReplace.push([/([a-zA-Z]+)\?\?/g, "((typeof($1)!==undefined)&&($1!==null))?($1):"]);
-            contentReplace.push([`this.matchFields?.join("-")`, `((y)=>y?y.join("-"):y)(this.matchFields)`]);
+            contentReplace.push([/([a-zA-Z_$][a-zA-Z_$0-9]*)\?\?/g, "((typeof($1)!==undefined)&&($1!==null))?($1):"]);
+            contentReplace.push([`H.integrity=S.sriHashes[t],`, ``]);
+            break;
+        case "gh-script-optchain":
+            contentReplace.push([/(([a-zA-Z_$][a-zA-Z_$0-9]*\.)*([a-zA-Z_$][a-zA-Z_$0-9]*))\?\.([a-zA-Z_$][a-zA-Z_$0-9]*)/g,
+                                "((_x => (_x==null)?undefined:_x.$3)($1))"]);
             contentReplace.push([`H.integrity=S.sriHashes[t],`, ``]);
             break;
         case "gh-worker-csp":
@@ -158,7 +162,7 @@ function supersededFixes(service) {
         superseded.add("tmx-optchain");
     }
     if (service.isNullishCoalescingSupported) {
-        superseded.add("gh-script-optchain");
+        superseded.add("gh-script-nullish");
     }
     return superseded;
 }
@@ -814,7 +818,7 @@ class HTTPObserver {
                 }
                 break;
             case "http-on-modify-request":
-                if (gService.isSeaMonkey && fixes.a.includes("sm-cookie")) {
+                if (gService.isSeaMonkey && fixes.fixes.includes("sm-cookie")) {
                     try {
                         this.cookie = subject.getRequestHeader("Cookie");
                     } catch (e) {

and lib/builtin-rules.js:

--- a/lib/builtin-rules.js
+++ b/lib/builtin-rules.js
@@ -11,7 +11,7 @@
 // For easier maintainability, please keep in logical-alphabetical order:
 //   generally sorted by host name part, minus "www."
 //   "www.dhl.de" sorts as "dhl"
-//   "static.ce-cdn.net" sorts together with it's parent, "godbolt.org"
+//   "static.ce-cdn.net" sorts together with its parent, "godbolt.org"
 
 exports = String.raw`
 developer.apple.com
@@ -31,6 +31,9 @@ gist.github.com/socket-worker.js$script
 github.com/assets-cdn/worker/socket-worker-*.js$script
 gist.github.com/assets-cdn/worker/socket-worker-*.js$script
     gh-worker-csp
+github.githubassets.com/assets/*.js$script
+    $script-content,gh-script-optchain
+
 ! --
 godbolt.org
     std-queueMicrotask

(Anyone who asks why this isn't a GH PR should try making one when GH scripts aren't working)

Now, I've abolished the console errors, but apparently the scripts are failing silently. I'm getting this
None of the "sha512" hashes in the integrity attribute match the content of the subresource.
apparently from the catch at the end of TracingListener.onStopRequest.

Any advice?

Metadata

Metadata

Assignees

No one assigned

    Labels

    js-syntaxProblem caused by unsupported JS syntaxwontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions