JavaScript - is it possible to force code execution after an error?

I am trying to make PoC mirrored cross-site scripting on a website that I am testing right now. I found a place inside the Javascript code where commands can be entered, however the problem is that the error "not defined" is generated in the previous block of code, and therefore (at least I think so) my entered code does not execute, is there a chance execute code anyway?

Here is the code:

UndefinedObject.Init({ Var1:"a", Var2:"b", Var3:"can_be_injected_with_JS_code")} 

I cannot enter any HTML tags because they are filtered by the application.

Thank you very much!

+4
source share
4 answers

Wrap them in a try catch block.

+1
source

In the execution sequence, if the code is not executed, the rest will not be executed. Javascript errors ("Exceptions") can be detected using try ... catch (if you can also enter this try).

If there is another thread (through another event), the code will continue.

+1
source

You can either try using try-catch, or if that doesn't work, try using window.onerror

+1
source

Generally, the correct way is to use try-catch-finally or try-finally:

If you are doing something in the error log or doing something else. Catch can also be used to execute your code, but not for good practice. You cannot do anything about the error if you want, therefore it is finally used.

Finally, it is used when it is important to execute a piece of code, regardless of whether an error is selected or not. For example, in C ++ or another language, when you work with files inside, the file is closed (you cannot open it). Look here for some examples.

+1
source

All Articles