Need: Code Protection

Jscrambler 101 — First Use

Last updated on September 3rd, 2024

Welcome to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. These tutorials cover Jscrambler version 8.1.

Introduction

In this tutorial — First Use — you will be introduced to our interface and we will guide you through the process of making your first protection request. You will learn how to navigate the Web App, make different protections, and protect your own apps. In the final section, we’ll also explain the first steps to using our command-line interface (CLI).

How to Access Your Dashboard

To start using Jscrambler, you have to sign in with the credentials you used to create your account. If you don’t have a Jscrambler account, now is the time to create one by clicking Try Jscrambler for Free or going to the login page.

The first time you open Jscrambler’s web app, you will see a callout message to click the Playground app. After clicking it, you will see a demo screen as shown below:



demo screen of Jscrambler's web application


In this demo, you have a sample code shown on the left side of the text editor. Follow the message bubble and click the Protect App button. Jscrambler will apply for code lock protection with real-time notifications, preventing the app from running on any browser except the allow-listed one.

Now, you will be prompted to run your newly protected app. When you run it, our HTML5 racing game will attempt to run in your current browser, which will trigger the code lock.

run your newly protected app to trigger the code lock and to see our HTML5 racing game


Because the code lock has the real-time notifications feature enabled, you can now click “See Notifications”. This will lead you to your Live Feed, where you’ll see an alert that someone tried to run the code outside of the lock.

live feed to see alerts when someone try to run the code outside the lock


Now, you can proceed to your own dashboard, simply by following the message bubble and clicking Dashboard on the top left menu.

see your dashboard of Jscrambler web app


Navigating the Playground App


To use your Dashboard, you must verify your email address.

In the Dashboard, click the Playground app. This is a sample HTML5 racing game that will enable you to test our transformations. After opening the Playground, in the File Tree on the left, you will see a set of pre-configured sample files.

If you click the JavaScript file common.js, you will see its content on the left side of the Text Editor, and some information about the file on the bottom-left of the page (as shown in the screenshot).

Navigating the Playground App of Jscrambler web application

Now, let’s move on to the right side of the text editor. Here is where you will find the protected code after you apply for protection. You can also find two available tabs:

  • Templates — where you can select one of our default templates (or use a template you created) in order to apply a saved set of transformations to the sample code.

  • Fine-Tuning — where you can select which individual transformations you want to apply to the source code.

fine tuning is where you can select which individual transformations you want to apply to the source codeWe’ll now go over each of these tabs separately.

Fine-Tuning


On this tab, you can specify the code transformations you want to apply to the source code one by one.

On the top, you’ll notice there’s a Targets and an Advanced tab. You can select the targets and choose the transformations you want to apply in a simple way. If you want to take it one step further you can select the Advanced tab where you’ll get an additional set of options for your transformations.

If you hover over each transformation in the Advanced tab, a brief explanation will appear on each one. Take this as an example:
If you hover over each transformation in the Advanced tab, a brief explanation will appear on each one

Templates


Templates consist of a saved set of code protections. As so, they enable you to apply multiple pre-defined transformations without needing to choose them one by one every time.

On this tab, you will find Default Templates and Custom Templates. Default Templates are provided directly by us and contain sets of protections with self-explanatory purposes. As an example, the Advanced Obfuscation template will apply a set of protections that give your code the highest level of obfuscation.

Custom Templates consist of templates you created. Creating a template is simple: head over to the Fine-Tuning tab and select some protections. From there, just click the Create Template button below the transformations. Give your template a name and a description, click Save Template and you’re done!

If you go into the Templates tab you should now see your new Template.

Templates consist of a saved set of code protections and you choose from Default Templates and Custom Templates

Protecting, Testing, and Downloading the Code


It’s time to start protecting our HTML5 racing game. As you may remember, we can do this two different ways: either by picking protections one by one on the Fine-Tuning tab or by selecting a pre-defined template on the Templates tab.

Let’s go ahead and test the Advanced Obfuscation template. Select it on the Templates tab. If you’re curious to see which transformations this template includes, simply go to the Fine-Tuning tab and check for yourself.

We’re ready to apply these protections. To do that, press Protect App at the bottom. After the app is protected, you will see the result on the right side of the text editor. If nothing shows up, just click on the common.js file. The result will be similar to this:


the result of pressing Protect App at the bottom is protected code

All protections you apply in the Playground won’t affect your account balance in any way — you can try everything without any worries.

Now, you can test the newly protected file. To do that, simply click “Run Protected” at the bottom of the screen. You will notice that the app will run normally, even though it’s using obfuscated code.

Downloading your newly protected code is also straightforward: simply press Download App (bottom left) and that’s it.

The transformations we applied during this simple process already go a long way toward protecting your code. They are suitable for obfuscating your functions and objects and concealing their logic.

How to Protect Your Own App


So far, we have covered the basics of Jscrambler by using the Playground app. Now, we will guide you through the process of protecting your own app. To return to the dashboard, click the Dashboard link on the menu.

Once there, you should click the Add App button, insert a name in the input like Hello World, select the Protection Type as “Code Integrity”, and click Create to create your own Jscrambler project.
create your own Jscrambler projecrt by clicking the Add app button and select the protection type as code integrityThis will redirect you to the Live Feed for your newly created app. To enter the Code Integrity protection builder, click the Protect App option on the left sidebar.


click the protect app option on the left sidebard to enter the code integrity protection builder


How to Add Your Own File to Be Protected


On the left side of the screen, you have your file tree, where you can check which files have been uploaded to the app. You can add your JavaScript and HTML files or add a single Zip archive containing your project into the app.

If you click the “Add” button on the left, you can see that a file can be created directly from the interface, uploaded from your device, or obtained through a URL. Choose the most suitable option to add your app.

add your own file to be protect by clicking the add buton on the left side of the screenAfter you have some files in your file tree, you can apply transformations to your own code.

For tutorial purposes, let’s choose Identifiers Renaming and Whitespace Removal as our transformations (find them after toggling Advanced Options, in the Fine-Tuning tab).

You may notice that some of the transformations are greyed out. This happens because you’re currently using a free trial account. If you want to unlock all Jscrambler features, please upgrade your plan.

With your trial account, you can still try the greyed-out transformations, but only by selecting a predefined template.

You can now protect your app with these transformations and check out what your protected code looks like. After that, it’s ready to be downloaded and used. Remember you can always create new templates to apply these transformations later.

Jscrambler CLI First Steps


With the Jscrambler CLI, you can easily integrate Jscrambler into your build process.

Jscrambler CLI first steps include the download of a JSON file

To get your Jscrambler configuration settings quickly, select the transformations you want (or a template) directly from the dashboard, and then download a JSON file by clicking the cogwheel above the Fine Tuning tab, and then clicking “Download Settings in JSON”.

You will be able to decide whether to download the entire file or to download the file without your Jscrambler secrets. For the sake of this tutorial, download the entire file by selecting “All Parameters”.

You should have downloaded a file similar to the one below:

