Compiled code shows secrets in the clear #14048
Replies: 3 comments 6 replies
-
|
That is because deno compile just puts your code under the Deno binary (simplified but it's how it works) However, depending on what you are building of course, you should use a .env file instead of putting your secrets inside your javascript code. As a side note, there is this repo that has not been updated but had the purpose of obfuscating the code directly inside deno, (that requires re-compiling deno) https://github.com/littledivy/deno_compile There isn't any other way (yet?) |
Beta Was this translation helpful? Give feedback.
-
|
TLDR: Never put secrets in your code, this is a very bad practice. You should never version-control them either. First, let me say that an executable file might look like gibberish when opened in a text editor, but it is actually a structured file. Deno compile does for Deno what nexe or pkg do for Node: create a standalone, self-contained binary from your JavaScript or TypeScript source code, which means that your code is bundled as-is. You could use obfuscation techniques to "hide" your code and secrets, but that just means it will be more difficult to see them, it won't be impossible. So you should not rely on that. A great solution though would be to just NOT ship any kind of credentials with your code. Load them from a file, environment variables, etc. And never commit the file or else it will show in your repository history (even if you delete it afterwards). |
Beta Was this translation helpful? Give feedback.
-
|
Thank you all for your quick responses. FYI, normally, I never put secrets in code, I use the .env files. The reason I was investigating the Deno Compiler is for those small 'scripts' that I wanted to encode and pass to others within our organization, like our network ops guy so I could write some canned service code and just provide him the exe. As a test of the compiler, I put secrets that are normally in the .env file in the code to see if they were visible, and I found that they were. So based on the responses, hiding values in the compiled code is not an option. I will have to find my own way to obfuscate my secrets. So maybe my original post should have been 'encrypt javascript code compile option' in the 'Ideas' section? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to encode all the JavaScript files prior to or during deno compile? I did not see an option.
Background:
In the Javascript code, I include some secrets (like API KEYs) in the clear, with hope that the codes would be hidden in the exe file. However, after compiling for Windows, when looking at the executable with a text editor, towards the end, the javascript is in the clear and is visible, as well as my secrets.
Beta Was this translation helpful? Give feedback.
All reactions