I'm experimenting with webAssembly and trying to figure out a way of validating the integrity of a JS method used by the webAssembly module.
For the purpose of the discussion, let's assume that the binary module is not hackable (I know it is not the case), but the JS side is.
Given the following C code:
#include <emscripten.h>
//js method to validate
void validateMe();
int validateMethods(){
// check validateMe integrity.
// return 1 if validation succeeded.
}
EMSCRIPTEN_KEEPALIVE
void doStuff(){
if (validateMethods()){
// do stuff
}
}
I would like to call doStuff()
from the JS side, and doStuff()
will operate only if the integrity check succeeded.
I thought of doing some sort of integrity check, similar to Subresource, checking the toString representation of the method. However, If I want to get the current (in-memory) JS method toString, I'll have to call JS which can be compromised.
Q: Can I somehow get the toString in a different way? Any other approach would also be appreciated.
Update: after digging a bit deeper, reading this article, it seems that there is no way to access the JS memory other than the shared array. So any validation technic would be appreciated.
Update 2 (Goal): My ultimate goal is to make sure the WASM part will only work with a specific JS, or at least make it harder to interact with manipulated JS.
Fiddle Example: The following fiddle, is a naive function validation, comparing the toString of the function char by char. If you alter the validateMe function, the validation fails. I'm trying to "bulletproof" it.