<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Arvind K on Medium]]></title>
        <description><![CDATA[Stories by Arvind K on Medium]]></description>
        <link>https://medium.com/@kb_arvind?source=rss-dc5e8eef8093------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*3fm5Nu8EFcZ8dVe6-S2NHg.jpeg</url>
            <title>Stories by Arvind K on Medium</title>
            <link>https://medium.com/@kb_arvind?source=rss-dc5e8eef8093------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:31:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kb_arvind/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Implementing Code Obfuscation for Node.js with Docker Containers]]></title>
            <link>https://medium.com/@kb_arvind/implementing-code-obfuscation-for-node-js-with-docker-containers-b869bea30674?source=rss-dc5e8eef8093------2</link>
            <guid isPermaLink="false">https://medium.com/p/b869bea30674</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[code-obfuscation]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[javascript-obfuscate]]></category>
            <dc:creator><![CDATA[Arvind K]]></dc:creator>
            <pubDate>Thu, 12 Jan 2023 15:35:10 GMT</pubDate>
            <atom:updated>2023-01-12T15:35:10.585Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing Code Obfuscation for Containerized Node.js application using js-obfuscator in Docker</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*bbowtj_ose37T9pBMrNzRQ.png" /><figcaption>Illustrations from official <a href="https://www.docker.com/blog/how-to-use-the-node-docker-official-image/">Docker</a> and js-obfuscator</figcaption></figure><blockquote>The below code seems to be straight forward and it’s evident that any one in the galaxy🌌 with basic programming knowledge can read and understand what it is</blockquote><pre>const hi = () =&gt; {<br>  console.log(&quot;Hello World!&quot;);<br>}<br>hi();</pre><p>Jeesh, my bad 🤦. That’s not the reason we are here right cause we know<strong> avaScript </strong>looks like that in a plain text format</p><p>Now let’s take a look at below code now</p><pre>function _0x94c5() {<br>    var _0x5c0cce = [&#39;log&#39;, &#39;Hello\x20World!&#39;];<br>    _0x94c5 = function() {<br>        return _0x5c0cce;<br>    };<br>    return _0x94c5();<br>}<br><br>function hi() {<br>    var _0x1606f4 = _0x1e1c;<br>    console[_0x1606f4(0x16b)](_0x1606f4(0x16c));<br>}<br><br>function _0x1e1c(_0x2af524, _0x49f6cd) {<br>    var _0x1527d0 = _0x94c5();<br>    return _0x1e1c = function(_0x1cf04f, _0x4a185d) {<br>        _0x1cf04f = _0x1cf04f - (-0x1bfd + 0x16e * -0x16 + 0x3cdc);<br>        var _0x20c6c7 = _0x1527d0[_0x1cf04f];<br>        return _0x20c6c7;<br>    }, _0x1e1c(_0x2af524, _0x49f6cd);<br>}<br>hi();</pre><p><em>Confused ?? Nah </em>don’t worry. This is same as above the initial one line program of printing “Hello World” in JavaScript.</p><h4>So What is really meant for the term named as Obfuscation?</h4><p>A simple program is being converted to such a form that it becomes difficult to understand the core logic of the code with naked eye and without expertise.</p><p><em>Not going to elaborate on the what is actually obfuscation and details/process of it as we have many articles and blogs written on the same topic and available for everyone across digital world. To know more on it read the below article before proceeding to get more/better understanding of basics of obfuscation and code obfuscations.</em></p><ul><li><a href="https://cybersecurity.asee.co/blog/what-is-code-obfuscation/">What is code obfuscation? - Cybersecurity ASEE</a></li><li><a href="https://www.freecodecamp.org/news/make-your-code-secure-with-obfuscation/">What is Code Obfuscation? How to Disguise Your Code to Make it More Secure</a></li><li><a href="https://en.wikipedia.org/wiki/Obfuscation_(software)">Obfuscation (software) - Wikipedia</a></li></ul><p>Lets node dive into our topic of the article.</p><p>Meanwhile lets get into on how to containerize an node.js application first.</p><h3>Containerizing Node.js App</h3><p>Find the below useful links to know more on how to containerize node.js applications in real world.</p><ul><li><a href="https://nodejs.org/en/docs/guides/nodejs-docker-webapp/">Dockerizing a Node.js web app | Node.js</a></li><li><a href="https://cloudnweb.dev/2019/10/crafting-multi-stage-builds-with-docker-in-node-js/">Crafting multi-stage builds with Docker in Node.js</a></li></ul><blockquote>All samples we focus on are for application build with node.js and typescript.</blockquote><p>Before starting the process of containerizing the Node.js/Typescript application with obfuscation we need to have the <a href="https://obfuscator.io/">Javascript-Obfuscator </a>package available as part of our project/solution.</p><p><a href="https://github.com/javascript-obfuscator/javascript-obfuscator">GitHub - javascript-obfuscator/javascript-obfuscator: A powerful obfuscator for JavaScript and Node.js</a></p><h4>Adding obfuscation build script to package.json</h4><pre>&quot;scripts&quot;: {<br>    &quot;build&quot;: &quot;node_modules/.bin/tsc&quot;,<br>    &quot;build-docker-obfuscator&quot;: &quot;node_modules/.bin/javascript-obfuscator ./build -o ./build_obf  --compact true --self-defending true --exclude node_modules&quot;<br>  }</pre><p>We can add these “build-secure” to npm script just to make sure things are set up for building one one script. But it is not mandatory as awe can run script every-time manually also.</p><p>To secure the code base in node.js application made out of typescript we can simple run</p><pre>npm run build &amp;&amp; npm run build-docker-obfuscator</pre><blockquote>This above bash will run the build scripts in node package manager and will create <strong>build_obf </strong>folder with obfuscated files respectively.</blockquote><h4>Adding obfuscation to docker build stage</h4><p>Now let’s find out way on how to add “<strong><em>JavaScript Obfuscator</em></strong>” package to docker build stage. Guess by now you have basic understanding on using docker multi-stage build steps in <em>Dockerfile. </em>Can refer to above useful links if not already.</p><pre>FROM node:13.12.0-alpine3.10 as build-obfuscator<br>WORKDIR /app<br># Copy the build files<br>COPY --from=builder /app ./build <br>COPY --from=builder /app/node_modules ./node_modules<br>COPY --from=builder /app/package.json .<br><br>RUN npm i javascript-obfuscator<br># Run the obfuscator for all build files<br>RUN /app/node_modules/.bin/javascript-obfuscator &#39;/app/build&#39; -o &#39;./build_obf&#39;  --compact true --self-defending true --exclude node_modules</pre><blockquote>In this above step we copy files <em>“</em>builder” stage of docker multi-stage and executing the JavaScript obfuscator on top of it with few settings such as <em>compact, select-defending,</em> etc., Also make sure we always <strong>exclude</strong> <strong><em>node_modules </em></strong>folder and any other folders not containing source codes from getting obfuscate or else assume your doomed.</blockquote><blockquote>Below block is release stage where obfuscated files alone are copied to release image and thus ignoring all other files of actual source code</blockquote><pre>#  this is release build of docker multi-stage<br>FROM node:13.12.0-alpine3.10 as release<br># author Metadata<br>LABEL description=&quot;Some Application Description&quot; version=0.0.1 maintainer=&quot;ak@ak.com&quot;<br>RUN addgroup -g 1001 -S appuser &amp;&amp; adduser -u 1001 -S appuser -G appuser<br>WORKDIR /app<br># Copy the build files and package json for compatibility<br># This copies from multi stage build-obfuscator step to here and not actual files<br>COPY --from=build-obfuscator /app/build_obf/ .<br>COPY --from=builder /app/package.json .<br>COPY --from=builder /app/node_modules ./node_modules<br># Assign a user to avoid docker defaulting to root user and this step is advisable for security reasons<br>RUN chown -R appuser:appuser /app<br>USER appuser<br>CMD [&quot;node&quot;, &quot;index.js&quot;]</pre><p>With the above step once docker image is build using “<em>docker build .</em>” command, the resultant docker image will contain obfuscated application code base making sure that its difficult for normal human to read even person decodes docker image and extracts the files inside the build stage of docker image using various tools and options available such as ‘<a href="https://docs.docker.com/engine/reference/commandline/exec/">docker exec</a>’, <a href="https://docs.docker.com/engine/reference/commandline/cp/">docker cp</a>’.</p><p>As discussed on all articles we would have came across during the course where JavaScript obfuscation is subject, the mechanism of obfuscation code has its own pros and cons such as it increases file size of overall final deliverables or docker image size but it can to be considered as <strong>negligible </strong>considering the pros it is giving us in return. Also keep the point that <em>keeping high level during the obfuscation also makes it difficult for compiler in executing the code.</em></p><p><a href="https://ourcodeworld.com/articles/read/1439/why-and-when-should-you-obfuscate-your-javascript-code">Why and when should you obfuscate your JavaScript code?</a></p><p>Hope was able to give you useful and basic tips on how to obfuscate JavaScript and build docker image out of it.</p><blockquote>Hope i was able to give worth for contributing your valuable time on this. Please feel free to correct if any typos, comment your thoughts or any suggestions and I am always happy to learn</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*9c1Kw0gG4O5XHDp3ywDpJg.gif" /></figure><blockquote>Learning is the only thing the mind never exhausts, never fears, and never regrets - Leonardo da Vinci</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b869bea30674" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>