{
  "keys": {
    "accessKey": "myAccessKey",
    "secretKey": "mySecretKey"
  },
  "applicationId": "myApplicationID",
  "params": [
        {
      "name": "identifiersRenaming"
    },
    {
      "name": "whitespaceRemoval"
    }
  ],
  "areSubscribersOrdered": false,
  "applicationTypes": {
    "webBrowserApp": false,
    "desktopApp": false,
    "serverApp": false,
    "hybridMobileApp": false,
    "javascriptNativeApp": false,
    "html5GameApp": false
  },
  "languageSpecifications": {
    "es5": true,
    "es6": false,
    "es7": false
  },
  "useRecommendedOrder": true,
  "jscramblerVersion": "8.1",
  "tolerateMinification": true
}


The AccessKey and SecretKey vary from user to user, while applicationId changes according to the application you are protecting. You can check your application inside the app, above the text editor:
verify your accesskey and secretkey inside the appAs for your AccessKey and SecretKey, you can check them on the My Profile page, under the “API Credentials” section:
check your API credentials on the my profile pageFor further directions on using the Jscrambler CLI, check our following 101 article.

In case you’re using a specific JavaScript framework or library, see our integration tutorials below:


Conclusion


This concludes our first tutorial on how to use Jscrambler.

You should now be able to navigate easily through the available apps, create new projects, apply transformations to your code, save them as templates, and download them as a JSON file to be able to use the API.

Feel free to proceed to one of our next 101 Tutorials, according to your current needs:



Enjoy your testing and start protecting your Applications ASAP! If you have any additional questions, feel free to contact us.

Jscrambler 101 – One-Click Code Protection

Updated on October 1st, 2024

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. This tutorial covers the One-Click Code Protection feature, included in the Jscrambler version 8.4.


Introduction


In this article, we’ll explore One-Click Code Protection, a new Jscrambler feature released in version 8.4. This feature allows all Code Integrity users to secure their app in minutes by choosing an Automatic Configuration mode.


About the One-Click Code Protection feature


How was the feature inspired?


Initially, Code Integrity was designed to give users the freedom to select and configure the techniques and transformations for the protection of their code. However, some users found that they had too many options to choose from. For smaller teams, it was also a challenge to figure out the best transformations for their framework to avoid incompatibility issues. That’s why our team started testing a quick protection feature that would allow users to protect their apps quickly and effortlessly. 


The goal of the new One-Click Protection feature is to universally allow users to secure their applications in a matter of just a few minutes, removing the need to tweak and customize. This feature is now available to all Code Integrity users.


How does the One-Click Code Protection feature work?

The ability for Code Integrity users to apply code protection without mandatory manual configuration will be achieved by introducing a new option called “Automatic Configuration”. This option now appears at the App Creation stage of the process.

How-does-the-One-Click-Code-Protection-feature-work

All users now have 2 ways to protect code when they create a new app:


  • Automatic configuration – users can apply an automatic protection that does not require configuration.

  • Manual configuration – users can make a customized selection of transformations and templates (this is what is currently available).

  • Experience for existing and new users

    The experience for existing and new users will be slightly different when accessing an app, depending on their plan:

    For existing users:

    • When creating a new app: users will be asked to select the desired configuration (Automatic / Manual).

    • When accessing an app that existed before this feature went live: will not be asked to select the desired configuration, landing straight in the App Builder, and the visualization will depend on their plan.

    New users:

    • When creating a new app: users will be asked to select the desired configuration (Automatic / Manual).

    • When accessing an app created after this feature is available: will not be asked to select the desired configuration, landing straight in the App Builder with the visualization according to what they selected the last time for that app.


One-Click Code Protection Benefits 


  • Simple to Use: The One-Click Code Protection feature is designed with user simplicity in mind, ensuring that anyone on the team can use it effortlessly. It enables users to safeguard their code with just a single click.

  • No Fine-Tuning Needed: One-Click Code Protection removed the need to select a template and/or manually fine-tune protection settings. Users do not need to worry about choosing the right protection strategy or adjusting parameters—everything is handled automatically. 

  • High Level of Code Protection Resilience: The feature employs advanced algorithms and security mechanisms to offer a high level of resilience against reverse engineering and malicious JavaScript attacks. This guarantees that sensitive logic, intellectual property, and proprietary algorithms within the code remain well-protected, providing peace of mind for developers and stakeholders alike.

  • Time Efficiency: The entire process takes less than 3 minutes. There’s no need for manual configuration or tweaking, which allows developers to integrate security measures into their workflow without interrupting the pace of development. This quick protection process is especially valuable in fast-moving projects, where deadlines are tight and security is paramount.

  • Framework Compatibility: All the most popular hybrid mobile frameworks can be protected without manual configuration (React Native, Vue, React, Cordova, Ionic, NativeScript, etc.)


    Here’s the full list of JavaScript frameworks:

  • Angular

  • EmberJS

  • Meteor

  • Next.js

  • Nuxt.js

  • Vue

  • React

  • React Native

  • Cordova

  • Ionic

  • NativeScript


Conclusion


This feature is quite empowering for Code Integrity users, as it provides the possibility of applying code protection without manual configuration. It’s a plug-and-play solution that will help customers apply a code protection recipe that works on the first try, without delving and wasting time into technical details or having to worry about extensive technical configuration.


Jscrambler 101 — Self Defending

Last updated on August 23rd, 2023

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. These tutorials cover Jscrambler version 8.2.

Introduction: Self Defending

Last time, on Jscrambler 101 — Code Annotations, we talked about using Code Annotations and how they can help protect an App. This time, we will talk about Self Defending.

Attempts to tamper with an unprotected game

This is our unprotected space shooter. You’ll notice that we have 3 rockets at the start of the game. There’s also a “Buy Rockets” button at the top of the screen, which allows us to buy more credits and continue the game.
(0:16-0:23)

We will try to add rockets without clicking the button and, therefore, without buying them. In this case, for tutorial purposes, we don’t have any trigger to process the payment when we click the button, but if there was any, the game creator would lose money with the tampering we’re about to do.

You can see below that when we click the button, the number of rockets increases.
One of the things we can do now is inspect the button element and access the onClick function in the “Event Listeners” tab. Now, we can add a breakpoint to the function and analyze the existing cr Object for any ‘Rocket’ reference.

(0:23-0:50)

We have already developed a script to analyze the cr Object and return any property with a ‘Rocket’ reference. As such, all we have to do is paste the script on our browser’s console and execute it. By doing that, we can see the returned properties that reference ‘Rocket’ on the bottom of the console:

(0:50-1:16)

We previously recorded what property we wanted after running the script and analyzing the properties. Now, we can use this property to add rockets. In this case, we’ll be adding 10 more rockets to our game. After that, you can see a total of 14 rockets at the top of the game:

(1:25-1:51)

Conclusion

This tutorial shows how our Self-defending transformation works with anti-debugging and anti-tampering.

Feel free to proceed to one of our other 101 Tutorials:

Enjoy your testing.

Start protecting your Applications ASAP! If you have any additional questions, contact our client-side security experts.

Jscrambler 101 — Source Maps

Last updated on August 23rd, 2023

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. These tutorials cover Jscrambler version 8.2.

