Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best solution to obfuscate Angular JS controller code

I want to Obfuscate + Minify my Angular JS code in order to not make it public and if someone tries to decode it, then make it a hurdle. Code is running up on the server.

Note: In future we are planning to shift http to https.

I have seen a lot of options like Gulp, Google Closure Compiler, UglifyJS etc and many tool which a user can download and obfuscate the code like jsob, javascript obfuscate etc.

I need a suggestion and have few questions.

  1. What is the more better approach apart from encryption?
  2. If I shift to https shall I still require obfuscations?
  3. What are the better and easy approaches with pros and cons?
  4. If I use a tool like JavaScript obfuscate, then what will be its pros and cons? Am I able to get It back, I mean decode?
  5. Or If someone is able to look into gulp file will it be easy to get my code?
like image 785
Mishi Avatar asked Jan 19 '17 08:01

Mishi


People also ask

How can I obfuscate JavaScript code?

You can obfuscate the javascript source all you want, but it will always be reverse-engineerable just by virtue of requiring all the source code to actually run on the client machine... the best option I can think of is having all your processing done with server-side code, and all the client code javascript does is ...

Which of the below tool can be used for JavaScript obfuscation?

Tools For Code Obfuscation In Javascript You can use an online tool like: JavaScript Obfuscator. Beautifytools.

How do you obfuscate your code?

Encrypting some or all of a program's code is one obfuscation method. Other approaches include stripping out potentially revealing metadata, replacing class and variable names with meaningless labels and adding unused or meaningless code to an application script.


2 Answers

1 - It really depends on what you are trying to achieve. If you really want to protect your code to hide your business logic, you should go for a resilient solution, instead of relying on a minification or obfuscation tool per se which is far too easy to defeat.

2 - Https simply means that the communication between your browser and website is encrypted. Https can also be decrypted, so it would make sense to apply other protection mechanisms

4 - JavaScript Obfuscator and several other tools do not protect the code, they are simple obfuscators and so they can be easily reversed in minutes and that's why some people think it's not worth protecting code on the client-side. In fact, you can get most of the original code using a simple JS optimizer. ClosureCompiler and UglifyJS have precisely this different approach, they reduce the size of the code and optimize it, they do not offer code protection.

3, 5 - I found this blog post from js13kGames competition creator quite useful for my case. He suggests a solution that seems to be more appropriate - Jscrambler. IMO you should give it a try as it combines code transformations with anti-debugging and anti-tampering features. You can also lock your code to a predefined list of domains or set an expiry date to deliver expirable demos, for example. Maybe it could be a fit for your case too as it supports Angular.

like image 169
user7366409 Avatar answered Oct 04 '22 00:10

user7366409


I've found a nice solution using gulp-uglify. If you use implicit anotation, first use gulp-ng-annotate for not losing service names on uglify process.

like image 36
MarcBilbo Avatar answered Oct 04 '22 02:10

MarcBilbo