htmlcs: hide UMD loader globals during HTMLCS.js injection so HTMLCS_RUNNER reaches window (fixes #47)#52
Open
wittjeff wants to merge 1 commit into
Open
Conversation
…ool#47) HTMLCS.js is a UMD bundle. On pages exposing an AMD loader (define.amd, e.g. Wix/Thunderbolt, RequireJS) or leaked CommonJS globals, its wrapper registers HTMLCS as a module and never attaches HTMLCS_RUNNER to window, so window.HTMLCS_RUNNER.run() throws and the whole act is reported prevented ("ERROR executing HTMLCS_RUNNER in the page"). Hide window.define/exports/module for the duration of the synchronous script insertion so the wrapper falls through to its browser-global branch, then restore them. Keeps the script-element injection (CSP-safe; no eval/new Function). Verified against a live Wix page (https://www.thesagemages.com): before = prevented, 0 instances; after = 61 standard instances, AMD loader intact afterward. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #47.
What
tests/htmlcs.jsnow hideswindow.define/window.exports/window.modulefor the duration of the (synchronous) HTMLCS.js script insertion, then restores them.Why
HTMLCS.js is a UMD bundle. On pages that expose an AMD loader (
define.amd— Wix/Thunderbolt, RequireJS) or leaked CommonJS globals, the UMD wrapper registers HTMLCS as a module instead of taking its browser-global branch, sowindow.HTMLCS_RUNNERis never defined.window.HTMLCS_RUNNER.run(actStandard)then throws, and the whole act is reported prevented (ERROR executing HTMLCS_RUNNER in the page) — htmlcs silently returns zero results on a broad class of real-world sites. Full analysis in #47.Hiding the loader globals makes the wrapper fall through to the browser-global branch; because the injected script executes synchronously, the globals are restored before any page code can observe their absence. The script-element injection is kept as-is, so CSP compatibility (no
eval/new Function) is unchanged.Verification
Live run against a hydrated Wix page (
https://www.thesagemages.com), htmlcs act only, testaro 75.2.1:ERROR executing HTMLCS_RUNNER in the pageThe page's AMD loader works normally after the run. We have been running this change in production as a patch-package patch across daily multi-site scans since June with no htmlcs regressions.