Secure JavaScript code using JS Obfuscation

secure-source-code
Protecting the source code of your application is the one of the main concern when it comes to the security of your application. JavaScript is one of the commonly used front-end scripting language that powers-up almost all the web applications. JavaScript is interpreted by browsers so it is must that should be visible and accessible to browser.
Unfortunately, this makes the JS visible to users too. Anyone with slight experience in browser debugging can see the source code of JS files. Even the minified files can be reverted to their original source code to make them readable.
By default browsers/servers do not provide any mechanism to secure your JS code but there are some techniques by which you can protect your source code. Code Obfuscation is one of the best and robust technique to secure the JS code.
There is a tool called JavaScript Obfuscator which allows you to obfuscate your JS online or you can download their setup files and do it on your local machine.
Let me show you how a simple JS and its obfuscated code looks like. The first one is the normal JS code and second one is obfuscated version –

 

obfuscated_code

How JS Obfuscation works ?

Obfuscation is the technique in which the tool scans your source code and changes the variable names, function names, data structures and rearranges the code in order to make it less readable and nearly impossible to apply reverse engineering on the code.

Benefits of code Obfuscation

  • Protects the source code from being available to everyone.
  • Works with almost all JS frameworks.
  • Maintains the algorithmic logic and data structures.
  • Reduces the size of code.

Drawbacks of code Obfuscation

  • Obfuscation process is irreversible. So if you loose your original source code, you lost it.
  • Can reduce the productivity in development and staging phases.
  • Need special tools, where you can share your JS code to apply obfuscation technique.