0

I am using nest.js and I am trying to obfuscate the code in the dist folder. I tried various solutions but none of them seems to work. They all fail when I bootstrap the server(main.js file)

Is there any recommend tool that I can use that is working properly?

MasterOfPuppets
  • 173
  • 3
  • 10

2 Answers2

2

Due to how Nest works with typescript reflection and class names, obfuscation often leads changing the names of classes which makes the reflection system not work in the same way. Usually you don't need to worry about obfuscating server side code because it isn't publicly visible.

Jay McDoniel
  • 57,339
  • 7
  • 135
  • 147
  • Yes that is what I thought but still it's a concern for me. Is there any other way around it? It doesn't have to be 100% obfuscating. – MasterOfPuppets Oct 09 '20 at 02:36
  • I don't know of any partial obfuscators. What's the reason for needing server side obfuscation? – Jay McDoniel Oct 09 '20 at 02:43
  • @JayMcDoniel What if you are deploying the application on-premise, your code resides on someone else's server? – Tanmay Dec 24 '20 at 15:02
  • @Tanmay it doesn't change my answer. Most of the time there isn't a need for code-obfuscation on the server side. – Jay McDoniel Dec 24 '20 at 16:15
1

Here's how I did it using javascript-obfuscator.

  1. npm i -D javascript-obfuscator
  2. Update tsconfig.json, set outDir to ./dist_raw
  3. Update package.json, set scripts.build to nest build && javascript-obfuscator dist_raw --output dist --target node
  4. Update .gitignore, add line /dist_raw
  5. npm run build

Simply change typescript complation output to ./dist_raw and run javascript-obfuscator to produce final ./dist folder.

Ukasyah
  • 31
  • 2