Introduction: Source Maps

Last time, on Jscrambler 101 — How to use the CLI, we showed you a simple way to protect your code through our command-line interface (CLI).This time, we dive into one of Jscrambler’s most handy features: Source Maps.

What Are Jscrambler Source Maps?

If you have tried Jscrambler’s code protection features, you know that one of its protection layers makes your code extremely hard to read and reverse-engineer, mainly with advanced JavaScript obfuscation. So, a piece of JavaScript like this:

function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('txt').innerHTML =
    h + ":" + m + ":" + s;
    var t = setTimeout(startTime, 500);
}

It would look like this after being protected with Jscrambler:

B100.P=function (){return typeof B100.H.C==='function'?B100.H.C.apply(B100.H,arguments):B100.H.C;};B100.H8=function(){var u8=2;while(u8!==1){switch(u8){case 2:return{C8:function W8(n8,S8){var F8=2;while(F8!==10){switch(F8){case 11:return f8;break;case 14:f8[U8][(c8+S8*U8)%n8]=f8[c8];F8=13;break;case 5:F8=i8<n8?4:9;break;case 3:i8+=1;F8=5;break;case 8:F8=U8<n8?7:11;break;case 4:f8[(i8+S8)%n8]=[];F8=3;break;case 9:var U8=0;F8=8;break;case 13:c8-=1;F8=6;break;case 7:var c8=n8-1;F8=6;break;case 1:var i8=0;F8=5;break;case 6:F8=c8>=0?14:12;break;case 12:U8+=1;F8=8;break;case 2:var f8=[];F8=1;break;}}}(14,6)};break;}}}();B100.x8=function (){return typeof B100.H8.C8==='function'?B100.H8.C8.apply(B100.H8,arguments):B100.H8.C8;};B100.G8=function (){return typeof B100.H8.b1==='function'?B100.H8.b1.apply(B100.H8,arguments):B100.H8.b1;};B100.l8=function (){return typeof B100.H8.b1==='function'?B100.H8.b1.apply(B100.H8,arguments):B100.H8.b1;};B100.B0=function (){return typeof B100.R0.C==='function'?B100.R0.C.apply(B100.R0,arguments):B100.R0.C;};B100.t1=function (){return typeof B100.a1.C==='function'?B100.a1.C.apply(B100.a1,arguments):B100.a1.C;};B100.s8=function (){return typeof B100.H8.C==='function'?B100.H8.C.apply(B100.H8,arguments):B100.H8.C;};B100.P8=function (){return typeof B100.H8.I1==='function'?B100.H8.I1.apply(B100.H8,arguments):B100.H8.I1;};B100.q=function (){return typeof B100.H.C==='function'?B100.H.C.apply(B100.H,arguments):B100.H.C;};B100.B1=function (){return typeof B100.a1.b1==='function'?B100.a1.b1.apply(B100.a1,arguments):B100.a1.b1;};B100.b8=function (){return typeof B100.H8.w0==='function'?B100.H8.w0.apply(B100.H8,arguments):B100.H8.w0;};B100.T8=function (){return typeof B100.H8.I1==='function'?B100.H8.I1.apply(B100.H8,arguments):B100.H8.I1;};B100.H=function(){var n=function(W,E){var a=E&0xffff;var J=E-a;return(J*W|0)+(a*W|0)|0;},z=function(O,N,b){var w=0xcc9e2d51,M=0x1b873593;var G=b;var l=N&~0x3;for(var R=0;R<l;R+=4){var i=O.charCodeAt(R)&0xff|(O.charCodeAt(R+1)&0xff)<<8|(O.charCodeAt(R+2)&0xff)<<16|(O.charCodeAt(R+3)&0xff)<<24;i=n(i,w);i=(i&0x1ffff)<<15|i>>>17;i=n(i,M);G^=i;G=(G&0x7ffff)<<13|G>>>19;G=G*5+0xe6546b64|0;}i=0;switch(N%4){case 3:i=(O.charCodeAt(l+2)&0xff)<<16;case 2:i|=(O.charCodeAt(l+1)&0xff)<<8;case 1:i|=O.charCodeAt(l)&0xff;i=n(i,w);i=(i&0x1ffff)<<15|i>>>17;i=n(i,M);G^=i;}G^=N;G^=G>>>16;G=n(G,0x85ebca6b);G^=G>>>13;G=n(G,0xc2b2ae35);G^=G>>>16;return G;};return{C:z};}();B100.s1=function (){return typeof B100.a1.w0==='function'?B100.a1.w0.apply(B100.a1,arguments):B100.a1.w0;};B100.W0=function (){return typeof B100.R0.C==='function'?B100.R0.C.apply(B100.R0,arguments):B100.R0.C;};B100.w1=function (){return typeof B100.a1.I1==='function'?B100.a1.I1.apply(B100.a1,arguments):B100.a1.I1;};B100.n1=function (){return typeof B100.a1.C==='function'?B100.a1.C.apply(B100.a1,arguments):B100.a1.C;};B100.C1=function (){return typeof B100.a1.b1==='function'?B100.a1.b1.apply(B100.a1,arguments):B100.a1.b1;};B100.c1=function (){return typeof B100.a1.I1==='function'?B100.a1.I1.apply(B100.a1,arguments):B100.a1.I1;};B100.R0=function(){var j0=2;while(j0!==1){switch(j0){case 2:return{w0:function(H0){var y0=2;while(y0!==14){switch(y0){case 2:var C0='',A0=decodeURI("A$+5%25%1B%7C%07%09%0E06%5C%02*%25%25%20v%3E=$%094M%3E%00%3C2%3EM$1%12.%1AL%14%1Bj%094M%3E%1654%3CF.6%0E06%5C%07,%3E%22'M9");y0=1;break;case 5:y0=K0<A0.length?4:7;break;case 1:var K0=0,i0=0;y0=5;break;case 8:K0++,i0++;y0=5;break;case 6:return function(q0){var V0=2;while(V0!==1){switch(V0){case 2:return C0[q0];break;}}};break;case 3:i0=0;y0=9;break;case 9:C0+=String.fromCharCode(A0.charCodeAt(K0)^H0.charCodeAt(i0));y0=8;break;case 4:y0=i0===H0.length?3:9;break;case 7:C0=C0.split('^');y0=6;break;}}}('(JEPWS')};break;}}}();B100.D8=function (){return typeof B100.H8.w0==='function'?B100.H8.w0.apply(B100.H8,arguments):B100.H8.w0;};B100.b0=function (){return typeof B100.R0.w0==='function'?B100.R0.w0.apply(B100.R0,arguments):B100.R0.w0;};B100.a1=function(A1){return{I1:function(){var P1,D1=arguments;switch(A1){case B100.x8()[7][6]:P1=D1[0]*D1[2]-D1[1];break;case B100.M0()[7][12]:P1=-(D1[2]*D1[3])-D1[4]+-D1[1]+D1[0];break;}return P1;},b1:function(d1){A1=d1;}};}();B100.R1=function (){return typeof B100.a1.w0==='function'?B100.a1.w0.apply(B100.a1,arguments):B100.a1.w0;};B100.M0=function (){return typeof B100.H8.C8==='function'?B100.H8.C8.apply(B100.H8,arguments):B100.H8.C8;};function B100(){}B100.v0=function (){return typeof B100.R0.w0==='function'?B100.R0.w0.apply(B100.R0,arguments):B100.R0.w0;};B100.K8=function (){return typeof B100.H8.C==='function'?B100.H8.C.apply(B100.H8,arguments):B100.H8.C;};function startTime(){var I0=B100;var B,K,g,T,d,Y,r,I;B=new Date();K=B[I0.b0(1)]();g=B[I0.b0(7)]();T=583587531;d=-1024664412;Y=2;for(var o=1;I0.q(o.toString(),o.toString().length,44684)!==T;o++){r=B[I0.v0(4)]();g=checkTime(g);Y+=2;}if(I0.q(Y.toString(),Y.toString().length,49201)!==d){r=B[I0.v0(4)]();g=checkTime(g);}r=B[I0.v0(6)]();g=checkTime(g);r=checkTime(r);I0.C1(I0.x8()[8][12]);var o0=I0.w1(4,67,18);I0.B1(I0.x8()[4][8]);var c0=I0.w1(93,10,7,10,8);document[I0.v0(3)](I0.b0(2))[I0.v0(0)]=K+I0.b0(o0)+g+I0.b0(c0)+r;I=setTimeout(startTime,500);}

