roxxie-proxy-u-prod 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +123 -0
- package/SOURCE.md +29 -0
- package/THIRD_PARTY_NOTICES.md +24 -0
- package/dist/assets/filters-Bu_3nHVy.bin +0 -0
- package/dist/assets/index-BdRlQ7d_.css +1 -0
- package/dist/assets/index-DcvPYWS3.js +3621 -0
- package/dist/assets/inject-BnVzMVpl.js +40 -0
- package/dist/assets/scramjet-C9HLwI-y.wasm +0 -0
- package/dist/defaultfavicon.png +0 -0
- package/dist/icon.png +0 -0
- package/dist/roxxie-icon.svg +12 -0
- package/embed.js +70 -0
- package/examples/single-page.html +25 -0
- package/package.json +42 -0
- package/runtime/controller.sw.js +273 -0
- package/runtime/index.html +18 -0
- package/runtime/localcontrollersw.js +7 -0
- package/runtime/roxxie-network.json +13 -0
- package/runtime/sw.js +6 -0
- package/scripts/build.mjs +344 -0
- package/scripts/smoke.mjs +123 -0
- package/scripts/verify.mjs +122 -0
- package/source/external/dreamlandjs/LICENSE +21 -0
- package/source/external/dreamlandjs/README.md +22 -0
- package/source/external/dreamlandjs/dist/core.d.ts +167 -0
- package/source/external/dreamlandjs/dist/core.js +2 -0
- package/source/external/dreamlandjs/dist/core.js.map +1 -0
- package/source/external/dreamlandjs/dist/core.size.html +4950 -0
- package/source/external/dreamlandjs/dist/js-runtime.d.ts +3 -0
- package/source/external/dreamlandjs/dist/js-runtime.js +2 -0
- package/source/external/dreamlandjs/dist/js-runtime.js.map +1 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.d.ts +1 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.js +2 -0
- package/source/external/dreamlandjs/dist/jsx-runtime.js.map +1 -0
- package/source/external/dreamlandjs/dist/motion.d.ts +19 -0
- package/source/external/dreamlandjs/dist/motion.js +2 -0
- package/source/external/dreamlandjs/dist/motion.js.map +1 -0
- package/source/external/dreamlandjs/dist/router.d.ts +48 -0
- package/source/external/dreamlandjs/dist/router.js +2 -0
- package/source/external/dreamlandjs/dist/router.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.client.d.ts +3 -0
- package/source/external/dreamlandjs/dist/ssr.client.js +2 -0
- package/source/external/dreamlandjs/dist/ssr.client.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.client.size.html +4950 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.d.ts +7 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.js +2 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.js.map +1 -0
- package/source/external/dreamlandjs/dist/ssr.hybrid.size.html +4950 -0
- package/source/external/dreamlandjs/dist/ssr.server.d.ts +11 -0
- package/source/external/dreamlandjs/dist/ssr.server.js +2373 -0
- package/source/external/dreamlandjs/dist/ssr.server.js.map +1 -0
- package/source/external/dreamlandjs/dist/types/core/consts.d.ts +16 -0
- package/source/external/dreamlandjs/dist/types/core/css/index.d.ts +11 -0
- package/source/external/dreamlandjs/dist/types/core/css/selectorParser.d.ts +50 -0
- package/source/external/dreamlandjs/dist/types/core/delegate.d.ts +10 -0
- package/source/external/dreamlandjs/dist/types/core/index.d.ts +9 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/child.d.ts +2 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/definitions.d.ts +76 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/dom.d.ts +28 -0
- package/source/external/dreamlandjs/dist/types/core/jsx/index.d.ts +14 -0
- package/source/external/dreamlandjs/dist/types/core/state/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/core/state/pointers.d.ts +37 -0
- package/source/external/dreamlandjs/dist/types/core/state/state.d.ts +13 -0
- package/source/external/dreamlandjs/dist/types/core/state/use.d.ts +11 -0
- package/source/external/dreamlandjs/dist/types/core/utils.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/js-runtime/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/jsx-runtime/index.d.ts +2 -0
- package/source/external/dreamlandjs/dist/types/motion/index.d.ts +15 -0
- package/source/external/dreamlandjs/dist/types/router/index.d.ts +45 -0
- package/source/external/dreamlandjs/dist/types/ssr/client/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/consts.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/serialize.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/common/types.d.ts +21 -0
- package/source/external/dreamlandjs/dist/types/ssr/hybrid/index.d.ts +4 -0
- package/source/external/dreamlandjs/dist/types/ssr/server/index.d.ts +7 -0
- package/source/external/dreamlandjs/dist/types/ssr/server/vdom.d.ts +71 -0
- package/source/external/dreamlandjs/dist/types/util/index.d.ts +1 -0
- package/source/external/dreamlandjs/dist/types/util/store.d.ts +26 -0
- package/source/external/dreamlandjs/dist/types/vite/css-minifier.d.ts +7 -0
- package/source/external/dreamlandjs/dist/types/vite/index.d.ts +11 -0
- package/source/external/dreamlandjs/dist/util.d.ts +29 -0
- package/source/external/dreamlandjs/dist/util.js +2 -0
- package/source/external/dreamlandjs/dist/util.js.map +1 -0
- package/source/external/dreamlandjs/dist/vite.d.ts +19 -0
- package/source/external/dreamlandjs/dist/vite.js +2 -0
- package/source/external/dreamlandjs/dist/vite.js.map +1 -0
- package/source/external/dreamlandjs/package.json +101 -0
- package/source/external/dreamlandjs/rollup.config.ts +302 -0
- package/source/external/dreamlandjs/rollup.plugins.ts +1134 -0
- package/source/external/dreamlandjs/src/core/consts.d.ts +16 -0
- package/source/external/dreamlandjs/src/core/consts.js +18 -0
- package/source/external/dreamlandjs/src/core/css/index.ts +111 -0
- package/source/external/dreamlandjs/src/core/css/selectorParser.ts +313 -0
- package/source/external/dreamlandjs/src/core/delegate.ts +28 -0
- package/source/external/dreamlandjs/src/core/index.ts +31 -0
- package/source/external/dreamlandjs/src/core/jsx/child.ts +91 -0
- package/source/external/dreamlandjs/src/core/jsx/definitions.ts +125 -0
- package/source/external/dreamlandjs/src/core/jsx/dom.ts +49 -0
- package/source/external/dreamlandjs/src/core/jsx/index.ts +289 -0
- package/source/external/dreamlandjs/src/core/state/index.ts +1 -0
- package/source/external/dreamlandjs/src/core/state/pointers.ts +310 -0
- package/source/external/dreamlandjs/src/core/state/state.ts +112 -0
- package/source/external/dreamlandjs/src/core/state/use.ts +82 -0
- package/source/external/dreamlandjs/src/core/utils.ts +48 -0
- package/source/external/dreamlandjs/src/js-runtime/index.ts +4 -0
- package/source/external/dreamlandjs/src/jsx-runtime/index.ts +3 -0
- package/source/external/dreamlandjs/src/motion/index.ts +156 -0
- package/source/external/dreamlandjs/src/router/index.tsx +394 -0
- package/source/external/dreamlandjs/src/router/tsconfig.json +9 -0
- package/source/external/dreamlandjs/src/ssr/client/index.ts +193 -0
- package/source/external/dreamlandjs/src/ssr/common/consts.ts +5 -0
- package/source/external/dreamlandjs/src/ssr/common/serialize.ts +115 -0
- package/source/external/dreamlandjs/src/ssr/common/types.ts +28 -0
- package/source/external/dreamlandjs/src/ssr/hybrid/index.ts +144 -0
- package/source/external/dreamlandjs/src/ssr/server/index.ts +157 -0
- package/source/external/dreamlandjs/src/ssr/server/tsconfig.json +7 -0
- package/source/external/dreamlandjs/src/ssr/server/vdom.ts +285 -0
- package/source/external/dreamlandjs/src/util/index.ts +10 -0
- package/source/external/dreamlandjs/src/util/store.ts +134 -0
- package/source/external/dreamlandjs/src/vite/css-minifier.ts +222 -0
- package/source/external/dreamlandjs/src/vite/index.ts +60 -0
- package/source/external/dreamlandjs/src/vite/tsconfig.json +7 -0
- package/source/external/dreamlandjs/tsconfig.json +15 -0
- package/source/package.json +48 -0
- package/source/packages/adrift-protocol/package.json +31 -0
- package/source/packages/adrift-protocol/src/index.ts +348 -0
- package/source/packages/adrift-protocol/tsconfig.json +18 -0
- package/source/packages/cdp/LICENSE +21 -0
- package/source/packages/cdp/README.md +47 -0
- package/source/packages/cdp/dist/chobitsu.js +2 -0
- package/source/packages/cdp/dist/chobitsu.js.map +1 -0
- package/source/packages/cdp/package.json +73 -0
- package/source/packages/cdp/script/build.js +15 -0
- package/source/packages/cdp/src/Chobitsu.ts +110 -0
- package/source/packages/cdp/src/domains/CSS.ts +378 -0
- package/source/packages/cdp/src/domains/CacheStorage.ts +8 -0
- package/source/packages/cdp/src/domains/DOM.ts +487 -0
- package/source/packages/cdp/src/domains/DOMDebugger.ts +109 -0
- package/source/packages/cdp/src/domains/DOMStorage.ts +122 -0
- package/source/packages/cdp/src/domains/Debugger.ts +25 -0
- package/source/packages/cdp/src/domains/IndexedDB.ts +207 -0
- package/source/packages/cdp/src/domains/Input.ts +177 -0
- package/source/packages/cdp/src/domains/Network.ts +251 -0
- package/source/packages/cdp/src/domains/Overlay.ts +230 -0
- package/source/packages/cdp/src/domains/Page.ts +296 -0
- package/source/packages/cdp/src/domains/Runtime.ts +273 -0
- package/source/packages/cdp/src/domains/Storage.ts +71 -0
- package/source/packages/cdp/src/index.d.ts +8 -0
- package/source/packages/cdp/src/index.ts +153 -0
- package/source/packages/cdp/src/lib/connector.ts +15 -0
- package/source/packages/cdp/src/lib/constants.ts +1 -0
- package/source/packages/cdp/src/lib/evaluate.ts +59 -0
- package/source/packages/cdp/src/lib/mutationObserver.ts +39 -0
- package/source/packages/cdp/src/lib/nodeManager.ts +142 -0
- package/source/packages/cdp/src/lib/objManager.ts +422 -0
- package/source/packages/cdp/src/lib/request.ts +313 -0
- package/source/packages/cdp/src/lib/resources.ts +59 -0
- package/source/packages/cdp/src/lib/scriptMananger.ts +62 -0
- package/source/packages/cdp/src/lib/stylesheet.ts +146 -0
- package/source/packages/cdp/src/lib/util.ts +105 -0
- package/source/packages/cdp/tsconfig.json +16 -0
- package/source/packages/cdp/webpack.config.js +48 -0
- package/source/packages/chrome/index.html +17 -0
- package/source/packages/chrome/package.json +41 -0
- package/source/packages/chrome/public/ROXXIE_NETWORK.md +22 -0
- package/source/packages/chrome/public/controller.sw.js +273 -0
- package/source/packages/chrome/public/defaultfavicon.png +0 -0
- package/source/packages/chrome/public/icon.png +0 -0
- package/source/packages/chrome/public/localcontrollersw.js +7 -0
- package/source/packages/chrome/public/roxxie-icon.svg +12 -0
- package/source/packages/chrome/public/roxxie-network.json +13 -0
- package/source/packages/chrome/public/sw.js +6 -0
- package/source/packages/chrome/src/App.tsx +269 -0
- package/source/packages/chrome/src/CDP.ts +285 -0
- package/source/packages/chrome/src/Tab/History.ts +186 -0
- package/source/packages/chrome/src/Tab/Tab.tsx +219 -0
- package/source/packages/chrome/src/Tab/screenshot.ts +66 -0
- package/source/packages/chrome/src/Tab/serialize.ts +221 -0
- package/source/packages/chrome/src/adblock/AdBlockPlugin.test.ts +159 -0
- package/source/packages/chrome/src/adblock/AdBlockPlugin.ts +232 -0
- package/source/packages/chrome/src/adblock/AdBlockService.test.ts +148 -0
- package/source/packages/chrome/src/adblock/AdBlockService.ts +166 -0
- package/source/packages/chrome/src/adblock/NOTICE.md +14 -0
- package/source/packages/chrome/src/adblock/assets/filters.bin +0 -0
- package/source/packages/chrome/src/adblock/index.ts +18 -0
- package/source/packages/chrome/src/assets/favicon.ts +4 -0
- package/source/packages/chrome/src/components/BookmarkPopup.tsx +101 -0
- package/source/packages/chrome/src/components/BookmarksStrip.tsx +150 -0
- package/source/packages/chrome/src/components/Button.tsx +99 -0
- package/source/packages/chrome/src/components/Checkbox.tsx +89 -0
- package/source/packages/chrome/src/components/DownloadsPopup.tsx +230 -0
- package/source/packages/chrome/src/components/Favicon.tsx +65 -0
- package/source/packages/chrome/src/components/Icon.tsx +29 -0
- package/source/packages/chrome/src/components/Input.tsx +82 -0
- package/source/packages/chrome/src/components/Menu.tsx +287 -0
- package/source/packages/chrome/src/components/Omnibar/BookmarkButton.tsx +73 -0
- package/source/packages/chrome/src/components/Omnibar/CircularProgress.tsx +83 -0
- package/source/packages/chrome/src/components/Omnibar/Omnibar.tsx +455 -0
- package/source/packages/chrome/src/components/Omnibar/OmnibarButton.tsx +48 -0
- package/source/packages/chrome/src/components/Omnibar/Omnibox.tsx +466 -0
- package/source/packages/chrome/src/components/Omnibar/SiteOptionsButton.tsx +52 -0
- package/source/packages/chrome/src/components/Omnibar/Suggestion.tsx +186 -0
- package/source/packages/chrome/src/components/Omnibar/UrlInput.tsx +198 -0
- package/source/packages/chrome/src/components/Omnibar/suggestions.ts +468 -0
- package/source/packages/chrome/src/components/Omnibar/utils.ts +11 -0
- package/source/packages/chrome/src/components/ReportBrokenSiteModal.tsx +279 -0
- package/source/packages/chrome/src/components/Shell.tsx +191 -0
- package/source/packages/chrome/src/components/SiteInformationPopup.tsx +96 -0
- package/source/packages/chrome/src/components/SmallIconButton.tsx +36 -0
- package/source/packages/chrome/src/components/StartScreen.tsx +386 -0
- package/source/packages/chrome/src/components/TabStrip/DragTab.tsx +546 -0
- package/source/packages/chrome/src/components/TabStrip/Sidebar.tsx +820 -0
- package/source/packages/chrome/src/components/TabStrip/TabHoverCard.tsx +87 -0
- package/source/packages/chrome/src/components/TabStrip/TabStrip.tsx +510 -0
- package/source/packages/chrome/src/components/TopSiteButton.tsx +234 -0
- package/source/packages/chrome/src/consts.ts +3 -0
- package/source/packages/chrome/src/icons.ts +70 -0
- package/source/packages/chrome/src/index.ts +168 -0
- package/source/packages/chrome/src/migrations/0-from-legacy.ts +6 -0
- package/source/packages/chrome/src/migrations/1-vertical-tab-settings.ts +15 -0
- package/source/packages/chrome/src/migrations/index.ts +42 -0
- package/source/packages/chrome/src/pages/AboutPage.tsx +37 -0
- package/source/packages/chrome/src/pages/DownloadsPage.tsx +133 -0
- package/source/packages/chrome/src/pages/HistoryPage.tsx +99 -0
- package/source/packages/chrome/src/pages/NewTabPage.tsx +264 -0
- package/source/packages/chrome/src/pages/PlaygroundPage.tsx +43 -0
- package/source/packages/chrome/src/pages/SettingsPage.tsx +1931 -0
- package/source/packages/chrome/src/proxy/Controller.ts +331 -0
- package/source/packages/chrome/src/proxy/ProxyFrame.ts +26 -0
- package/source/packages/chrome/src/proxy/cache.ts +487 -0
- package/source/packages/chrome/src/proxy/codec.ts +11 -0
- package/source/packages/chrome/src/proxy/contextitems.ts +180 -0
- package/source/packages/chrome/src/proxy/index.ts +5 -0
- package/source/packages/chrome/src/proxy/roxxie.ts +85 -0
- package/source/packages/chrome/src/proxy/scramjet.ts +642 -0
- package/source/packages/chrome/src/reset.css +124 -0
- package/source/packages/chrome/src/runtime-base.ts +16 -0
- package/source/packages/chrome/src/sentry.tsx +45 -0
- package/source/packages/chrome/src/services/DownloadsService.ts +136 -0
- package/source/packages/chrome/src/services/FaviconService.ts +161 -0
- package/source/packages/chrome/src/services/KVWrapper.ts +169 -0
- package/source/packages/chrome/src/services/ProfileService.ts +94 -0
- package/source/packages/chrome/src/services/Service.ts +10 -0
- package/source/packages/chrome/src/services/SettingsService.ts +108 -0
- package/source/packages/chrome/src/services/TabsService.ts +161 -0
- package/source/packages/chrome/src/startup.test.ts +129 -0
- package/source/packages/chrome/src/startup.ts +161 -0
- package/source/packages/chrome/src/style.css +229 -0
- package/source/packages/chrome/src/themes.ts +756 -0
- package/source/packages/chrome/src/util/StatefulClass.ts +31 -0
- package/source/packages/chrome/src/util/index.ts +74 -0
- package/source/packages/chrome/src/util/memoize.ts +13 -0
- package/source/packages/chrome/src/vite-env.d.ts +16 -0
- package/source/packages/chrome/tsconfig.json +30 -0
- package/source/packages/chrome/vite.config.ts +47 -0
- package/source/packages/inject/package.json +20 -0
- package/source/packages/inject/src/context.ts +194 -0
- package/source/packages/inject/src/emulators/alwaysLastBubble.ts +168 -0
- package/source/packages/inject/src/emulators/anchors.ts +55 -0
- package/source/packages/inject/src/emulators/contextmenu.ts +46 -0
- package/source/packages/inject/src/emulators/history.ts +51 -0
- package/source/packages/inject/src/emulators/titlewatcher.ts +42 -0
- package/source/packages/inject/src/emulators/windowopen.ts +134 -0
- package/source/packages/inject/src/errorpage/errorpage.css +234 -0
- package/source/packages/inject/src/errorpage/errorpage.html +29 -0
- package/source/packages/inject/src/errorpage/errorpage.ts +76 -0
- package/source/packages/inject/src/index.ts +62 -0
- package/source/packages/inject/src/transport.ts +97 -0
- package/source/packages/inject/src/types.d.ts +136 -0
- package/source/packages/roxxie-transport/package.json +36 -0
- package/source/packages/roxxie-transport/src/binary.ts +398 -0
- package/source/packages/roxxie-transport/src/config.ts +254 -0
- package/source/packages/roxxie-transport/src/connection.ts +767 -0
- package/source/packages/roxxie-transport/src/index.ts +5 -0
- package/source/packages/roxxie-transport/src/tracker.ts +651 -0
- package/source/packages/roxxie-transport/src/transport.ts +414 -0
- package/source/packages/roxxie-transport/tsconfig.json +18 -0
- package/source/packages/scramjet/packages/controller/package.json +37 -0
- package/source/packages/scramjet/packages/controller/src/index.ts +861 -0
- package/source/packages/scramjet/packages/controller/src/inject.ts +365 -0
- package/source/packages/scramjet/packages/controller/src/sw.ts +231 -0
- package/source/packages/scramjet/packages/controller/src/symbols.ts +1 -0
- package/source/packages/scramjet/packages/controller/src/types.d.ts +140 -0
- package/source/packages/scramjet/packages/controller/src/typesEntry.ts +6 -0
- package/source/packages/scramjet/packages/controller/src/version.ts +30 -0
- package/source/packages/scramjet/packages/controller/tsconfig.json +24 -0
- package/source/packages/scramjet/packages/core/dist/scramjet-external.mjs +57 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.js +13599 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.mjs +13649 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.mjs.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet.wasm +0 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.js +13601 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.mjs +13651 -0
- package/source/packages/scramjet/packages/core/dist/scramjet_bundled.mjs.map +1 -0
- package/source/packages/scramjet/packages/core/dist/temp-types-build/index.js +23 -0
- package/source/packages/scramjet/packages/core/dist/temp-types-build/index.js.map +1 -0
- package/source/packages/scramjet/packages/core/dist/types/Tap.d.ts +39 -0
- package/source/packages/scramjet/packages/core/dist/types/client/client.d.ts +115 -0
- package/source/packages/scramjet/packages/core/dist/types/client/entry.d.ts +5 -0
- package/source/packages/scramjet/packages/core/dist/types/client/events.d.ts +10 -0
- package/source/packages/scramjet/packages/core/dist/types/client/helpers.d.ts +1 -0
- package/source/packages/scramjet/packages/core/dist/types/client/index.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/client/location.d.ts +2 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/eval.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/sourcemaps.d.ts +19 -0
- package/source/packages/scramjet/packages/core/dist/types/client/shared/wrap.d.ts +4 -0
- package/source/packages/scramjet/packages/core/dist/types/client/singletonbox.d.ts +18 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/body.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/fetch.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/headers.d.ts +19 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/index.d.ts +128 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/parse.d.ts +23 -0
- package/source/packages/scramjet/packages/core/dist/types/fetch/util.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/index.d.ts +12 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/cookie.d.ts +26 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/headers.d.ts +13 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/htmlRules.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/index.d.ts +50 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/mime.d.ts +53 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/refresh.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/css.d.ts +4 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/html.d.ts +33 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/index.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/js.d.ts +11 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/url.d.ts +24 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/wasm.d.ts +7 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/rewriters/worker.d.ts +3 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/set-cookie-parser.d.ts +20 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/snapshot.d.ts +186 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/sniffEncoding.d.ts +65 -0
- package/source/packages/scramjet/packages/core/dist/types/shared/util.d.ts +2 -0
- package/source/packages/scramjet/packages/core/dist/types/symbols.d.ts +6 -0
- package/source/packages/scramjet/packages/core/dist/types/types.d.ts +60 -0
- package/source/packages/scramjet/packages/core/dist/types/typesEntry.d.ts +5 -0
- package/source/packages/scramjet/packages/core/lib/index.cjs +7 -0
- package/source/packages/scramjet/packages/core/lib/index.d.ts +8 -0
- package/source/packages/scramjet/packages/core/package.json +69 -0
- package/source/packages/scramjet/packages/core/rewriter/Cargo.lock +1985 -0
- package/source/packages/scramjet/packages/core/rewriter/Cargo.toml +20 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/Cargo.toml +15 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/analyze.rs +1118 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/ast_table.rs +927 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/helper_index.rs +556 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/lib.rs +455 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/reachability.rs +85 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/templates.rs +192 -0
- package/source/packages/scramjet/packages/core/rewriter/coverage-macro/src/witness.rs +597 -0
- package/source/packages/scramjet/packages/core/rewriter/js/Cargo.toml +18 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/cfg.rs +45 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/changes.rs +379 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/lib.rs +171 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/rewrite.rs +290 -0
- package/source/packages/scramjet/packages/core/rewriter/js/src/visitor.rs +967 -0
- package/source/packages/scramjet/packages/core/rewriter/native/Cargo.toml +22 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/main.rs +166 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/rewriter.rs +161 -0
- package/source/packages/scramjet/packages/core/rewriter/native/src/test_runner.rs +156 -0
- package/source/packages/scramjet/packages/core/rewriter/rust-toolchain.toml +5 -0
- package/source/packages/scramjet/packages/core/rewriter/rustfmt.toml +2 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/Cargo.toml +16 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/src/lib.rs +242 -0
- package/source/packages/scramjet/packages/core/rewriter/transform/src/transform.rs +123 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/Cargo.toml +22 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/build.sh +128 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/error.rs +56 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/jsr.rs +125 -0
- package/source/packages/scramjet/packages/core/rewriter/wasm/src/lib.rs +144 -0
- package/source/packages/scramjet/packages/core/src/Tap.ts +166 -0
- package/source/packages/scramjet/packages/core/src/client/client.ts +916 -0
- package/source/packages/scramjet/packages/core/src/client/dom/attr.ts +94 -0
- package/source/packages/scramjet/packages/core/src/client/dom/beacon.ts +11 -0
- package/source/packages/scramjet/packages/core/src/client/dom/cookie.ts +21 -0
- package/source/packages/scramjet/packages/core/src/client/dom/css.ts +106 -0
- package/source/packages/scramjet/packages/core/src/client/dom/document.ts +140 -0
- package/source/packages/scramjet/packages/core/src/client/dom/element.ts +783 -0
- package/source/packages/scramjet/packages/core/src/client/dom/fontface.ts +11 -0
- package/source/packages/scramjet/packages/core/src/client/dom/fragments.ts +32 -0
- package/source/packages/scramjet/packages/core/src/client/dom/history.ts +35 -0
- package/source/packages/scramjet/packages/core/src/client/dom/open.ts +59 -0
- package/source/packages/scramjet/packages/core/src/client/dom/origin.ts +13 -0
- package/source/packages/scramjet/packages/core/src/client/dom/performance.ts +50 -0
- package/source/packages/scramjet/packages/core/src/client/dom/protocol.ts +17 -0
- package/source/packages/scramjet/packages/core/src/client/dom/storage.ts +107 -0
- package/source/packages/scramjet/packages/core/src/client/entry.ts +12 -0
- package/source/packages/scramjet/packages/core/src/client/events.ts +10 -0
- package/source/packages/scramjet/packages/core/src/client/helpers.ts +7 -0
- package/source/packages/scramjet/packages/core/src/client/index.ts +7 -0
- package/source/packages/scramjet/packages/core/src/client/location.ts +139 -0
- package/source/packages/scramjet/packages/core/src/client/shared/antiantidebugger.ts +20 -0
- package/source/packages/scramjet/packages/core/src/client/shared/blob.ts +35 -0
- package/source/packages/scramjet/packages/core/src/client/shared/caches.ts +31 -0
- package/source/packages/scramjet/packages/core/src/client/shared/chrome.ts +90 -0
- package/source/packages/scramjet/packages/core/src/client/shared/err.ts +55 -0
- package/source/packages/scramjet/packages/core/src/client/shared/error.ts +42 -0
- package/source/packages/scramjet/packages/core/src/client/shared/eval.ts +40 -0
- package/source/packages/scramjet/packages/core/src/client/shared/event.ts +215 -0
- package/source/packages/scramjet/packages/core/src/client/shared/function.ts +59 -0
- package/source/packages/scramjet/packages/core/src/client/shared/import.ts +46 -0
- package/source/packages/scramjet/packages/core/src/client/shared/indexeddb.ts +18 -0
- package/source/packages/scramjet/packages/core/src/client/shared/opfs.ts +27 -0
- package/source/packages/scramjet/packages/core/src/client/shared/postmessage.ts +113 -0
- package/source/packages/scramjet/packages/core/src/client/shared/realm.ts +26 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/eventsource.ts +17 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/fetch.ts +67 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/websocket.ts +389 -0
- package/source/packages/scramjet/packages/core/src/client/shared/requests/xmlhttprequest.ts +163 -0
- package/source/packages/scramjet/packages/core/src/client/shared/settimeout.ts +20 -0
- package/source/packages/scramjet/packages/core/src/client/shared/sourcemaps.ts +203 -0
- package/source/packages/scramjet/packages/core/src/client/shared/worker.ts +72 -0
- package/source/packages/scramjet/packages/core/src/client/shared/wrap.ts +197 -0
- package/source/packages/scramjet/packages/core/src/client/singletonbox.ts +52 -0
- package/source/packages/scramjet/packages/core/src/client/worker/importScripts.ts +13 -0
- package/source/packages/scramjet/packages/core/src/fetch/body.ts +93 -0
- package/source/packages/scramjet/packages/core/src/fetch/fetch.ts +323 -0
- package/source/packages/scramjet/packages/core/src/fetch/headers.ts +528 -0
- package/source/packages/scramjet/packages/core/src/fetch/index.ts +198 -0
- package/source/packages/scramjet/packages/core/src/fetch/parse.ts +149 -0
- package/source/packages/scramjet/packages/core/src/fetch/util.ts +81 -0
- package/source/packages/scramjet/packages/core/src/global.d.ts +32 -0
- package/source/packages/scramjet/packages/core/src/index.ts +78 -0
- package/source/packages/scramjet/packages/core/src/log.ts +117 -0
- package/source/packages/scramjet/packages/core/src/shared/cookie.ts +199 -0
- package/source/packages/scramjet/packages/core/src/shared/headers.ts +76 -0
- package/source/packages/scramjet/packages/core/src/shared/htmlRules.ts +154 -0
- package/source/packages/scramjet/packages/core/src/shared/index.ts +79 -0
- package/source/packages/scramjet/packages/core/src/shared/mime.ts +234 -0
- package/source/packages/scramjet/packages/core/src/shared/refresh.ts +164 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/css.ts +67 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/html.ts +603 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/index.ts +6 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/js.ts +158 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/url.ts +248 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/wasm.ts +58 -0
- package/source/packages/scramjet/packages/core/src/shared/rewriters/worker.ts +37 -0
- package/source/packages/scramjet/packages/core/src/shared/set-cookie-parser.ts +195 -0
- package/source/packages/scramjet/packages/core/src/shared/snapshot.ts +245 -0
- package/source/packages/scramjet/packages/core/src/shared/sniffEncoding.ts +1061 -0
- package/source/packages/scramjet/packages/core/src/shared/util.ts +35 -0
- package/source/packages/scramjet/packages/core/src/symbols.ts +9 -0
- package/source/packages/scramjet/packages/core/src/sync.ts +63 -0
- package/source/packages/scramjet/packages/core/src/types.ts +66 -0
- package/source/packages/scramjet/packages/core/src/typesEntry.ts +6 -0
- package/source/packages/scramjet/packages/core/tsconfig.json +21 -0
- package/source/packages/scramjet/packages/rpc/index.ts +100 -0
- package/source/packages/scramjet/packages/rpc/package.json +7 -0
- package/source/packages/scramjet/packages/utils/package.json +39 -0
- package/source/packages/scramjet/packages/utils/src/alwaysLastBubble.ts +172 -0
- package/source/packages/scramjet/packages/utils/src/catch-escaped-links.ts +34 -0
- package/source/packages/scramjet/packages/utils/src/event-handler-plugin.ts +86 -0
- package/source/packages/scramjet/packages/utils/src/global.d.ts +8 -0
- package/source/packages/scramjet/packages/utils/src/http-cache-plugin.ts +475 -0
- package/source/packages/scramjet/packages/utils/src/index.ts +26 -0
- package/source/packages/scramjet/packages/utils/src/link-handler-plugin.ts +75 -0
- package/source/packages/scramjet/packages/utils/src/typesEntry.ts +5 -0
- package/source/packages/scramjet/packages/utils/src/url-watcher.ts +37 -0
- package/source/packages/scramjet/packages/utils/src/version.ts +40 -0
- package/source/packages/scramjet/packages/utils/tsconfig.json +11 -0
- package/source/packages/scramjet/patches/htmlparser2@12.0.0.patch +124 -0
- package/source/packages/scramjet/rspack.config.ts +613 -0
- package/source/packages/scramjet/tsconfig.json +11 -0
- package/source/packages/tracker-protocol/package.json +31 -0
- package/source/packages/tracker-protocol/src/index.ts +745 -0
- package/source/packages/tracker-protocol/tsconfig.json +18 -0
- package/source/pnpm-lock.yaml +12018 -0
- package/source/pnpm-workspace.yaml +31 -0
- package/source/rspack.config.ts +103 -0
- package/source/scripts/update-adblock-assets.mjs +164 -0
- package/third_party/filter-lists/LICENSE-CC-BY-SA-3.0.txt +359 -0
- package/third_party/filter-lists/LICENSE-GPL-3.0.txt +674 -0
- package/third_party/filter-lists/LICENSE-MPL-2.0.txt +375 -0
- package/third_party/filter-lists/README.md +24 -0
- package/third_party/filter-lists/easylist.txt +83088 -0
- package/third_party/filter-lists/easyprivacy.txt +56361 -0
- package/third_party/filter-lists/manifest.json +56 -0
- package/third_party/filter-lists/ublock-filters.txt +10937 -0
- package/third_party/filter-lists/ublock-privacy.txt +3209 -0
- package/third_party/filter-lists/ublock-resources.json +1852 -0
- package/third_party/filter-lists/ublock-unbreak.txt +6026 -0
|
@@ -0,0 +1,967 @@
|
|
|
1
|
+
use std::error::Error;
|
|
2
|
+
|
|
3
|
+
use coverage_macro::coverage_checked;
|
|
4
|
+
use oxc::{
|
|
5
|
+
allocator::{Allocator, StringBuilder},
|
|
6
|
+
ast::ast::{
|
|
7
|
+
AssignmentExpression, AssignmentTarget, AssignmentTargetMaybeDefault,
|
|
8
|
+
AssignmentTargetProperty, AssignmentTargetPropertyIdentifier, BindingPattern,
|
|
9
|
+
BindingPatternKind, BindingProperty, CallExpression, ComputedMemberExpression,
|
|
10
|
+
DebuggerStatement, ExportAllDeclaration, ExportNamedDeclaration, Expression, ForStatement,
|
|
11
|
+
ForStatementInit, ForStatementLeft, FormalParameter, FunctionBody, IdentifierReference,
|
|
12
|
+
ImportDeclaration, ImportExpression, MemberExpression, MetaProperty, NewExpression,
|
|
13
|
+
ObjectAssignmentTarget, ObjectExpression, ObjectPattern, ObjectPropertyKind,
|
|
14
|
+
PrivateIdentifier, PropertyKey, ReturnStatement, SimpleAssignmentTarget, Statement,
|
|
15
|
+
StringLiteral, ThisExpression, UnaryExpression, UnaryOperator, UpdateExpression,
|
|
16
|
+
VariableDeclaration, VariableDeclarationKind, VariableDeclarator,
|
|
17
|
+
},
|
|
18
|
+
ast_visit::{Visit, walk},
|
|
19
|
+
span::{Atom, GetSpan, Span},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
use crate::{
|
|
23
|
+
cfg::{Config, Flags, UrlRewriter},
|
|
24
|
+
changes::JsChanges,
|
|
25
|
+
rewrite::rewrite,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// required stub markers
|
|
29
|
+
macro_rules! audit_skip { ($($t:tt)*) => {}; }
|
|
30
|
+
#[allow(unused)]
|
|
31
|
+
macro_rules! skip_field { ($($t:tt)*) => {}; }
|
|
32
|
+
|
|
33
|
+
// js MUST not be able to get a reference to any of these because sbx
|
|
34
|
+
//
|
|
35
|
+
// maybe move this out of this lib?
|
|
36
|
+
const UNSAFE_GLOBALS: &[&str] = &["parent", "top", "location", "eval"];
|
|
37
|
+
|
|
38
|
+
pub struct Visitor<'alloc, 'data, E>
|
|
39
|
+
where
|
|
40
|
+
E: UrlRewriter,
|
|
41
|
+
{
|
|
42
|
+
pub alloc: &'alloc Allocator,
|
|
43
|
+
pub jschanges: JsChanges<'alloc, 'data>,
|
|
44
|
+
pub error: Option<Box<dyn Error + Sync + Send>>,
|
|
45
|
+
|
|
46
|
+
pub config: &'data Config,
|
|
47
|
+
pub rewriter: &'data E,
|
|
48
|
+
pub flags: Flags,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
impl<'data, E> Visitor<'_, 'data, E>
|
|
52
|
+
where
|
|
53
|
+
E: UrlRewriter,
|
|
54
|
+
{
|
|
55
|
+
fn rewrite_url(&mut self, url: &StringLiteral<'data>, module: bool) {
|
|
56
|
+
let mut builder = StringBuilder::from_str_in(&self.config.prefix, self.alloc);
|
|
57
|
+
if self.error.is_some() {
|
|
58
|
+
builder.push_str("__URL_REWRITER_ALREADY_ERRORED__");
|
|
59
|
+
} else if let Err(err) =
|
|
60
|
+
self.rewriter
|
|
61
|
+
.rewrite(self.config, &self.flags, &url.value, &mut builder, module)
|
|
62
|
+
{
|
|
63
|
+
self.error.replace(err);
|
|
64
|
+
builder.push_str("__URL_REWRITER_ERROR__");
|
|
65
|
+
}
|
|
66
|
+
let text = builder.into_str();
|
|
67
|
+
|
|
68
|
+
self.jschanges
|
|
69
|
+
.add(rewrite!(url.span.shrink(1), Replace { text }));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn rewrite_ident(&mut self, name: &Atom, span: Span) {
|
|
73
|
+
if UNSAFE_GLOBALS.contains(&name.as_str()) {
|
|
74
|
+
self.jschanges.add(rewrite!(span, WrapFn { enclose: true }));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fn handle_computed_member_expression(&mut self, it: &ComputedMemberExpression<'data>) {
|
|
79
|
+
if self.flags.disable_computed_wrap { return };
|
|
80
|
+
match &it.expression {
|
|
81
|
+
Expression::NullLiteral(_)
|
|
82
|
+
| Expression::BigIntLiteral(_)
|
|
83
|
+
| Expression::NumericLiteral(_)
|
|
84
|
+
| Expression::RegExpLiteral(_)
|
|
85
|
+
| Expression::BooleanLiteral(_) => {}
|
|
86
|
+
Expression::StringLiteral(lit) => {
|
|
87
|
+
if UNSAFE_GLOBALS.contains(&lit.value.as_str()) {
|
|
88
|
+
self.jschanges
|
|
89
|
+
.add(rewrite!(it.expression.span(), WrapProperty,));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
_ => {
|
|
93
|
+
self.jschanges
|
|
94
|
+
.add(rewrite!(it.expression.span(), WrapProperty,));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn recurse_object_assignment_target(
|
|
100
|
+
&mut self,
|
|
101
|
+
s: &ObjectAssignmentTarget<'data>,
|
|
102
|
+
restids: &mut Vec<Atom<'data>>,
|
|
103
|
+
location_assigned: &mut bool,
|
|
104
|
+
) {
|
|
105
|
+
if let Some(r) = &s.rest {
|
|
106
|
+
// { ...rest } = self;
|
|
107
|
+
match &r.target {
|
|
108
|
+
AssignmentTarget::AssignmentTargetIdentifier(i) => {
|
|
109
|
+
if i.name == "location" {
|
|
110
|
+
self.jschanges.add(rewrite!(i.span, TempVar));
|
|
111
|
+
restids.push(self.alloc.alloc_str(&self.config.templocid).into());
|
|
112
|
+
*location_assigned = true;
|
|
113
|
+
} else {
|
|
114
|
+
restids.push(i.name);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_ => panic!("what?"),
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for prop in &s.properties {
|
|
121
|
+
match prop {
|
|
122
|
+
AssignmentTargetProperty::AssignmentTargetPropertyIdentifier(p) => {
|
|
123
|
+
// { location } = self;
|
|
124
|
+
// correct thing to do here is to change it into an AsignmentTargetPropertyProperty
|
|
125
|
+
// { $sj_location: location } = self;
|
|
126
|
+
if UNSAFE_GLOBALS.contains(&p.binding.name.to_string().as_str()) {
|
|
127
|
+
let mut tempvar = false;
|
|
128
|
+
if p.binding.name == "location" {
|
|
129
|
+
tempvar = true;
|
|
130
|
+
*location_assigned = true;
|
|
131
|
+
}
|
|
132
|
+
self.jschanges.add(rewrite!(
|
|
133
|
+
p.binding.span(),
|
|
134
|
+
RebindProperty {
|
|
135
|
+
ident: p.binding.name.clone(),
|
|
136
|
+
tempvar,
|
|
137
|
+
}
|
|
138
|
+
));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if let Some(d) = &p.init {
|
|
142
|
+
// { location = parent } = {};
|
|
143
|
+
// we still need to rewrite whatever stuff might be in the default expression
|
|
144
|
+
walk::walk_expression(self, &d);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
AssignmentTargetProperty::AssignmentTargetPropertyProperty(p) => {
|
|
148
|
+
// { location: x } = self;
|
|
149
|
+
// { location: x = "..."} = self;
|
|
150
|
+
// { location: { href } } = self;
|
|
151
|
+
// { location: { href: x } } = self;
|
|
152
|
+
// { ["location"]: x } = self;
|
|
153
|
+
|
|
154
|
+
match &p.name {
|
|
155
|
+
PropertyKey::StaticIdentifier(id) => {
|
|
156
|
+
// { location: x } = self;
|
|
157
|
+
if UNSAFE_GLOBALS.contains(&id.name.to_string().as_str()) {
|
|
158
|
+
self.jschanges.add(rewrite!(
|
|
159
|
+
p.name.span(),
|
|
160
|
+
RewriteProperty { ident: id.name }
|
|
161
|
+
));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
PropertyKey::StringLiteral(s) => {
|
|
165
|
+
if UNSAFE_GLOBALS.contains(&s.value.to_string().as_str()) {
|
|
166
|
+
self.jschanges.add(rewrite!(s.span(), RewriteProperty { ident: s.value }));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// this is really annoying, we have to list out all the things that *aren't* expressions, you can't just check if it is one
|
|
171
|
+
// otherwise { 0:location } rewrites to { scramjet$prop(0):location } which is obviously invalid syntax
|
|
172
|
+
PropertyKey::NumericLiteral(_) | PropertyKey::RegExpLiteral(_) | PropertyKey::BigIntLiteral(_) | PropertyKey::PrivateIdentifier(_) => {}
|
|
173
|
+
|
|
174
|
+
_ => {
|
|
175
|
+
// { ["location"]: x } = self;
|
|
176
|
+
self.jschanges.add(rewrite!(p.name.span(), WrapProperty));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let mut target;
|
|
181
|
+
|
|
182
|
+
if let Some(t) = p.binding.as_assignment_target() {
|
|
183
|
+
target = t;
|
|
184
|
+
} else {
|
|
185
|
+
match &p.binding {
|
|
186
|
+
AssignmentTargetMaybeDefault::AssignmentTargetWithDefault(d) => {
|
|
187
|
+
target = &d.binding;
|
|
188
|
+
// { location: x = parent } = {};
|
|
189
|
+
// we still need to rewrite whatever stuff might be in the default expression
|
|
190
|
+
walk::walk_expression(self, &d.init);
|
|
191
|
+
}
|
|
192
|
+
_=>unreachable!()
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
match &target {
|
|
197
|
+
AssignmentTarget::ObjectAssignmentTarget(p) => {
|
|
198
|
+
self.recurse_object_assignment_target(&p, restids, location_assigned);
|
|
199
|
+
}
|
|
200
|
+
AssignmentTarget::AssignmentTargetIdentifier(p) => {
|
|
201
|
+
if p.name == "location" {
|
|
202
|
+
self.jschanges.add(rewrite!(p.span(), TempVar));
|
|
203
|
+
*location_assigned = true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
AssignmentTarget::ArrayAssignmentTarget(a) => {
|
|
207
|
+
self.recurse_array_assignment_target(&a, restids, location_assigned);
|
|
208
|
+
}
|
|
209
|
+
_ => {}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
fn recurse_array_assignment_target(
|
|
216
|
+
&mut self,
|
|
217
|
+
s: &oxc::ast::ast::ArrayAssignmentTarget<'data>,
|
|
218
|
+
restids: &mut Vec<Atom<'data>>,
|
|
219
|
+
location_assigned: &mut bool,
|
|
220
|
+
) {
|
|
221
|
+
// note that i don't actually have to care about the rest param here since it wont have dangerous props. i still need to keep track of the object destructure rests though
|
|
222
|
+
for elem in &s.elements {
|
|
223
|
+
if let Some(elem) = elem {
|
|
224
|
+
match elem {
|
|
225
|
+
AssignmentTargetMaybeDefault::AssignmentTargetWithDefault(p) => {
|
|
226
|
+
if let Some(name) = p.binding.get_identifier_name()
|
|
227
|
+
&& name == "location"
|
|
228
|
+
{
|
|
229
|
+
self.jschanges.add(rewrite!(p.span(), TempVar));
|
|
230
|
+
*location_assigned = true;
|
|
231
|
+
}
|
|
232
|
+
walk::walk_expression(self, &p.init);
|
|
233
|
+
}
|
|
234
|
+
AssignmentTargetMaybeDefault::AssignmentTargetIdentifier(p) => {
|
|
235
|
+
if p.name == "location" {
|
|
236
|
+
self.jschanges.add(rewrite!(p.span(), TempVar));
|
|
237
|
+
*location_assigned = true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
AssignmentTargetMaybeDefault::ObjectAssignmentTarget(o) => {
|
|
241
|
+
self.recurse_object_assignment_target(o, restids, location_assigned);
|
|
242
|
+
}
|
|
243
|
+
AssignmentTargetMaybeDefault::ArrayAssignmentTarget(a) => {
|
|
244
|
+
self.recurse_array_assignment_target(a, restids, location_assigned);
|
|
245
|
+
}
|
|
246
|
+
_ => {}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
fn recurse_binding_pattern(
|
|
253
|
+
&mut self,
|
|
254
|
+
it: &BindingPattern<'data>,
|
|
255
|
+
restids: &mut Vec<Atom<'data>>,
|
|
256
|
+
no_shadow: bool,
|
|
257
|
+
location_assigned: &mut bool,
|
|
258
|
+
) {
|
|
259
|
+
match &it.kind {
|
|
260
|
+
BindingPatternKind::BindingIdentifier(p) => {
|
|
261
|
+
// let a = 0;
|
|
262
|
+
if no_shadow && p.name == "location" {
|
|
263
|
+
self.jschanges.add(rewrite!(p.span, TempVar));
|
|
264
|
+
*location_assigned = true;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
BindingPatternKind::AssignmentPattern(p) => {
|
|
268
|
+
// const {a = 1} = 1;
|
|
269
|
+
walk::walk_binding_pattern(self, &p.left);
|
|
270
|
+
walk::walk_expression(self, &p.right);
|
|
271
|
+
}
|
|
272
|
+
BindingPatternKind::ObjectPattern(p) => {
|
|
273
|
+
for prop in &p.properties {
|
|
274
|
+
match &prop.key {
|
|
275
|
+
PropertyKey::StaticIdentifier(id) => {
|
|
276
|
+
if UNSAFE_GLOBALS.contains(&id.name.to_string().as_str()) {
|
|
277
|
+
if prop.shorthand {
|
|
278
|
+
// const { location } = self;
|
|
279
|
+
let mut tempvar = false;
|
|
280
|
+
if no_shadow && id.name == "location" {
|
|
281
|
+
tempvar = true;
|
|
282
|
+
*location_assigned = true;
|
|
283
|
+
}
|
|
284
|
+
self.jschanges.add(rewrite!(
|
|
285
|
+
id.span(),
|
|
286
|
+
RebindProperty {
|
|
287
|
+
ident: id.name,
|
|
288
|
+
tempvar
|
|
289
|
+
}
|
|
290
|
+
));
|
|
291
|
+
|
|
292
|
+
// don't recurse into the value because the value is the same and it would double rewrite the prop
|
|
293
|
+
continue;
|
|
294
|
+
} else {
|
|
295
|
+
// const { location: a } = self;
|
|
296
|
+
if no_shadow && id.name == "location" {
|
|
297
|
+
self.jschanges.add(rewrite!(
|
|
298
|
+
id.span(),
|
|
299
|
+
RewriteProperty {
|
|
300
|
+
ident: self
|
|
301
|
+
.alloc
|
|
302
|
+
.alloc_str(&self.config.templocid)
|
|
303
|
+
.into()
|
|
304
|
+
}
|
|
305
|
+
));
|
|
306
|
+
*location_assigned = true;
|
|
307
|
+
} else {
|
|
308
|
+
self.jschanges.add(rewrite!(
|
|
309
|
+
id.span(),
|
|
310
|
+
RewriteProperty { ident: id.name }
|
|
311
|
+
));
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
PropertyKey::StringLiteral(id) => {
|
|
317
|
+
// const { "location": x } = self;
|
|
318
|
+
// this cannot be shorthand, so we can use the easy path
|
|
319
|
+
if UNSAFE_GLOBALS.contains(&id.value.to_string().as_str()) {
|
|
320
|
+
self.jschanges.add(rewrite!(
|
|
321
|
+
id.span.shrink(1),
|
|
322
|
+
RewriteProperty { ident: id.value }
|
|
323
|
+
));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// see comment in recurse_object_assignment_target
|
|
328
|
+
PropertyKey::NumericLiteral(_) | PropertyKey::RegExpLiteral(_) | PropertyKey::BigIntLiteral(_) | PropertyKey::PrivateIdentifier(_) => {}
|
|
329
|
+
|
|
330
|
+
_ => {
|
|
331
|
+
// const { ["location"]: x } = self;
|
|
332
|
+
self.jschanges.add(rewrite!(prop.key.span(), WrapProperty));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
self.recurse_binding_pattern(&prop.value, restids, no_shadow, location_assigned);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if let Some(r) = &p.rest {
|
|
339
|
+
match &r.argument.kind {
|
|
340
|
+
BindingPatternKind::BindingIdentifier(i) => {
|
|
341
|
+
if no_shadow && i.name == "location" {
|
|
342
|
+
self.jschanges.add(rewrite!(i.span, TempVar));
|
|
343
|
+
restids.push(self.alloc.alloc_str(&self.config.templocid).into());
|
|
344
|
+
*location_assigned = true;
|
|
345
|
+
} else {
|
|
346
|
+
restids.push(i.name);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
_ => panic!("what?"),
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
_ => {}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
fn handle_var_declarator(
|
|
358
|
+
&mut self,
|
|
359
|
+
v: &VariableDeclaration<'data>,
|
|
360
|
+
restids: &mut Vec<Atom<'data>>,
|
|
361
|
+
location_assigned: &mut bool,
|
|
362
|
+
) {
|
|
363
|
+
// (const/let) location = ... is perfectly fine, no matter the scope
|
|
364
|
+
// var location = ... is dangerous, it will assign to the real global if called in scope
|
|
365
|
+
let no_shadow = matches!(v.kind, VariableDeclarationKind::Var);
|
|
366
|
+
for dec in &v.declarations {
|
|
367
|
+
if let Some(ini) = &dec.init {
|
|
368
|
+
walk::walk_expression(self, ini);
|
|
369
|
+
}
|
|
370
|
+
self.recurse_binding_pattern(&dec.id, restids, no_shadow, location_assigned);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
fn handle_assignment_target_member(&mut self, target: &AssignmentTarget<'data>) {
|
|
375
|
+
match target {
|
|
376
|
+
AssignmentTarget::StaticMemberExpression(s) => {
|
|
377
|
+
// window.location = ...
|
|
378
|
+
if UNSAFE_GLOBALS.contains(&s.property.name.as_str()) {
|
|
379
|
+
self.jschanges.add(rewrite!(
|
|
380
|
+
s.property.span(),
|
|
381
|
+
RewriteProperty {
|
|
382
|
+
ident: s.property.name
|
|
383
|
+
}
|
|
384
|
+
));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// walk the left hand side of the member expression (`window` for the `window.location = ...` case)
|
|
388
|
+
walk::walk_expression(self, &s.object);
|
|
389
|
+
}
|
|
390
|
+
AssignmentTarget::ComputedMemberExpression(s) => {
|
|
391
|
+
// window["location"] = ...
|
|
392
|
+
self.handle_computed_member_expression(s);
|
|
393
|
+
// `window`
|
|
394
|
+
walk::walk_expression(self, &s.object);
|
|
395
|
+
// `"location"`
|
|
396
|
+
walk::walk_expression(self, &s.expression);
|
|
397
|
+
}
|
|
398
|
+
_ => {}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
fn handle_for_of_in(&mut self, left: &ForStatementLeft<'data>, right: &Expression<'data>, body: &Statement<'data>) {
|
|
403
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
404
|
+
let mut location_assigned: bool = false;
|
|
405
|
+
let declare_local_location: bool;
|
|
406
|
+
if let ForStatementLeft::VariableDeclaration(v) = &left {
|
|
407
|
+
self.handle_var_declarator(&v, &mut restids, &mut location_assigned);
|
|
408
|
+
// var { location } = ... is special because it will rewrite both the member access to $sj_location
|
|
409
|
+
// and the actual name of the variable to $scramjet$temploc so we can set it back later
|
|
410
|
+
// but this means that the variable location never actually gets assigned
|
|
411
|
+
// so if it was actually meant to be a local, it won't exist in scope
|
|
412
|
+
// we flag this here so it will be appended tos the variable declarations in cleanup
|
|
413
|
+
declare_local_location = location_assigned;
|
|
414
|
+
} else {
|
|
415
|
+
let target = left.as_assignment_target().unwrap();
|
|
416
|
+
match target {
|
|
417
|
+
AssignmentTarget::AssignmentTargetIdentifier(s) => {
|
|
418
|
+
if &s.name == "location" {
|
|
419
|
+
self.jschanges.add(rewrite!(s.span, TempVar));
|
|
420
|
+
location_assigned = true;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
AssignmentTarget::StaticMemberExpression(_) | AssignmentTarget::ComputedMemberExpression(_) => {
|
|
425
|
+
self.handle_assignment_target_member(target);
|
|
426
|
+
}
|
|
427
|
+
AssignmentTarget::ObjectAssignmentTarget(o) => {
|
|
428
|
+
self.recurse_object_assignment_target(o, &mut restids, &mut location_assigned);
|
|
429
|
+
}
|
|
430
|
+
AssignmentTarget::ArrayAssignmentTarget(a) => {
|
|
431
|
+
self.recurse_array_assignment_target(a, &mut restids, &mut location_assigned);
|
|
432
|
+
}
|
|
433
|
+
AssignmentTarget::PrivateFieldExpression(_) => {
|
|
434
|
+
// `for (location.#p of ...)`
|
|
435
|
+
audit_skip!("private field can never contain anything unsafe");
|
|
436
|
+
}
|
|
437
|
+
_ => {}
|
|
438
|
+
}
|
|
439
|
+
declare_local_location = false;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if location_assigned || restids.len() > 0 {
|
|
443
|
+
match &body {
|
|
444
|
+
Statement::BlockStatement(b) => {
|
|
445
|
+
self.jschanges.add(rewrite!(
|
|
446
|
+
Span::new(b.span.start + 1, b.span.end - 1),
|
|
447
|
+
CleanFunction {
|
|
448
|
+
restids,
|
|
449
|
+
location_assigned,
|
|
450
|
+
expression: false,
|
|
451
|
+
wrap: false,
|
|
452
|
+
declare_local_location,
|
|
453
|
+
}
|
|
454
|
+
));
|
|
455
|
+
}
|
|
456
|
+
Statement::BreakStatement(_)
|
|
457
|
+
| Statement::ContinueStatement(_)
|
|
458
|
+
| Statement::EmptyStatement(_)
|
|
459
|
+
| Statement::DebuggerStatement(_) => {}
|
|
460
|
+
_ => {
|
|
461
|
+
self.jschanges.add(rewrite!(
|
|
462
|
+
body.span(),
|
|
463
|
+
CleanFunction {
|
|
464
|
+
restids,
|
|
465
|
+
location_assigned,
|
|
466
|
+
expression: false,
|
|
467
|
+
wrap: true,
|
|
468
|
+
declare_local_location,
|
|
469
|
+
}
|
|
470
|
+
));
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
walk::walk_expression(self, &right);
|
|
475
|
+
walk::walk_statement(self, &body);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
fn scramitize(&mut self, span: Span) {
|
|
479
|
+
self.jschanges.add(rewrite!(span, Scramitize));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
impl<'data, E> Visit<'data> for Visitor<'_, 'data, E>
|
|
484
|
+
where
|
|
485
|
+
E: UrlRewriter,
|
|
486
|
+
{
|
|
487
|
+
#[coverage_checked(IdentifierReference)]
|
|
488
|
+
fn visit_identifier_reference(&mut self, it: &IdentifierReference) {
|
|
489
|
+
if UNSAFE_GLOBALS.contains(&it.name.as_str()) {
|
|
490
|
+
self.jschanges
|
|
491
|
+
.add(rewrite!(it.span, WrapFn { enclose: false }));
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
#[coverage_checked(NewExpression)]
|
|
496
|
+
fn visit_new_expression(&mut self, it: &NewExpression<'data>) {
|
|
497
|
+
match &it.callee {
|
|
498
|
+
Expression::StaticMemberExpression(_) | Expression::Identifier(_) => {
|
|
499
|
+
// new top(), new location.top(), etc
|
|
500
|
+
// rewriting to new $wrap(location).top() WILL change semantics
|
|
501
|
+
// so it has to be wrapped to new ($wrap(location).top)()
|
|
502
|
+
// TODO: skip paren wrap if it's determined to be safe
|
|
503
|
+
self.jschanges.add(rewrite!(it.callee.span(), WrapNew));
|
|
504
|
+
walk::walk_expression(self, &it.callee);
|
|
505
|
+
}
|
|
506
|
+
Expression::ComputedMemberExpression(c) => {
|
|
507
|
+
walk::walk_expression(self, &c.expression);
|
|
508
|
+
}
|
|
509
|
+
_=>{
|
|
510
|
+
// any other kind of expression
|
|
511
|
+
// new (f(location))()
|
|
512
|
+
walk::walk_expression(self, &it.callee);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
walk::walk_arguments(self, &it.arguments);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
#[coverage_checked(MemberExpression)]
|
|
519
|
+
fn visit_member_expression(&mut self, it: &MemberExpression<'data>) {
|
|
520
|
+
match &it {
|
|
521
|
+
MemberExpression::StaticMemberExpression(s) => {
|
|
522
|
+
// TODO
|
|
523
|
+
// you could break this with ["postMessage"] etc
|
|
524
|
+
// however this code only exists because of recaptcha whatever
|
|
525
|
+
// and it would slow down js execution a lot
|
|
526
|
+
if s.property.name == "postMessage" && !matches!(&s.object, Expression::Super(_)) {
|
|
527
|
+
self.jschanges.add(rewrite!(s.object.span(), WrapPostMessage));
|
|
528
|
+
|
|
529
|
+
walk::walk_expression(self, &s.object);
|
|
530
|
+
return; // unwise to walk the rest of the tree
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if UNSAFE_GLOBALS.contains(&s.property.name.as_str()) {
|
|
534
|
+
self.jschanges.add(rewrite!(
|
|
535
|
+
s.property.span(),
|
|
536
|
+
RewriteProperty {
|
|
537
|
+
ident: s.property.name
|
|
538
|
+
}
|
|
539
|
+
));
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
MemberExpression::ComputedMemberExpression(s) => {
|
|
543
|
+
self.handle_computed_member_expression(s);
|
|
544
|
+
}
|
|
545
|
+
_ => {}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
walk::walk_member_expression(self, it);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
#[coverage_checked(DebuggerStatement)]
|
|
552
|
+
fn visit_debugger_statement(&mut self, it: &DebuggerStatement) {
|
|
553
|
+
// delete debugger statements entirely. some sites will spam debugger as an anti-debugging measure, and we don't want that!
|
|
554
|
+
self.jschanges.add(rewrite!(it.span, Delete));
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// we can't overwrite window.eval in the normal way because that would make everything an
|
|
558
|
+
// indirect eval, which could break things. we handle that edge case here
|
|
559
|
+
#[coverage_checked(CallExpression)]
|
|
560
|
+
fn visit_call_expression(&mut self, it: &CallExpression<'data>) {
|
|
561
|
+
audit_skip!(it.callee, "top(0): none of the unsafe globals can be called as functions, other than eval which we handle above");
|
|
562
|
+
if let Expression::Identifier(s) = &it.callee {
|
|
563
|
+
// if it's optional that actually makes it an indirect eval which is handled separately
|
|
564
|
+
if s.name == "eval" && !it.optional {
|
|
565
|
+
self.jschanges.add(rewrite!(
|
|
566
|
+
it.span,
|
|
567
|
+
Eval {
|
|
568
|
+
inner: Span::new(s.span.end + 1, it.span.end - 1),
|
|
569
|
+
}
|
|
570
|
+
));
|
|
571
|
+
|
|
572
|
+
// then we walk the arguments, but not the callee, since we want it to resolve to
|
|
573
|
+
// the real eval
|
|
574
|
+
walk::walk_arguments(self, &it.arguments);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if self.flags.scramitize {
|
|
579
|
+
self.scramitize(it.span);
|
|
580
|
+
}
|
|
581
|
+
walk::walk_call_expression(self, it);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
#[coverage_checked(ImportDeclaration)]
|
|
585
|
+
fn visit_import_declaration(&mut self, it: &ImportDeclaration<'data>) {
|
|
586
|
+
let str = it.source.to_string();
|
|
587
|
+
if str.contains(":")
|
|
588
|
+
|| str.starts_with("/")
|
|
589
|
+
|| str.starts_with(".")
|
|
590
|
+
|| str.starts_with("..")
|
|
591
|
+
{
|
|
592
|
+
self.rewrite_url(&it.source, true);
|
|
593
|
+
}
|
|
594
|
+
walk::walk_import_declaration(self, it);
|
|
595
|
+
}
|
|
596
|
+
#[coverage_checked(ImportExpression)]
|
|
597
|
+
fn visit_import_expression(&mut self, it: &ImportExpression<'data>) {
|
|
598
|
+
self.jschanges.add(rewrite!(
|
|
599
|
+
Span::new(it.span.start, it.span.start + 7),
|
|
600
|
+
ImportFn
|
|
601
|
+
));
|
|
602
|
+
walk::walk_import_expression(self, it);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
#[coverage_checked(ExportAllDeclaration)]
|
|
606
|
+
fn visit_export_all_declaration(&mut self, it: &ExportAllDeclaration<'data>) {
|
|
607
|
+
self.rewrite_url(&it.source, true);
|
|
608
|
+
}
|
|
609
|
+
#[coverage_checked(ExportNamedDeclaration)]
|
|
610
|
+
fn visit_export_named_declaration(&mut self, it: &ExportNamedDeclaration<'data>) {
|
|
611
|
+
if let Some(source) = &it.source {
|
|
612
|
+
self.rewrite_url(source, true);
|
|
613
|
+
}
|
|
614
|
+
audit_skip!(it.declaration, "export {x} is safe because you can only export locals, which the only unsafe `top/parent` obviously can't be");
|
|
615
|
+
audit_skip!(it.specifiers, "export {x as y} is safe because you can only export locals");
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
#[coverage_checked(TryStatement)]
|
|
619
|
+
fn visit_try_statement(&mut self, it: &oxc::ast::ast::TryStatement<'data>) {
|
|
620
|
+
// for debugging we need to know what the error was
|
|
621
|
+
|
|
622
|
+
if self.flags.capture_errors
|
|
623
|
+
&& let Some(h) = &it.handler
|
|
624
|
+
&& let Some(name) = &h.param
|
|
625
|
+
&& let Some(ident) = name.pattern.get_identifier_name()
|
|
626
|
+
{
|
|
627
|
+
let start = h.body.span.start + 1;
|
|
628
|
+
self.jschanges
|
|
629
|
+
.add(rewrite!(Span::new(start, start), ScramErr { ident }));
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if !self.flags.destructure_rewrites {
|
|
633
|
+
walk::walk_try_statement(self, it);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if let Some(h) = &it.handler {
|
|
638
|
+
if let Some(p) = &h.param {
|
|
639
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
640
|
+
let mut location_assigned: bool = false;
|
|
641
|
+
|
|
642
|
+
// variables defined in catch shadow the global, don't rewrite location to the temploc here
|
|
643
|
+
self.recurse_binding_pattern(
|
|
644
|
+
&p.pattern,
|
|
645
|
+
&mut restids,
|
|
646
|
+
false,
|
|
647
|
+
&mut location_assigned,
|
|
648
|
+
);
|
|
649
|
+
if h.body.body.len() > 0 {
|
|
650
|
+
self.jschanges.add(rewrite!(
|
|
651
|
+
h.body.body[0].span(),
|
|
652
|
+
CleanFunction {
|
|
653
|
+
restids,
|
|
654
|
+
expression: false,
|
|
655
|
+
location_assigned,
|
|
656
|
+
wrap: false,
|
|
657
|
+
declare_local_location: false,
|
|
658
|
+
}
|
|
659
|
+
));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
walk::walk_block_statement(self, &h.body);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if let Some(f) = &it.finalizer {
|
|
666
|
+
walk::walk_block_statement(self, f);
|
|
667
|
+
}
|
|
668
|
+
walk::walk_block_statement(self, &it.block);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
#[coverage_checked(ObjectExpression)]
|
|
672
|
+
fn visit_object_expression(&mut self, it: &ObjectExpression<'data>) {
|
|
673
|
+
for prop in &it.properties {
|
|
674
|
+
if let ObjectPropertyKind::ObjectProperty(p) = prop
|
|
675
|
+
&& let Expression::Identifier(s) = &p.value
|
|
676
|
+
&& UNSAFE_GLOBALS.contains(&s.name.to_string().as_str())
|
|
677
|
+
&& p.shorthand
|
|
678
|
+
{
|
|
679
|
+
self.jschanges
|
|
680
|
+
.add(rewrite!(s.span, ShorthandObj { name: s.name }));
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
walk::walk_object_expression(self, it);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
#[coverage_checked(Function)]
|
|
689
|
+
fn visit_function(
|
|
690
|
+
&mut self,
|
|
691
|
+
it: &oxc::ast::ast::Function<'data>,
|
|
692
|
+
flags: oxc::syntax::scope::ScopeFlags,
|
|
693
|
+
) {
|
|
694
|
+
if !self.flags.destructure_rewrites {
|
|
695
|
+
walk::walk_function(self, it, flags);
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
700
|
+
let mut location_assigned: bool = false;
|
|
701
|
+
for param in &it.params.items {
|
|
702
|
+
// function params shadow global, don't rewrite temploc
|
|
703
|
+
self.recurse_binding_pattern(
|
|
704
|
+
¶m.pattern,
|
|
705
|
+
&mut restids,
|
|
706
|
+
false,
|
|
707
|
+
&mut location_assigned,
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if let Some(b) = &it.body {
|
|
712
|
+
// calling the actual visit method is neccesary here, walking isn't enough for some reason
|
|
713
|
+
self.visit_function_body(b);
|
|
714
|
+
if restids.len() > 0 || location_assigned {
|
|
715
|
+
if let Some(stmt) = b.statements.get(0) {
|
|
716
|
+
let span = stmt.span();
|
|
717
|
+
self.jschanges.add(rewrite!(
|
|
718
|
+
Span::new(span.start, span.start),
|
|
719
|
+
CleanFunction {
|
|
720
|
+
restids,
|
|
721
|
+
expression: false,
|
|
722
|
+
location_assigned,
|
|
723
|
+
wrap: false,
|
|
724
|
+
declare_local_location: false,
|
|
725
|
+
}
|
|
726
|
+
));
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
#[coverage_checked(ArrowFunctionExpression)]
|
|
733
|
+
fn visit_arrow_function_expression(
|
|
734
|
+
&mut self,
|
|
735
|
+
it: &oxc::ast::ast::ArrowFunctionExpression<'data>,
|
|
736
|
+
) {
|
|
737
|
+
if !self.flags.destructure_rewrites {
|
|
738
|
+
walk::walk_arrow_function_expression(self, it);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
743
|
+
let mut location_assigned: bool = false;
|
|
744
|
+
for param in &it.params.items {
|
|
745
|
+
self.recurse_binding_pattern(
|
|
746
|
+
¶m.pattern,
|
|
747
|
+
&mut restids,
|
|
748
|
+
false,
|
|
749
|
+
&mut location_assigned,
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
self.visit_function_body(&it.body);
|
|
754
|
+
if let Some(stmt) = &it.body.statements.get(0) {
|
|
755
|
+
self.jschanges.add(rewrite!(
|
|
756
|
+
stmt.span(),
|
|
757
|
+
CleanFunction {
|
|
758
|
+
restids,
|
|
759
|
+
expression: it.expression,
|
|
760
|
+
location_assigned,
|
|
761
|
+
wrap: false,
|
|
762
|
+
declare_local_location: false,
|
|
763
|
+
}
|
|
764
|
+
));
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
#[coverage_checked(ForStatement)]
|
|
769
|
+
fn visit_for_statement(&mut self, it: &ForStatement<'data>) {
|
|
770
|
+
if !self.flags.destructure_rewrites {
|
|
771
|
+
walk::walk_for_statement(self, it);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
776
|
+
let mut location_assigned: bool = false;
|
|
777
|
+
if let Some(i) = &it.init {
|
|
778
|
+
if let ForStatementInit::VariableDeclaration(d) = &i {
|
|
779
|
+
self.handle_var_declarator(d, &mut restids, &mut location_assigned);
|
|
780
|
+
|
|
781
|
+
if location_assigned || restids.len() > 0 {
|
|
782
|
+
let declare_local_location = location_assigned;
|
|
783
|
+
self.jschanges.add(rewrite!(
|
|
784
|
+
d.span,
|
|
785
|
+
CleanVariableDeclaration {
|
|
786
|
+
restids,
|
|
787
|
+
location_assigned,
|
|
788
|
+
declare_local_location,
|
|
789
|
+
}
|
|
790
|
+
));
|
|
791
|
+
}
|
|
792
|
+
} else {
|
|
793
|
+
// we've narrowed the for specific stuff so it's just a regular expression now
|
|
794
|
+
walk::walk_for_statement_init(self, i);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if let Some(t) = &it.test {
|
|
799
|
+
walk::walk_expression(self, t);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
if let Some(t) = &it.update {
|
|
803
|
+
walk::walk_expression(self, t);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
walk::walk_statement(self, &it.body);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
#[coverage_checked(ForOfStatement)]
|
|
810
|
+
fn visit_for_of_statement(&mut self, it: &oxc::ast::ast::ForOfStatement<'data>) {
|
|
811
|
+
self.handle_for_of_in(&it.left, &it.right, &it.body);
|
|
812
|
+
}
|
|
813
|
+
#[coverage_checked(ForInStatement)]
|
|
814
|
+
fn visit_for_in_statement(&mut self, it: &oxc::ast::ast::ForInStatement<'data>) {
|
|
815
|
+
self.handle_for_of_in(&it.left, &it.right, &it.body);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
#[coverage_checked(FunctionBody)]
|
|
819
|
+
fn visit_function_body(&mut self, it: &FunctionBody<'data>) {
|
|
820
|
+
// tag function for use in sourcemaps
|
|
821
|
+
|
|
822
|
+
if self.flags.do_sourcemaps {
|
|
823
|
+
self.jschanges
|
|
824
|
+
.add(rewrite!(Span::new(it.span.start, it.span.start), SourceTag));
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
walk::walk_function_body(self, it);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
#[coverage_checked(UnaryExpression)]
|
|
831
|
+
fn visit_unary_expression(&mut self, it: &UnaryExpression<'data>) {
|
|
832
|
+
if matches!(it.operator, UnaryOperator::Typeof) {
|
|
833
|
+
match it.argument {
|
|
834
|
+
Expression::Identifier(_) => {
|
|
835
|
+
// `typeof location` -> `typeof $wrap(location)` seems like a sane rewrite but it's incorrect
|
|
836
|
+
// typeof has the special property of not caring whether the identifier is undefined
|
|
837
|
+
// and this won't escape anyway, so don't rewrite
|
|
838
|
+
audit_skip!(it.argument, "safe, identifier tree cannot expand into an escape");
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
_ => {
|
|
842
|
+
// `typeof (location)` / `typeof location.href` / `typeof function()`
|
|
843
|
+
// this is safe to rewrite
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
walk::walk_unary_expression(self, it);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
#[coverage_checked(UpdateExpression)]
|
|
851
|
+
fn visit_update_expression(&mut self, it: &UpdateExpression<'data>) {
|
|
852
|
+
// this is like a ++ or -- operator
|
|
853
|
+
match it.argument {
|
|
854
|
+
SimpleAssignmentTarget::AssignmentTargetIdentifier(_) => {
|
|
855
|
+
// if it's an identifier we cannot rewrite it
|
|
856
|
+
// $wrap(location)++ is invalid syntax
|
|
857
|
+
|
|
858
|
+
// so it's safer to assume that this "location" is a local
|
|
859
|
+
// even if it's real location you can't escape with it anyway
|
|
860
|
+
// unless you consider navigating to "https://proxy.com/NaN" escaping
|
|
861
|
+
audit_skip!(it.argument, "ident++ would need $wrap(ident)++ which is invalid syntax; arithmetic on location coerces to NaN and assigns the string back, which navigates only to a non-attacker-controlled URL");
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
_ => {}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// if it's not a simple identifier it's probably a member expression which is safe
|
|
868
|
+
walk::walk_update_expression(self, it);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
#[coverage_checked(MetaProperty)]
|
|
872
|
+
fn visit_meta_property(&mut self, it: &MetaProperty<'data>) {
|
|
873
|
+
if it.meta.name == "import" {
|
|
874
|
+
self.jschanges.add(rewrite!(it.span, MetaFn));
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
#[coverage_checked(VariableDeclaration)]
|
|
879
|
+
fn visit_variable_declaration(&mut self, it: &oxc::ast::ast::VariableDeclaration<'data>) {
|
|
880
|
+
if !self.flags.destructure_rewrites {
|
|
881
|
+
walk::walk_variable_declaration(self, it);
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
886
|
+
let mut location_assigned: bool = false;
|
|
887
|
+
self.handle_var_declarator(&it, &mut restids, &mut location_assigned);
|
|
888
|
+
|
|
889
|
+
if location_assigned || restids.len() > 0 {
|
|
890
|
+
let declare_local_location = location_assigned;
|
|
891
|
+
self.jschanges.add(rewrite!(
|
|
892
|
+
Span::new(it.span.end, it.span.end),
|
|
893
|
+
CleanFunction {
|
|
894
|
+
restids,
|
|
895
|
+
expression: false,
|
|
896
|
+
location_assigned,
|
|
897
|
+
wrap: false,
|
|
898
|
+
declare_local_location,
|
|
899
|
+
}
|
|
900
|
+
));
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
#[coverage_checked(AssignmentExpression)]
|
|
905
|
+
fn visit_assignment_expression(&mut self, it: &AssignmentExpression<'data>) {
|
|
906
|
+
match &it.left {
|
|
907
|
+
AssignmentTarget::AssignmentTargetIdentifier(s) => {
|
|
908
|
+
// location = ...
|
|
909
|
+
// location is the only unsafe global that has a setter
|
|
910
|
+
if &s.name == "location" {
|
|
911
|
+
self.jschanges.add(rewrite!(
|
|
912
|
+
it.span,
|
|
913
|
+
Assignment {
|
|
914
|
+
name: s.name,
|
|
915
|
+
rhs: it.right.span(),
|
|
916
|
+
op: it.operator,
|
|
917
|
+
}
|
|
918
|
+
));
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
AssignmentTarget::StaticMemberExpression(_) | AssignmentTarget::ComputedMemberExpression(_) => {
|
|
922
|
+
self.handle_assignment_target_member(&it.left);
|
|
923
|
+
}
|
|
924
|
+
AssignmentTarget::ObjectAssignmentTarget(o) => {
|
|
925
|
+
if self.flags.destructure_rewrites {
|
|
926
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
927
|
+
let mut location_assigned: bool = false;
|
|
928
|
+
self.recurse_object_assignment_target(o, &mut restids, &mut location_assigned);
|
|
929
|
+
|
|
930
|
+
if restids.len() > 0 || location_assigned {
|
|
931
|
+
self.jschanges.add(rewrite!(
|
|
932
|
+
it.span,
|
|
933
|
+
WrapObjectAssignment {
|
|
934
|
+
restids,
|
|
935
|
+
location_assigned
|
|
936
|
+
}
|
|
937
|
+
));
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
AssignmentTarget::ArrayAssignmentTarget(a) => {
|
|
942
|
+
if self.flags.destructure_rewrites {
|
|
943
|
+
let mut restids: Vec<Atom<'data>> = Vec::new();
|
|
944
|
+
let mut location_assigned: bool = false;
|
|
945
|
+
self.recurse_array_assignment_target(a, &mut restids, &mut location_assigned);
|
|
946
|
+
if restids.len() > 0 || location_assigned {
|
|
947
|
+
self.jschanges.add(rewrite!(
|
|
948
|
+
it.span,
|
|
949
|
+
WrapObjectAssignment {
|
|
950
|
+
restids,
|
|
951
|
+
location_assigned
|
|
952
|
+
}
|
|
953
|
+
));
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
AssignmentTarget::PrivateFieldExpression(_) => {
|
|
958
|
+
// `location.#p = x` — the private-field brand check throws
|
|
959
|
+
// TypeError before the identifier value is exposed to the
|
|
960
|
+
// program, so the bare `location` here cannot escape.
|
|
961
|
+
audit_skip!("PrivateField LHS: brand check throws TypeError before exposure");
|
|
962
|
+
}
|
|
963
|
+
_ => {}
|
|
964
|
+
}
|
|
965
|
+
walk::walk_expression(self, &it.right);
|
|
966
|
+
}
|
|
967
|
+
}
|