5 ms·
Ask HN: Can you protect your JavaScript code?
Friends of mine have seen their non-trivial code lifted right off their websites and sold by people on Fiverr as if they had written it. I would imagine a lot of folks on Fiverr do just this: Scour the web for the solution they are being paid to create and simply copy-and-paste it to their unsuspecting clients.
Say you are building a site that will make use of very heavy JS code, to the point that the code is critical to your business and you do not want it copied or stolen. How do you protect it? Can you protect it?
I can't see much past obfuscation through minification. How effective are these techniques?
One thought is to use AJAX wherever possible in order to have that code live server side. This, of course, would result in greater server load.
- mattbgates 9y agoYou could probably use a Javascript Obfuscater ( http://www.danstools.com/javascript-obfuscate/ http://www.danstools.com/javascript-obfuscate/ or https://javascriptobfuscator.com/Javascript-Obfuscator.aspx https://javascriptobfuscator.com/Javascript-Obfuscator.aspx ) but you'll always want to make backups of your original code. There are some that are able to obfuscate it but may not be able to reverse it. I've used it to mask emails when my contact forms have gotten spam, but haven't used it for massive amounts of code. However, if you are after protecting that code and making sure no one steals it, than why not use it?
- unprotected 9y agoIf you insist to protect the code you can use Jscrambler (https://jscrambler.com/ https://jscrambler.com/).
- oldandtired 9y agoSeriously, if you are wanting to protect client side js, you are closing the barn after the horse has bolted. Even with obfuscation, if the code is worth copying (for any reason, including money), it will be copied. It is irrelevant if it closed or open source. Even with it server side, any mistakes on your part and the code is available to whoever really wants it. Your friends would be better off finding out who was sold the code and letting those people know where the code actually came from. Do it pleasantly and your friends may find themselves some new customers. The one thing they do need to be careful about is not coming across vindictively. The potential clients may find that attitude less than favourable. Your friends could even do reviews on the Fiverr site with humorous comments about how good the people were at copying other peoples code and selling it as their own. Be funny about it and let the culprits lose it. It will pay off in the end. I have come across others who have had their work copied and then sold. The best way to handle this is NOT to get angry, but to use it as a means of advertising yourself. Your work is so good that people want copy it and pretend that it is their own work. How good a recommendation is that? There are different ways to handle this, be inventive, be pleasant and be smart.
- martin_hnuid 9y agoI know this is a tough one. I'm trying to understand what the options might be while fully understanding that JS is, in the end, not protectable. Say you develop a site that offers a very specialized CAD package unique to an industry. The entire thing has to be client side JS and it could take a year or more to develop. Theft of code in a case like that could be catastrophic. Frankly, I'm surprised nobody has come up with a real solution for this.
- oldandtired 9y agoThe problem here is that you are making a choice to use someone else's facilities to run your system. Once you do that, you have given up the control over what they do with it once it is on their facilities. The first question I would ask you is why does it have to be client side? The second is why does it have to be in javascript? As I said above, in using javascript you have forced the horse to bolt and then you close the barn doors. Javascript requires you to send them the source. If you use it, then that is the fundamental choice you are making at the outset. You cannot complain about someone copying your source code if the choice you make is for them to have to copy the source code to be able to use the application you have so painstakingly built. If you don't want them to have the source code then you give them a binary blob that has everything appropriately encrypted. The other point, I want to highlight is that having a copy of something is not theft. You can only steal something when you remove it from the control of the person you are stealing from. Not any copies, the actual object itself. These objects can be intangible such as your reputation, but that is another subject. It is an unfortunate fact of our society that this very important distinction has been lost. Theft only applies when the item being obtained is unique and belongs to someone else. Once you share something, whether it be code or an idea or anything else that can be treated as an infinitely copiable, intangible object and it is copied, it no longer is uniquely yours. Any copies that are made that are not made by you are not morally yours, irrespective of any monopoly rights granted to you by the reigning government over you. Governments do not deal with morally, they dictate law, which is a completely different thing. So in this case being discussed, you freely (irrespective of any form of payment you might receive) have given away the source code because of the underlying architecture you are using. If you don't want this happen then you have to choose some other architecture for the dissemination of your application. As I have said elsewhere, any copies created that have not been authorised by you under any monopoly rights that you have been given by some governing body can be used as free advertising but you cannot cry theft as a moral consequence. These days, I work on free projects and so I freely give away my work. This is the hope that when I actually need to do paid work, I'll be able to show my previous work and they will see that I am worth having on board.
- spurlock 9y ago> Say you are building a site that will make use of very heavy JS code, to the point that the code is critical to your business and you do not want it copied or stolen. How do you protect it? Can you protect it? There are countless obfuscation tools out there, but in the end if someone wants your code, they can reverse it into more readable code and steal it, using it on their website/webapp. It's the way browser engines are designed that ensures this. JavaScript is there for the taking and is not compiled into machine code. It's interpreted. So no, you can't protect it. No matter how much you abuse the eval() function or mangle the code[1] [1]: https://en.wikipedia.org/wiki/JSFuck https://en.wikipedia.org/wiki/JSFuck
- woranl 9y agoHow about rewrite/convert the app in C++ and deliver it via WebAssembly?
- martin_hnuid 9y agoThat's very interesting. I wasn't familiar with this. Thanks.