Jscrambler’s code protection prevents someone from reverse-engineering or tampering with your code, but it might seem like a burden to development teams when they want to debug their applications.This is especially relevant in cases where a problem can only be reproduced in production by running the source code. Jscrambler Source Maps allows us to achieve that. And having the code protected by Jscrambler will not be an issue.Jscrambler Source Maps enable mapping the obfuscated code back to its source code.As such, development teams can get through the debugging process of obfuscated code as if they were running the source code.It’s worth mentioning that Jscrambler’s Source Maps feature is used only for development purposes and doesn’t compromise your application’s security.

Using Jscrambler Source Maps

Jscrambler supports Source Maps either via the Web Application or through its API. Using Source Maps from previous compilation steps is also supported.Note that, in all cases, Source Maps are disabled by default.

Jscrambler Source Maps Via the Web Application

After understanding how Source Maps can benefit your specific case, setting them up is very straightforward.First, you need to access your Dashboard, from where you can click the App for which you wish to enable Source Maps.Now, click the cogwheel on the top right corner, next to Application Settings, and enable “Source Maps”, as shown below.

jscrambler-source-maps-via-web-applicationAfter this, all new protections to your code will have the Jscrambler Source Maps feature enabled until you decide to change it.Using Jscrambler Source Maps via the Web App has one relevant element: the source code will be embedded in the source map file. This behavior is specific to the Web app, and if you don’t want to include the source code, refer to the section below about using the API.We are ready to download the source map file. Return to the dashboard and click the icon below the App name. Then, click Protection History, as shown below:Open-Protection-HistoryThis will open a screen with the latest protections for your applications, as we show below:latest-protections-dashboard-code-integrityNow, click the ID of the protection for which you want to download the source map file. This will open a new screen with details for that specific protection. On this new screen, click on “Download Source Maps”.Download-Source-Maps-resultNow, we have the source map file, which will be used in the final section of this tutorial, with the name Including Source Maps With Your JavaScript Files.

Jscrambler Source Maps Via the API

To enable Jscrambler Source Maps through the API, refer to your Jscrambler configuration file (typically, it’s jscrambler.json).If you haven’t downloaded it yet, just head over to Jscrambler’s dashboard, select the app you want, click the Import/Export Settings menu on the bottom-right, and select “Download All Settings:download-jscrambler-jsonOpen this file and activate Source Maps by adding:

"sourceMaps": {
    "sourceContent": true
  },

Your configuration file should then look similar to the one below:

{
  "keys": {
    "accessKey": "YOUR_ACCESS_KEY",
    "secretKey": "YOUR_SECRET_KEY"
  },
  "applicationId": "YOUR_APPLICATION_ID",
  "filesSrc": [
    "/path/to/src.html",
    "/path/to/src.js"
  ],
  "filesDest": "/path/to/destDir/",
  "params": [
    {
      "name": "stringSplitting"
    }
  ],
  "sourceMaps": true
}

Configuring Jscrambler Source Maps via the API enables customizing whether the source code should be embedded in the Source Map file. By default, this is set to true by the property we covered before, “sourceMaps”: true.However, if you want to prevent your original code from being included in the Source Map file, you must set the sourceContent option, as shown below:

"sourceMaps": {
  "sourceContent": false
}

Also, disabling Jscrambler’s Source Maps feature entirely via the API is as simple as omitting the sourceMaps property or setting “sourceMaps” to false.To download the Source Map file through the API, we must get our protectionId. So, if our config file is named jscrambler.json, we execute:

jscrambler -c jscrambler.json

This will generate an output similar to 59021864dd26ca0011dc94ed, which is our protectionID.Next, the Source Map file for protection 59021864dd26ca0011dc94ed can be downloaded by executing:

jscrambler -c jscrambler.json -m 59021864dd26ca0011dc94ed

This will download the Jscrambler Source Maps to a folder named jscramblerSourceMaps.

Loading Jscrambler Source Maps into the Browser’s Dev Tools

This last step is very simple. Taking as an example a single file.js, you have two options:

Using an HTTP Header when serving the JavaScript file

SourceMap: /path/to/file.js.map

Or appending a comment to the JavaScript file

/* Protected JavaScript */
//# sourceMappingURL=/path/to/file.js.map

There is another option to load source maps that doesn’t require changes to the code or HTTP headers. Read more about it in the developer resources: view and manually load source maps. Pay special attention to the “Load a source map manually “section.And that’s it! You unlocked the full benefits of using Jscrambler Source Maps for painless debugging.

Conclusion

Ensure you don’t include the Source Map files by accident in production. This would grant anyone direct access to your original code!

Enjoy your testing and start protecting your applications ASAP! If you have any additional questions contact our client-side security experts.

Jscrambler 101 – Anti-Tampering

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. This tutorial covers Jscrambler version 8.1.

 

Introduction

We will explore Anti-Tampering, a new Jscrambler feature released in version 8.1. Anti-Tampering protects your application against tampering attacks.

 

Anti-Tampering

Before version 8.1, Jscrambler already had some transformations that included anti-tampering techniques such as Self-Defending and Self-Healing. This new transformation was made to address some of the issues that those two techniques had and to explore some new anti-tampering techniques.

Unlike previous transformations, Anti-Tampering is fully compatible with the browser’s Content Security Policy (CSP) and also works in React Native with Hermes (only the RCK technique).

This transformation also isolates the anti-tampering techniques into a single transformation. Therefore, it can be used without anti-debugging or self-healing techniques. Once tampering is detected, we can also customize the countermeasures that will be triggered.

The transformation has two different anti-tampering techniques, RCK and SKL (abstract internal names), to increase the strength of the protection. By default, both techniques are used, but they can be disabled individually. This is only possible using the CLI and a configuration file since it’s an advanced use case (check the API Parameters section of our Docs).

