We will be at OWASP APPSEC EUROPE 2017 - Belfast! Let’s talk!MORE INFO

Help Center

Get to know more about our API, Code Annotations and Code Transformations

Enable

The enable directive allows you to enable a transformation in a specific block or statement.

Take for instance the following example:

1
2
// @jscrambler enable regexObfuscation
/\sMSIE\s[6-9]\./test(navigator.userAgent)

This enables regexObfuscation in any regular expression found in the statement or block that comes immediately after the code annotation. The resulting code would look something like this:

1
/[\r​\u2028\u1680​\t\v\u2000-\u200a​\u00a0​\u3000\f\n\u205f\u180e​\u202f\u2029 ]\x4d\x53\x49\u0045[ \u205f​\u202f\u2000-\u200a\f​\u3000\u180e​\u00a0\t\v​\u2028\u2029\r\n\u1680​][96-78]\./.test(navigator.userAgent);

If you want to enable the transformation for the whole JavaScript source file you can use the global modifier. This is useful when you want to force a transformation to a specific JavaScript file but not to the whole JavaScript application, and also when preceding each statement or block in the JavaScript file would be too troublesome.

1
2
3
4
5
6
7
8
// @jscrambler global enable regexObfuscation
function isSE () {
return /google|yahoo|bing/.test(document.domain);
}
function isOldIE () {
return /\sMSIE\s[6-9]\./.test(navigator.userAgent);
}

The resulting code would look something like this:

1
2
3
4
5
6
7
// @jscrambler global enable regexObfuscation
function isSE() {
return /\u0067\157\x6f\u0067\154\145|\u0079\x61\150\x6f\157|\142\u0069\x6e\u0067/.test(document.domain);
}
function isOldIE() {
return /[\u2000-\u200a​\u202f​\u2028\u1680​​\u3000\v\u180e​\u00a0\u2029\t\f\r\n\u205f ]\u004d\123\111\105[\r\u1680​\u205f​\u202f\n\u180e\u2000-\u200a\f​\u3000​\u2028​\u00a0\u2029\v \t][7-96]\./.test(navigator.userAgent);
}

However, imagine that you have a huge number of regular expressions in your JavaScript source code and there are a few that you don’t want to be targeted by regexObfuscation. To solve this, you can enable the transformation globally and use the disable directive for the regular expressions you don’t want to obfuscate. If you want to read more about the disable directive click here.