You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is the source really protected with building apps with Electron? #2570
No, it is very easy to get your source code even when you packaged them in asar archive, the V8 JavaScript engine is never designed to hide source code. NW.js does succeed to hide one file of the source code completely, but with the price of significant performance downgrade.
So if you really to want to protect your source code, you have to write them in C++ and make a native Node module.
Reacted by Nicolas Guerinet, Zakaria Mansouri, Antonio Seo, Vikram, percy507, Julia A. Meister, recodyx, navi, DrakeXiang, MRsabs and 6 more
There are some options, but the level of protection they provide is limited by the reasons @zcbenz mentioned:
You could implement some decryption logic on your own, in a C++ node addon, but it will probably still be breakable (e.g. debug the program and copy the source after decryption but before eval).
There's also EncloseJS, that claims to compile your code for node.js/io.js, so it might work with Electron.
nw.js, which is a similar project, has support for v8 snapshots which provide some kind of protection (see details here).
Note that all of this methods, will incur some performance penalty.
@fritx, Node has a module called vm which can eval code. I guess you could find a way to call it or it's underlining C++ API from your addon and use that to load your code.
Keep in mind that the user could still manage to open the developer tools and see the loaded script. Even if you manage to block that using a custom Electron build and the addon checking to see that your Electron build wasn't tampered with, the user could still see your code as a string in memory.
Reacted by Extarys, Yuri Araújo, Sam Y, Unidentified, Sóstenes Apollo, eg, mohammadalimehdizadeh, Paulina Grunwald, Cheng Zheng(郑诚), Fellyp Karlon and 7 more
Reacted by Robert Zack Jaidyn Norris-Karr, Sid van Vliet, Josh Yoerger, Joseph Davies, Fellyp Karlon, Berkant İpek, Raphaël Badia, Leonardo Araoz and ~Excalibur
AFAIK it's simply unprotected. You can extract their app.asar and access the source code. For sensitive parts of the application you usually write custom addons in a compiled language like C/C++, as suggested above.
@charlesr1971 Meanwhile obfuscation is an option, it's not very effective. Obfuscated code is easily traceable simply using an IDE. Speaking from experience because I constantly write mods for applications and by this point, it has become quite effortless. Heavy obfuscation however, including string encryption is very effective. But the performance hit becomes unbearable. Especially for HTML UIs since it's already very clunky. Comparing this to compiled code, it's a no-brainer that the latter is way more advantages on every aspect. Also you don't need to have Angular. Setting up obfuscation with Webpack is extremely easy.
Even a beginner dev knows that the decompilation is inevitable but I think what we all looking for here is merely some protection against layman end users. I don't want my code to be exposed just because some bored YouTuber learned how to extract an asar file. And binary files provide that while not losing any performance too. In some scenarios improving the performance too. NW.js is a great example for that.
@m4heshd Because of this code protection issue, I am thinking about putting my application online. I want to place ipcMain on the server and ipcRenderer will be the client.
My question is, does the invoke method, which links ipcRenderer with ipcMain, use XHR?
So, could I continue to use this protocol to connect client with server.
Although, I have a lot of server side development experience, I haven’t used NodeJs, much. Coldfusion [cfml] is my language of choice.
However, I don’t want to rewrite all of my ipcMain code, so I would like to use it as my server side application.
Could you suggest how I can convert my Electron app into client server model? Thanks 🙏
Read this documentation. Electron does have something similar called "V8 snapshots" which is a part of V8 engine but it's not exactly similar. It's extremely difficult to adapt to, no useful documentation and could result in development and production state of the app behaving very differently.
Can I integrate NW.js with this environment?
Yes you can but beware that NW.js lacks the massive and active support system Electron has. Hence the less popularity. It has to do with not having a proper, up-to-date build suite, having to deal with the pain of building native modules with nw-gyp and more stuff like that.
I want to place ipcMain on the server and ipcRenderer will be the client.
Technically, you cannot "IPC" over the internet. For that kind of communication, you have to implement some kind of a REST API specific for your application.
does the invoke method, which links ipcRenderer with ipcMain, use XHR?
No. It's a completely different, native implementation included with Chromium.
Could you suggest how I can convert my Electron app into client server model?
I'm sorry I can't help you with that because it completely depends on your application's structure and process.
Could you suggest how I can convert my Electron app into client server model? Thanks pray
@charlesr1971 you should migrate your heavy code (source which you want to protect) into a server
and connect with it through RestAPI or GraphQl or render your html from it if you wish too, or you could use native modules and load your modules from your electron (however it's not too much useful since the hacker/cracker still have your source code)and can use your modules too
@annymosse How is a hacker going to get hold of the NodeJs code on my server? Yes. The hacker can inspect the Anguler client side code, but that is useless without the NodeJs part.
Converting this to a client server model is definitely the way to go.
The Electron engineers really need to implement code protection. This issue is a real disappointment. :(
How is a hacker going to get hold of the NodeJs code on my server?
I didn't say hacker can get your code at server side, however it can if you have a bad security structure.
Electron team can't make the silver bullet, after all there's no way to eliminate the crackers (reverse engineering) even avast, Kaspersky antivirus couldn't be safe, so the solution is to keep your code between your hands at server side and provide API then invest your money to keep your servers safe against the hackers instead the crackers.
If you need as "almost of us" need extra shields to keep your source code secure and perform well against these curious newbie users is to use native add-ons through N-Api & CPP,C or Rust; then obfuscate the rest "lightweight" part of your code.
For my own prospectives I prefer to see Electron more modular , FTP(S) stand alone module, WS(S) module,.... By this way the developer can load only the required modules and ship it's heavy important part as a native part belong to electron itself and the cracker can't make a single solution to crack all electron project since they're different, and the the project will be much more light and performing so well, and for the team at first time it will be a huge hard path to walk through, however at the end the project can stand alive forever as a modules instead a single huge hard project, and they can maintain it easily and can get more contributers even the chromium team might switch into electron structure because it's more cleaner and lighter.
How is a hacker going to get hold of the NodeJs code on my server?
I didn't say hacker can get your code at server side, however it can if you have a bad security structure.
Electron team can't make the silver bullet, after all there's no way to eliminate the crackers (reverse engineering) even avast, Kaspersky antivirus couldn't be safe, so the solution is to keep your code between your hands at server side and provide API then invest your money to keep your servers safe against the hackers instead the crackers.
If you need as "almost of us" need extra shields to keep your source code secure and perform well against these curious newbie users is to use native add-ons through N-Api & CPP,C or Rust; then obfuscate the rest "lightweight" part of your code.
For my own prospectives I prefer to see Electron more modular , FTP(S) stand alone module, WS(S) module,.... By this way the developer can load only the required modules and ship it's heavy important part as a native part belong to electron itself and the cracker can't make a single solution to crack all electron project since they're different, and the the project will be much more light and performing so well, and for the team at first time it will be a huge hard path to walk through, however at the end the project can stand alive forever as a modules instead a single huge hard project, and they can maintain it easily and can get more contributers even the chromium team might switch into electron structure because it's more cleaner and lighter.
@annymosse Well. NW.js seem to be able to achieve full protection. Why can’t Electron implement something like this? The only reason, I won’t use nw.js, is that we have to convert all node modules to binary etc. But, this process could be automated.
@charlesr1971 As I've said earlier, decompilation and deobfuscation is inevitable. There's no actual way of completely protecting client side code. Only the means of making it harder to do so. I'll simply put it as this. If your CPU can read the instructions, so can the user. That's all there's to it. Only way to have it protected is to have as much of the functionality at server-side as possible. But users could still have access to your backend APIs. So API abuse is also something to be worried about.
But I agree with you on Electron needing something similar to what NW.js have achieved. It would be such a great addition to Electron but as the devs mentioned multiple times earlier, don't hold your breath on that.
There's no full code protection when your app become at the user end desktop, he/she can crake it and use it for free, if you're looking for a solution you should use node add-ons which much more faster smaller size then these .bin files , it's true that when you compile your js code using nwjc you don't need to use other low level language but you'll keep facing same issue "your software will be craked"
@m4heshd Are you saying it is possible to reverse engineer compiled C++ or Java? I think this is very difficult to do and what is impossible is to reverse it to the original source code, because there is no 1:1 relation between the machine code and the source code..
So, what I am saying, why can’t the Electron team convert the JS to machine code.
@annymosse I think what I am saying, is electron should try and provide as much protection as any piece of software that is compiled to machine code, within an executable. Obviously, any piece of software can be cracked, if you throw enough resources & expertise, at it. But, most software users, won’t try and reverse engineer machine code.
Reacted by Abdelkarim Ben Hamida, xxss0903, Duc Nguyen Huu and xiling
I'd just like to interject for a moment. What you're refering to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX.
Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called Linux, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project.
There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called Linux distributions are really distributions of GNU/Linux!
thank you for your note, It's true that much better we use the correct name for right thing, It's fact Linux (the kernel) became the name of OS which ment to be controlled by GNU, however the alternative of Linux (monolithic) is Hurd (microkernel) which have slow development, and less contributors.
The successful key still until now the performance and stability and for this reason Electron is much more attracting developers more than other hybrid technologies (NWJs), and the current path of Electron not providing bright future compared to other projects, flutter and some new shiny rust's solutions, rust itself provide security, performance, stability and productivity so the developer can focus on securing it's project much safer without sacrificing the performance and providing modular solution, just consume what do you import, and crackers wont get same structure (libraries, folders, constant files,...), it became much harder to predict which framework, programming language....
Activity
zcbenz commentedon Aug 24, 2015
No, it is very easy to get your source code even when you packaged them in
asararchive, the V8 JavaScript engine is never designed to hide source code. NW.js does succeed to hide one file of the source code completely, but with the price of significant performance downgrade.So if you really to want to protect your source code, you have to write them in C++ and make a native Node module.
etiktin commentedon Aug 24, 2015
There are some options, but the level of protection they provide is limited by the reasons @zcbenz mentioned:
Note that all of this methods, will incur some performance penalty.
fritx commentedon Jul 27, 2016
@etiktin I'm running into this too.
Is it possible to just apply node.js code in C++ addon directly?
etiktin commentedon Jul 27, 2016
@fritx, Node has a module called vm which can eval code. I guess you could find a way to call it or it's underlining C++ API from your addon and use that to load your code.
Keep in mind that the user could still manage to open the developer tools and see the loaded script. Even if you manage to block that using a custom Electron build and the addon checking to see that your Electron build wasn't tampered with, the user could still see your code as a string in memory.
fizzvr commentedon Aug 17, 2016
Sounds good protect the source! 🔑
alexisfrjp commentedon Feb 2, 2017
Then I have a question, how closed code electron apps such as GitKraken, Whatsapp or Slack can hide the code ?
Hum4n01d commentedon Feb 3, 2017
@Alexis57 I have the same question; maybe it’s just that inspect element is disabled or something
alexisfrjp commentedon Feb 3, 2017
Or maybe the main code comes from a C/C++ library and then they use electron just for the GUI, don't know...
nabtron commentedon Mar 1, 2017
Would like to know how whatsapp and slack protect their source code too
boeserwolf commentedon Mar 22, 2017
AFAIK it's simply unprotected. You can extract their app.asar and access the source code. For sensitive parts of the application you usually write custom addons in a compiled language like C/C++, as suggested above.
nabtron commentedon Mar 22, 2017
How can we compile c++ code in it?
boeserwolf commentedon Mar 22, 2017
See: https://nodejs.org/api/addons.html
nabtron commentedon Mar 22, 2017
@boeserwolf thanks! :)
vasyl-shumskyi commentedon Jun 29, 2017
Subscribed
52 remaining items
charlesr1971 commentedon Dec 3, 2021
If you use Angular Electron, the Angular part is converted into Vanilla JavaScript and obfuscated, automatically. It is pretty much unreadable. :)
m4heshd commentedon Dec 3, 2021
@charlesr1971 Meanwhile obfuscation is an option, it's not very effective. Obfuscated code is easily traceable simply using an IDE. Speaking from experience because I constantly write mods for applications and by this point, it has become quite effortless. Heavy obfuscation however, including string encryption is very effective. But the performance hit becomes unbearable. Especially for HTML UIs since it's already very clunky. Comparing this to compiled code, it's a no-brainer that the latter is way more advantages on every aspect. Also you don't need to have Angular. Setting up obfuscation with Webpack is extremely easy.
Even a beginner dev knows that the decompilation is inevitable but I think what we all looking for here is merely some protection against layman end users. I don't want my code to be exposed just because some bored YouTuber learned how to extract an
asarfile. And binary files provide that while not losing any performance too. In some scenarios improving the performance too. NW.js is a great example for that.charlesr1971 commentedon Dec 3, 2021
I had a look at NW.js, but I don’t quite understand what it does? It says that it allows one to use node modules in the DOM?
But how does it protect our source code? I am using Angular with Electron. Can I integrate NW.js with this environment?
charlesr1971 commentedon Dec 3, 2021
@m4heshd Because of this code protection issue, I am thinking about putting my application online. I want to place ipcMain on the server and ipcRenderer will be the client.
My question is, does the invoke method, which links ipcRenderer with ipcMain, use XHR?
So, could I continue to use this protocol to connect client with server.
Although, I have a lot of server side development experience, I haven’t used NodeJs, much. Coldfusion [cfml] is my language of choice.
However, I don’t want to rewrite all of my ipcMain code, so I would like to use it as my server side application.
Could you suggest how I can convert my Electron app into client server model? Thanks 🙏
m4heshd commentedon Dec 3, 2021
Read this documentation. Electron does have something similar called "V8 snapshots" which is a part of V8 engine but it's not exactly similar. It's extremely difficult to adapt to, no useful documentation and could result in development and production state of the app behaving very differently.
Yes you can but beware that NW.js lacks the massive and active support system Electron has. Hence the less popularity. It has to do with not having a proper, up-to-date build suite, having to deal with the pain of building native modules with
nw-gypand more stuff like that.Technically, you cannot "IPC" over the internet. For that kind of communication, you have to implement some kind of a REST API specific for your application.
No. It's a completely different, native implementation included with Chromium.
I'm sorry I can't help you with that because it completely depends on your application's structure and process.
annymosse commentedon Dec 4, 2021
@charlesr1971 you should migrate your heavy code (source which you want to protect) into a server
and connect with it through RestAPI or GraphQl or render your html from it if you wish too, or you could use native modules and load your modules from your electron (however it's not too much useful since the hacker/cracker still have your source code)and can use your modules too
charlesr1971 commentedon Dec 4, 2021
@annymosse How is a hacker going to get hold of the NodeJs code on my server? Yes. The hacker can inspect the Anguler client side code, but that is useless without the NodeJs part.
Converting this to a client server model is definitely the way to go.
The Electron engineers really need to implement code protection. This issue is a real disappointment. :(
annymosse commentedon Dec 4, 2021
I didn't say hacker can get your code at server side, however it can if you have a bad security structure.
Electron team can't make the silver bullet, after all there's no way to eliminate the crackers (reverse engineering) even avast, Kaspersky antivirus couldn't be safe, so the solution is to keep your code between your hands at server side and provide API then invest your money to keep your servers safe against the hackers instead the crackers.
If you need as "almost of us" need extra shields to keep your source code secure and perform well against these curious newbie users is to use native add-ons through N-Api & CPP,C or Rust; then obfuscate the rest "lightweight" part of your code.
For my own prospectives I prefer to see Electron more modular , FTP(S) stand alone module, WS(S) module,.... By this way the developer can load only the required modules and ship it's heavy important part as a native part belong to electron itself and the cracker can't make a single solution to crack all electron project since they're different, and the the project will be much more light and performing so well, and for the team at first time it will be a huge hard path to walk through, however at the end the project can stand alive forever as a modules instead a single huge hard project, and they can maintain it easily and can get more contributers even the chromium team might switch into electron structure because it's more cleaner and lighter.
annymosse commentedon Dec 4, 2021
I didn't say hacker can get your code at server side, however it can if you have a bad security structure.
Electron team can't make the silver bullet, after all there's no way to eliminate the crackers (reverse engineering) even avast, Kaspersky antivirus couldn't be safe, so the solution is to keep your code between your hands at server side and provide API then invest your money to keep your servers safe against the hackers instead the crackers.
If you need as "almost of us" need extra shields to keep your source code secure and perform well against these curious newbie users is to use native add-ons through N-Api & CPP,C or Rust; then obfuscate the rest "lightweight" part of your code.
For my own prospectives I prefer to see Electron more modular , FTP(S) stand alone module, WS(S) module,.... By this way the developer can load only the required modules and ship it's heavy important part as a native part belong to electron itself and the cracker can't make a single solution to crack all electron project since they're different, and the the project will be much more light and performing so well, and for the team at first time it will be a huge hard path to walk through, however at the end the project can stand alive forever as a modules instead a single huge hard project, and they can maintain it easily and can get more contributers even the chromium team might switch into electron structure because it's more cleaner and lighter.
charlesr1971 commentedon Dec 4, 2021
@annymosse Well. NW.js seem to be able to achieve full protection. Why can’t Electron implement something like this? The only reason, I won’t use nw.js, is that we have to convert all node modules to binary etc. But, this process could be automated.
m4heshd commentedon Dec 4, 2021
@charlesr1971 As I've said earlier, decompilation and deobfuscation is inevitable. There's no actual way of completely protecting client side code. Only the means of making it harder to do so. I'll simply put it as this. If your CPU can read the instructions, so can the user. That's all there's to it. Only way to have it protected is to have as much of the functionality at server-side as possible. But users could still have access to your backend APIs. So API abuse is also something to be worried about.
But I agree with you on Electron needing something similar to what NW.js have achieved. It would be such a great addition to Electron but as the devs mentioned multiple times earlier, don't hold your breath on that.
annymosse commentedon Dec 4, 2021
There's no full code protection when your app become at the user end desktop, he/she can crake it and use it for free, if you're looking for a solution you should use node add-ons which much more faster smaller size then these
.binfiles , it's true that when you compile your js code usingnwjcyou don't need to use other low level language but you'll keep facing same issue "your software will be craked"charlesr1971 commentedon Dec 4, 2021
@m4heshd Are you saying it is possible to reverse engineer compiled C++ or Java? I think this is very difficult to do and what is impossible is to reverse it to the original source code, because there is no 1:1 relation between the machine code and the source code..
So, what I am saying, why can’t the Electron team convert the JS to machine code.
charlesr1971 commentedon Dec 4, 2021
@annymosse I think what I am saying, is electron should try and provide as much protection as any piece of software that is compiled to machine code, within an executable. Obviously, any piece of software can be cracked, if you throw enough resources & expertise, at it. But, most software users, won’t try and reverse engineer machine code.
annymosse commentedon Mar 2, 2023
thank you for your note, It's true that much better we use the correct name for right thing, It's fact Linux (the kernel) became the name of OS which ment to be controlled by GNU, however the alternative of Linux (monolithic) is Hurd (microkernel) which have slow development, and less contributors.
The successful key still until now the performance and stability and for this reason Electron is much more attracting developers more than other hybrid technologies (NWJs), and the current path of Electron not providing bright future compared to other projects, flutter and some new shiny rust's solutions, rust itself provide security, performance, stability and productivity so the developer can focus on securing it's project much safer without sacrificing the performance and providing modular solution, just consume what do you import, and crackers wont get same structure (libraries, folders, constant files,...), it became much harder to predict which framework, programming language....