Tampering attack example

In this tampering attack example, we will use a car racing game as a target for the attack. Our goal is to win (have the fastest lap time) by making the car go faster (increase max speed and acceleration).

Click to see the original game with regular car speed (maximum 120 mph).

Now, we will tamper with the code to increase the car’s speed and acceleration. To do this, we will use Chrome’s dev tools to view the source code and replace the variables maxSpeed and accel with higher values.

Check out the final result of this video’s tampering with the original code.

By doing that, we can now go much faster (240 mph). Thus, we can improve our fastest lap and win the game.

Anti-Tampering protection example

To prevent the attack, we will protect our game with Anti-Tampering. To do this, we upload our code to the Jscrambler Web App, select the Anti-Tampering transformation (in this example, we added a custom callback as a countermeasure), and click “Protect App”.

anti-tampering-protection-example-101-tutorial
Now that we have a protected version of the game, we will try to replicate the tamper we did previously. See the protected game video.

As we can see, the tamper was not successful, and the countermeasure was executed. Anti-Tampering prevented the attacker from getting an unfair advantage in the game. There are a variety of possible countermeasures that can be used to accomplish different results once the tamper is detected.

Conclusion

This new transformation allows us to have anti-tampering techniques work in more environments than before (CSP and React Native with Hermes). It is now isolated from anti-debugging and self-healing techniques.

The addition of multiple techniques (RCK and SKL) makes the transformation safer and harder to crack by an attacker, giving us more confidence in its effectiveness.

Jscrambler 101 — SIEM Integration

Welcome back to Jscrambler 101, a collection of tutorials on how to use Jscrambler to protect your JavaScript. This tutorial is about SIEM integration and covers Jscrambler version 7.2.


Introduction


Last time, on Jscrambler 101: Memory Protection, we explored a new Jscrambler feature that ciphers sensitive data using cryptographic algorithms, only allowing the data to be deciphered when it needs to be accessed by the application.

This time, we’re going to explore SIEM Integration, a new Jscrambler feature that allows you to forward and aggregate the valuable security Information Jscrambler gives you into a SIEM (e.g., Elasticsearch, Splunk).

SIEM Integration


From Jscrambler version 6.0 onwards, we provide a JavaScript Threat Monitoring module that displays a real-time notification on the Jscrambler dashboard as soon as some violation occurs, such as the client’s JavaScript code being tampered with or used in a different environment or date from the one(s) that are set on the protection configuration.

Now, with the SIEM Integration, you can easily access all that valuable information from one place and automate the process of looking at audit logs and alerting.

Setting up your SIEM Integration


To set up the integration between Jscrambler and your SIEM, you need to configure a Jscrambler notification driver and map the fields of the notification body. Let’s explore these steps below.

To access the SIEM Integrations page, go to the Jscrambler dashboard, select the target application, and then click the “Integration” link under the Setup section.

siem-integration-jscrambler-dashboard-setup-section

Currently, we provide two types of drivers that your SIEM will most likely be compatible with: Elasticsearch and Webhook. Below, we will explore how to set things up in each of these.



Elasticsearch


To set up real-time notifications with an Elasticsearch instance, select the Elasticsearch Notification driver from the dropdown box and click the “Add” button.

set-up-real-time-notifications-with-Elasticsearch-instance


Then, you will need to configure the following parameters according to your Elasticsearch setup:

  • Title: Name of this integration

  • URI: Network endpoint of your Elasticsearch instance (must be publicly available)

  • Accept All Certificates: turn on to allow self-signed certificates

  • Username/Password: client authorization to the Elasticsearch instance

  • Request Timeout (milliseconds): maximum amount of time waiting for the request to be completed

  • Max. Number of Retries: number of times the service attempts to deliver the Real-Time Notification once the first attempt fails

  • Elasticsearch Index: name of the Elasticsearch index where your notifications will be grouped

  • Elasticsearch Type: name of the Elasticsearch type


When you are done, click on the Create button to validate and store the configured Elasticsearch integration.

Webhook


To set up real-time notifications with a Webhook, select the Webhook Notification driver from the dropdown box and click on the “Add” button.

set-up-real-time-notifications-with-webhook

Then, you need to configure the following parameters according to your SIEM (which should be capable of receiving HTTPS requests):

  • Title: Name of this integration

  • Endpoint to send a POST Request: Network endpoint of your HTTP (S) server instance (must be publicly available)

  • Basic Authentication Username/Password: client authorization to the HTTP (S) server

  • Support Self-Signed Certificates: turn on to allow self-signed certificates

  • Max. Number of Retries: number of times the service attempts to deliver the Real-Time Notification once the first attempt fails


When you are done, click on the Create button to validate and store the configured webhook integration.

And that’s all from the Jscrambler dashboard! Let’s now see how to map the notification body to the respective security alerts.


Mapping the notification body


Each real-time notification sent by Jscrambler will follow the pattern below:

{
  "title": "Real time notification",
  "description": "Code violation: j-003-00001",
  "body": {
	"0": "j-003-00001",
	"1": 1625757006491,
	"2": -60,
	"3": "Linux x86_64",
	"4": "Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0",
	"5": "https://example.com/index.html",
	"8": "Gecko"
  },
  “clientIp”:111.111.111.111}


To properly visualize this data in your SIEM, you should map these fields to their corresponding descriptions.

Here’s the meaning of each field in the request’s body:

JSON selector

Field description

body[“0”]

Alert codes (see table below for a mapping reference)

body[“1”]

Alert timestamp in milliseconds

body[“2”]

Timezone

body[“3”]

Platform

body[“4”]

User Agent

body[“5”]

Script URL

body[“8”]

Navigator product


As for the alert codes of body[“0”], find the corresponding alert description below:

Alert code

Alert description

j-001-xxxxx

Browser Lock

j-002-xxxxx

Date Lock

j-003-xxxxx

Domain Lock

j-004-xxxxx

OS Lock

j-005-xxxxx

Self Defending

j-0012-xxxxx

Root/Jailbreak Detection Lock


And that’s it! You’re done with the required configuration.


End Result


Now that you have set up your SIEM integration, you should see real-time notifications in your SIEM. In the image below, you can see a preview of the resulting dashboard using Kibana.

set-up-real-time-notifications-with-webhook

Now that you have centralized your security information in one system, it is easier to start automating your audit logs and alert checkups.


Conclusion

We have reached the end of our Jscrambler SIEM Integration tutorial.

As you saw, getting started with this feature is a simple, one-time process that will enrich your SIEM with valuable information. Don’t miss this chance to start centralizing your security information and making it easier to maintain in-depth security.

Feel free to proceed to one of our 101 Tutorials:


Enjoy your testing. Start protecting your Applications ASAP! If you have any additional questions, feel free to contact us.

Jscrambler 101 — Memory Protection

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. This tutorial covers Jscrambler version 7.1.

Introduction

Last time, on Jscrambler 101 — App Classification, we explored a new Jscrambler feature that classifies your apps and adjusts Jscrambler’s protections to maximize their security and performance.

