Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS context cannot be escaped #3

Closed
pstjvn opened this issue Jul 28, 2021 · 1 comment
Closed

JS context cannot be escaped #3

pstjvn opened this issue Jul 28, 2021 · 1 comment

Comments

@pstjvn
Copy link

pstjvn commented Jul 28, 2021

Unlike tamperMonkey this tool does not seem to provide means to use the global JS context on the top window (in which it is injected) and thus I see no way to access the globally defined APIs added by the site's creators and those are added explicitly for allowing user scripting via such tools.

Example:
Server sent JS file:

window.someFunction = function() { ... }

Tamperish script

document.onreadystatechange = function(e) { 
  if (document.readyState === 'complete') {
    window.someFunction(); // DOES NOT WORK as the symbol is missing.
  }
}
@pstjvn
Copy link
Author

pstjvn commented Jul 28, 2021

After some digging and remembering the 'good old days' a working solution (although not great IMHO) is to prepare the line(s) of script you want to be able to call in the original host context as text and put it in a script tag in the Body of the document. It would look like this:

(function() {
    function executeInTopContext(str) {
        let s = document.createElement('script');
        s.textContent = str;
        document.body.appendChild(s);
        setTimeout(function() {
            document.body.removeChild(s);
        }, 100);
    }

    executeInTopContext(
        // This will work because the script is executed in the original context of the web site.
        `window.my_custom_website_provided_function(${some_variable_from_tamperish_context});`);

})();

Hope this will help someone.

@pstjvn pstjvn closed this as completed Jul 28, 2021
@username0x0a username0x0a pinned this issue Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant