Trying to scan a script to determine if it is using any of these interfaces is the wrong approach. It is too easy to avoid obfuscation, as you seem to discover. This is fundamentally unsafe: there is no way to make it work.
Here is the best approach. Require script -writer to include a manifest that declares which special APIs it needs to receive. Then run the script in a secure Javascript sandbox that provides only the allowed APIs and APIs that it requested, but nothing more. If the script does not request GM_openSQL_Connection in its manifest, do not open this API for the script.
Since Javascript is a dynamic language that allows you to render monkeys harmless and have unlimited access to the global object, some creation of a reliable sandbox is required that restricts access to the API that the script can access. Therefore, I recommend that you use an existing sandbox solution. One approach is to run the user script in the sandbox and provide an isolated code library full of stubs for sensitive APIs, where stubs simply use postMessage to send an RPC request to your extension code. This avoids links that cross the sandbox border, which is good (depending on the technology of the sandbox) these types of links usually have significant potential for security vulnerabilities.
You can then manage user alerts based on the contents of the manifest. Important: think about it from a user's perspective. Will regular users know the meaning of the warnings? Will they be able to make smart decisions? Will users be in a better position to make the right decisions than you? Will users be overwhelmed by constant alerts and just start to ignore them and click ok (cry-wolf effect)?
For information on technology for the Javascript sandbox, please read the following IT security question: How to scan Javascript for malicious code? . In the future, you may receive answers on the IT security site on this subject.
source share