This time, we’re going to explore Memory Protection, a new Jscrambler feature that increases the security of sensitive data in your apps.

Memory Protection

In Web and Mobile applications, sensitive data often passes through the client-side. More specifically, values stored in memory can be accessed and tampered with at runtime.

Attackers’ motivations to exploit the app’s memory may vary from lower-risk to critical-risk. Generally, they will do it for one of these reasons:

  • to reverse-engineer the code and understand its mechanics;
  • to modify the app’s behavior and, for example, access new features;
  • to access and retrieve sensitive data, for example, in Contact Tracing apps.

In comes Memory Protection, is a new Jscrambler feature that ciphers sensitive data using cryptographic algorithms, only allowing the data to be deciphered when it needs to be accessed by the application.

Memory Protection can be applied to strings and numbers that are present in complex structures like objects and arrays.

Memory Attack Example

Let’s look at an attack example using our Jscrambler Racer HTML5 app.

In this simple HTML5 game, you do some laps with a racing car, attempting to keep your lap time as low as possible. We even have a Fastest Lap scoreboard at the top.

Jscrambler Racer Screenshot

Without question, a next-gen AAA racing game.

So let’s assume we are an attacker wanting to cheat by changing our current lap time. This is a perfect example of a value that’s typically stored in memory.

So, using one of many widely available tools for tampering with the memory, we can start looking for the Time value by trial and error at runtime.

So, when the time is at 15 seconds, we can look for values between 10 and 20. This retrieves 1718 results. Then, we keep refining our search as the time increases and, when we finally get 1 result, we can directly modify its value. Et voilà, we are now the best Jscrambler Racer player of all time.

Memory Protection Example

Memory Protection Example

Now, let’s look at how this attack would unfold if this app’s JavaScript and HTML5 code were protected using Jscrambler with the Memory Protection feature.

First off, we need to upload our app to the Jscrambler Web app and open the file that contains its source code.

We can apply Memory Protection using Code Annotations. In our example, we want to protect the function that handles the Time value:

// @jscrambler enable memoryProtection
function () {
    // other variables
    var currentLapTime = 0;
    var lastLapTime    = null;
    var keyLeft        = false;
    var keyRight       = false;
    var keyFaster      = false;
    var keySlower      = false;
    var hud = {
      speed:            { value: null, dom: Dom.get('speed_value')            },
      current_lap_time: { value: null, dom: Dom.get('current_lap_time_value') },
      last_lap_time:    { value: null, dom: Dom.get('last_lap_time_value')    },
      fast_lap_time:    { value: null, dom: Dom.get('fast_lap_time_value')    }
    }
    // other nested functions below
    function update(dt) {
      var n, car, carW, sprite, spriteW;
      // other variables in nested functions
    }
}

Using the settings we defined above, Memory Protection will be applied both to the primary function and all nested functions.

Because we know that these nested functions don’t pose a security risk, we should disable Memory Protection on them to ensure maximum performance of the protected app.

We do this by adding the // @jscrambler disable memoryProtection code annotation before each nested function:

// @jscrambler enable memoryProtection
function () {
    // variables
    }
    // other nested functions below
    // @jscrambler disable memoryProtection
    function update(dt) {
      // variables in nested functions
    }
}

Now that we have added Memory Protection to all high-risk objects, we can protect the app and run the newly protected version. Let’s try to replicate the attack on the protected app.

Memory Protection Example ProtectedAs we can see, Memory Protection prevents the attacker from gaining access to the value in memory, eventually getting 0 results.

Use Cases

Looking back at the 3 main scenarios for memory attacks that we presented earlier, our demo above is a good example of “modifying the app’s behavior and, for example, accessing new features”. So, changing values stored in memory can allow attackers to cheat.

However, another very significant scenario is with applications that handle critically sensitive data, such as government, healthcare, and financial apps. In those, an attack on the memory can have devastating results, with the exfiltration of extremely sensitive user data when certain conditions are met.

Conclusion

And so we reach the end of our Jscrambler Memory Protection tutorial.

As you’ll see in our upcoming tutorials, this is one of the new Jscrambler features aimed at protecting sensitive data within web and mobile applications. Now more than ever, companies have the duty of keeping their users’ data secure. Enjoy your testing and start protecting your Applications ASAP! If you have any additional questions, feel free to contact us.

Jscrambler 101 — App Classification

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. This tutorial covers Jscrambler version 6.3.

Introduction

Last time, on Jscrambler 101 — Profiling, we explored a major new feature that helps you achieve optimal performance in your protected apps.

This time, we’re going to explore App Classification, a huge leap forward in Jscrambler’s technology. We will cover the main benefits of App Classification and how you can start using this feature.

App Classification

In a nutshell, App Classification brings two benefits: intelligent, tailor-made protection and configurable compatibility.

Both these benefits come from the actual classification that Jscrambler automatically makes when you create or upload your code to the Web App.

By extracting and analyzing metadata such as language spec, type of app, and used dependencies, Jscrambler seamlessly enhances its protection to fit your specific app. Additionally, you get a new tab “App Information” with a summary of your application.

In parallel, this classification gives you full visibility and granular control over compatibility. You can set specific compatibility goals and Jscrambler will help you ensure that these goals are met.

Knowledge is power and, with App Classification, your protected app will have optimal performance, compatibility, and security.

Navigating App Classification

Because App Classification is a seamless step in the Jscrambler Web App from version 6.3 onwards, getting started is very simple.

Let’s upload a zipped file with an example JavaScript app. Immediately, we can navigate to the “App Info” tab, which contains the results of App Classification, as shown below:

Jscrambler App Classification

Besides this app overview, we can also check App Classification details for each individual file. We need to click one of these files and check the details in the bottom left corner:

Jscrambler App Classification

Configurable Compatibility

Going back to the “App Info” tab, we have a “Browser Compatibility” section. This displays the compatibility of our source code. We can now click on “Target Versions” to set our actual compatibility requirements. Another way to get to this screen is by clicking the lower cogwheel icon on the top right and selecting “Browser Compatibility”.

As an example, let’s set our requirements as shown below:

Jscrambler Browser Compatibility

Note that, by leaving Safari and Edge blank, we are essentially ignoring compatibility checks for both. As for our other requirements, we are enforcing Jscrambler to ensure that the protected code retains compatibility with Chrome version 40+, Firefox version 50+, and IE version 8+. Now, let’s save these requirements to exit this screen.

Our next step would be to select a Jscrambler template (or handpick transformations) and protect our app. Let’s select the “Self-Defending” template.

Once we do that, Jscrambler will show us some compatibility warnings.

First, a tooltip will appear on the “Protect App” button and the button will be greyed out. This prevents us from getting a protected app version that doesn’t meet our compatibility requirements.

Jscrambler Browser Compatibility

Now, we can investigate a bit further which transformations are responsible for this compatibility change. Heading over to the “Fine Tuning” tab, we will see a blue icon next to some transformations. In our case, it appears next to the “Self-Defending” transformation:

Jscrambler Browser Compatibility

As we can read on the tooltip, selecting this transformation causes our minimum supported IE version to increase from 8 to 9.

Taking this into consideration, we have some decisions to make:

  1. Change our IE target browser versions to version 9 and above, or
  2. Skip the Self-Defending transformation or look for an alternative

If we choose the first option, it’s as simple as heading back to the “Browser Compatibility” screen and adjusting the IE version, as shown below:

Jscrambler Browser Compatibility

(Note that Jscrambler also shows us all compatibility changes on the “Protected Code” column in yellow. In this case, the known compatibility with Edge will change from version 12 to 18, and Safari will change from 4 to 10.1).

If we prefer the second option, we can look for alternative transformations that fulfill our goal. As an example, if we were choosing “Self-Defending” because we wanted its anti-tampering features, we could use the “Self-Healing” transformation instead. You can find alternative transformations in our help center.

Once we take one of these actions, the “Protect App” button will be usable again and we can go ahead and protect our app. Our resulting protected code will be compatible with our selected browser versions.

Not only that but, because of App Classification, Jscrambler will seamlessly optimize the protection for better performance and security.

Jscrambler CLI

As usual, you can also enjoy the benefits of this new Jscrambler feature when using the CLI.

First off, you can enable/disable App Classification quickly with a single line on the Jscrambler config file:

{
// other Jscrambler configurations
  "useAppClassification": true
}

Then, you can easily set your compatibility requirements in the Jscrambler config file, as shown below:

{
// other Jscrambler configurations
  "browsers": {
    "chrome": "40",
    "firefox": "50",
    "ie": "8"
  }
}

After setting these requirements, the protection via the CLI will fail whenever the selected transformations do not match the compatibility requirements. The error message also displays further details to quickly address incompatibilities.

Jscrambler Browser Compatibility

Conclusion

And so we reach the end of our Jscrambler App Classification tutorial. As we saw, by intelligently analyzing our app, Jscrambler seamlessly helps us increase the performance, compatibility, and security of our protected code. Enjoy your testing and start protecting your Applications ASAP! If you have any additional questions, feel free to contact us.

Jscrambler 101 — Profiling

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. This tutorial covers Jscrambler version 6.3.

Introduction

Last time, on Jscrambler 101 — Self-Healing, we explored a new anti-tampering approach that ensures that the app doesn’t break when tampering is detected while regenerating the original code.

This time, we’re going to delve into a new Jscrambler feature: Profiling. We will explain why Profiling is a valuable feature for performance-critical apps, how you can use it in your own apps, and its main use cases.

Profiling

When protecting JavaScript, it’s desirable to achieve the optimal balance between three key metrics: potency, resilience, and cost. The first two correlate to the overall strength of the code protection, while the last refers to eventual impacts on performance and code size.

Often, applying a strong set of protections to the whole source code doesn’t affect the performance of the app. However, some applications tend to perform less than ideal when this is done. In those cases, we can reduce Cost manually using Code Annotations — specifying different protection templates to parts of the code that we know to be crucial to performance.

Jscrambler Profiling is a new way of achieving this goal effortlessly by understanding which parts of the code are performance-critical and applying the best transformations when you protect your code.

When To Use Profiling

Now that we understand the basics of Jscrambler Profiling, it begs the question: when should we use Profiling?

As a general rule, before using Profiling, you should protect your application normally and check if the protected app has any performance issues. If it doesn’t, then there is no reason to use Jscrambler Profiling.

Setting Up Profiling

From Jscrambler version 6.3 onwards, Profiling can be set up both via the Web App and via the CLI. We’ll cover both strategies step-by-step. If you intend to use the CLI, please don’t skip the instructions on the Web App Setup, as they cover essential Profiling concepts.

We will be using the “Jscrambler HTML5 Racer” app as an example.

Initial Setup Using The Web App

Once you’re on your app’s Code Protection Builder page on the Jscrambler Web App, switch from the “Protect App” context to “Create Profiling” by using the dropdown on the right sidebar as shown below:

Profiling ContextNow, we need to instrument our app. This step adapts the application to include tools that will measure the performance of the original application and report data back to Jscrambler. It’s as simple as clicking “Instrument Application” and then downloading the newly instrumented app.

This instrumented app is not protected — do not send it to production! Instead, we will be using it to run the app in a testing environment so that it sends performance data to the Jscrambler profiler. To do so, let’s click “Start Profiling”.

From this point onwards, Jscrambler Profiling is actively receiving data whenever the profiled app is run. Our objective here is to run the app in a way that “exercises” as many functions of our code as possible, and/or the application “flows” that you believe to be less performant than usual.

So, let’s unzip the previously downloaded instrumented app and run it in our browser.

Don’t worry if the profiled app doesn’t run smoothly — this slowdown is due to the overhead of measuring the properties of the application, and will not be present in the final protected version.

Instrumented AppAs we do this, we can check the Jscrambler Profiling progress in the Web App. There, we will see a number of reports coming in as shown below — this is the collected performance data that will be essential to let Jscrambler figure out which parts of the code are performance-critical.

Jscrambler Profiling RunningYou can also run your automated unit tests with the instrumented code so that all program flows are tested.

Once we consider that we have tested most of the application, we can click “Stop Current Profiling”. Note that Profiling will also finish automatically if no data is received for 30 minutes.

Now that we have finished Profiling our app, the next step is to check the results. This step is the same for the Web App and CLI approaches.

Initial Setup Using The CLI

Note: The instructions for the CLI can also be seen in a small video.

Let’s consider that we have a simple project with our example app within the following directory:

simpleRacerDemo/
|-- profiling-ready/
|-- protected/
|-- unprotected/
| |-- *.js
| |-- *.html
|-- jscrambler.json

Our first step is to generate the jscrambler.json file through the Web App as shown below and place it on our root folder.

Download JSONNow, let’s generate the instrumented version of our app (placing it on the profiling-ready/ folder) with the following command:

jscrambler -c jscrambler.json --instrument --output-dir profiling-ready/ unprotected/**/**

We’re now ready to exercise the logic of our instrumented app. Let’s initiate the Profiling process with:

jscrambler -c jscrambler.json --start-profiling

The next step is to start running tests that cover as many possible use cases of our app as possible (luckily, in our case, this means taking our Jscrambler race car for a spin!).

Once we’re happy with our tests, let’s stop the Profiling process with:

jscrambler -c jscrambler.json --stop-profiling

And there we have it! Our app is now Profiled and our next step is analyzing the Profiling results and fine-tuning them if needed.

Profiling Results

When we stop the Profiling process, Jscrambler will process all the collected data and we will see a summary of the Profiling results on the Web App.

On this updated screen, we see 4 main results:

  • Profiled Functions: Functions that were executed during Profiling;
  • Remaining Functions: Functions that were not executed during Profiling;
  • Recommended Settings: Functions that will be protected with the recommended settings by Profiling; for example, recommending the “Light Obfuscation” default template when a function is profiled as being performance-critical;
  • General Settings: Functions that will be protected with the general settings selected by you in the Protection Builder.

We can also click “See Report” to check each profiled function of your app and their Profiling recommendations.

On this page, we can change the template that Profiling suggested in each instance — perhaps we know that a certain function is security-critical but Profiling suggested a “Light Obfuscation” template; we can change this template to “General Settings” to ensure that this specific function will be protected with the overall protection settings.

Jscrambler Profiling ReportNote that you should upload Source Maps in cases where you are using transpilers or module bundlers, for example. Simply use the “Source Maps” toggle for this.

We will also see some references to “Annotations”. This has to do with the different Profiling modes that can be used to apply Profiling recommendations when it’s time to protect the app. Let’s explore that next.

Protecting a Profiled App

Since Jscrambler version 6.3 onwards, there are 3 different Profiling modes: Annotations, Automatic, and Off.

Deciding which to choose depends on your objectives. The Annotations mode requires a one-time additional step where you have to annotate your code – meaning that Profiling results will persist after source code changes. The Automatic mode automatically applies Profiling results at protection time, but new Profiling is needed after source code changes.

So, as a rule of thumb, you will find the Automatic mode more useful when you’re first trying out Profiling or just wanting to see its results quickly. The Annotations mode is more beneficial when you want to easily integrate Profiling into your CI/CD pipeline.

The Off mode, as the name implies, doesn’t use the Profiling results at all when protecting the code.

Choosing a Profiling mode and protecting the app varies depending on whether you’re using the Web App or the CLI. Let’s explore both below.

Protecting Profiled App Via the Web App

Let’s change our Web App context from “Create Profiling” to “Protect App” using the dropdown on the top right. Now, we can choose a Profiling mode on the bottom dropdown, as shown below.

Protected Profiled AppIf we’re using the Automatic mode, then our next step is simply to click “Protect App”. Jscrambler will automatically apply the Profiling results and we’ll get our protected code.

But if you want to use the Annotations mode, you’ll have to get back to the Profiling Results page. Once there, you can either download a .csv file with all Annotations or copy them one by one, as shown below.

Protected Profiled AppIn both instances, you’ll have clear instructions about the position (line/column) of the annotation. Let’s look at an example:

"// @jscrambler profiling default lightObfuscation","highCostFunction",1:10,"index.js"

This means that we have to find function highCostFunction on line 1, column 10, and add the Profiling annotation so that the final result looks like this:

// @jscrambler profiling default lightObfuscation
function highCostFunction() {
 // performance-intensive logic
}

If you plan on using minifiers, consider adding these annotations as strings to avoid having them removed.

After placing the required annotations, we go back to the “Protect App” context, change the Profiling mode to Annotations, and click the “Protect App” button. Jscrambler will use our Profiling annotations and protect the code accordingly.

If, after this, we make some minor changes to our source code, we probably won’t have to profile the app again — Profiling is necessary after major changes.

Now, all that’s left for us to do is check the performance of our protected app.

Protecting Profiled App Via the CLI

Now that we understand the different Profiling modes, we are one command away from protecting our code.

So, if we want to use the Automatic mode, we use the command:

jscrambler -c jscrambler.json --profiling-data-mode automatic

This will create a new folder inside the protected/ folder with our newly protected app. Following our example, we can serve it locally with:

http-server protected/unprotected/

 

Final App Test

We can now test our final app, which was protected using Profiling recommendations. Let’s take our Jscrambler race car out of the garage for another spin:

Protected Profiled AppNot only does our HTML5 app run with great performance, but all of its code is also protected with an excellent potency-resilience-cost balance. Based on our tests for this HTML5 app, the average performance of the protected profiled app (measured in FPS) was 35% better than the un-profiled protected app.

And remember, our code is still protected with the best JavaScript protection available today:

Jscrambler Profiling Protected CodeWith Jscrambler Profiling doing all the heavy lifting to obtain most of the gain, we could now still use Code Annotations if we wished to tweak performance even further.

Conclusion

This sums up Jscrambler Profiling — a feature that enables effortlessly improving the performance of protected code in complex apps.

Enjoy your testing and start protecting your Applications ASAP! If you have any additional questions, feel free to contact us.

Jscrambler 101 — How to use the CLI

Last updated on May 5th, 2023

Welcome back to Jscrambler 101! A collection of tutorials on how to use Jscrambler to protect your JavaScript. These tutorials cover Jscrambler version 8.1.


Introduction – How to Use the CLI


Last time, we talked about Jscrambler’s Code Locks and how they could be used to protect your JavaScript and enforce licenses.

We’ve decided to take a step back from our transformations and show you a simple way to protect your code through our command line interface (CLI).

Let’s take a sample project:

sample-project-jscrambler

Note that there’s a subfolder structure. Inside the js folder, we have a dontProtect.js file that we don’t want to protect with Jscrambler, but we do want to protect the clock.js and the index.html files.


Ignore files


We’ll start by creating a .jscramblerignore file in order to ignore the dontProtect.js file.

The .jscramblerignore file must be placed at the root of your project. The level where you should place this file depends on how you plan to zip your project.

If you will zip the project from inside the sample project folder, the .jscramblerignore file should be at the same level as index.html.

ignore-files-example



As so, the .jscramblerignore file should include the following:

js/dontProtect.js


If you want to include the sample project folder in your zip file, then the .jscramblerignore file should be at the same level as this folder.


ignore-files-second-step-tutorial


In this case, the .jscramblerignore file should have the following:

sample project/js/dontProtect.js


You can also use .jscramblerignore for folders, and to include certain files in the protection process. For example:

#ignore all files in js folder
sample project/js/

#except for clock.js
!sample project/js/clock.js


Now, we’re ready to protect our application using the CLI.


Download jscrambler.json

First, we have to go to Jscrambler’s Dashboard and create an application by clicking the Create App button.

Once you’re inside the app, select the Application Modes and the Transformations you want to apply (or select a template). Once that’s done, download your selections to a jscrambler.json file by clicking on the lower cogwheel in the top right corner of the screen, then selecting “Download Settings in JSON”. It will give you 2 options, No Secrets or All Parameters. Since the Jscrambler secrets are required to use the CLI, for the sake of this tutorial, you can download the file with All Parameters.


download-jscrambler-json-example


Installing the CLI

Let’s continue by installing the CLI through node’s package manager:

npm install -g jscrambler


Now let’s zip our project, and remember to include the .jscramblerignore file. For ease, we will place our jscrambler.json file next to our zip file, but they could be in different locations.

Now, open your terminal, and after navigating to the same folder where you have your zip and jscrambler.json file, run the following:

jscrambler -c jscrambler.json -o protected sampleProject.zip


This means that the sampleProject.zip will be protected and placed in the protected folder.

sampleProject-zip-jscrambler-tutorialNow, you can test if the protection worked correctly. If you open the dontProtect.js file, you’ll notice that no changes occurred in this file. All other JavaScript files which were not included in dontProtect.js will be protected.

You can find further information about the Jscrambler CLI options.



Integrations with Frameworks and Libraries

In case you’re using a specific JavaScript framework or library, see our integration tutorials below:

More information about Framework Compatibility


Conclusion

Feel free to proceed to one of our other 101 Tutorials:


Enjoy your testing and start protecting your Applications ASAP! If you have any additional questions, feel free to contact us.