<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Harsh Kamoriya</title>
    <description>The latest articles on DEV Community by Harsh Kamoriya (@harshkamoriya).</description>
    <link>https://dev.to/harshkamoriya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3789392%2F429ea05d-aa1b-431d-b5c9-8e7de7e84ea5.jpeg</url>
      <title>DEV Community: Harsh Kamoriya</title>
      <link>https://dev.to/harshkamoriya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harshkamoriya"/>
    <language>en</language>
    <item>
      <title>How Javascript Works on browser ? complete guide</title>
      <dc:creator>Harsh Kamoriya</dc:creator>
      <pubDate>Wed, 25 Feb 2026 19:33:28 +0000</pubDate>
      <link>https://dev.to/harshkamoriya/how-javascript-works-on-browser-complete-guide-bfm</link>
      <guid>https://dev.to/harshkamoriya/how-javascript-works-on-browser-complete-guide-bfm</guid>
      <description>&lt;h3&gt;
  
  
  Hey champs in this article we will try to understand what is javascript , where it is used and why it is used , this article will focus on high overview of how javascript works behind the scenes it is the intro part of js where we will try to answer some questions .
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;chaliye shuru karte hai javascript ki kahani&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Javascript is a high-level , interpreted  , dynamically typed programming language which is mainly used to make web pages interactive and dynamic . &lt;/p&gt;

&lt;p&gt;It was originally created to run inside browsers but today it also runs on servers using environement like Node.js . So earlier it was a scripting language whose main task was to control browser but later on it became a fully programming language . &lt;/p&gt;

&lt;p&gt;It can run on client side as well as on the server side but for that it need a runtime enviornment .&lt;br&gt;
server : Node.js (V8 + libuv + c++ bindings)&lt;br&gt;
client : browser &lt;/p&gt;

&lt;p&gt;Now you will be wondering about what is a browser and what is V8 engine so let us discuss that .&lt;/p&gt;
&lt;h2&gt;
  
  
  Browser
&lt;/h2&gt;

&lt;p&gt;It is your google chrome and safari where you go and search stuff and connects to internet &lt;/p&gt;

&lt;p&gt;so what browser does is it contains a few things in it &lt;br&gt;
1) Rendering engine&lt;br&gt;
2) Javascript Engine(V8)&lt;br&gt;
3) Web APIs&lt;br&gt;
4)Event Loop&lt;br&gt;
5)Networking Layering &lt;/p&gt;

&lt;p&gt;each one has their own jobs and working .let us discuss them one by one ,so what happens when you visit a web page Now tell me what is a web page so basically &lt;/p&gt;

&lt;p&gt;A web page is made of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML → Structure&lt;/li&gt;
&lt;li&gt;CSS → Styling&lt;/li&gt;
&lt;li&gt;JavaScript → Behavior&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  📄 HTML
&lt;/h2&gt;

&lt;p&gt;HTML defines &lt;a href="http://structure.it" rel="noopener noreferrer"&gt;structure.&lt;/a&gt; It provides a structure or skeleton to your page .&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;br&gt;
&amp;lt;button&amp;gt;Click&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When browser loads HTML:&lt;/p&gt;

&lt;p&gt;👉 It creates a&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DOM (Document Object Model) tree&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  🎨 CSS
&lt;/h2&gt;

&lt;p&gt;CSS defines styling. It basically styles your web page it adds colours and styling to your pages .&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1 { color:red; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when browser downloads or load the css file it creates :&lt;/p&gt;

&lt;p&gt;👉 CSSOM (CSS Object Model)&lt;/p&gt;

&lt;h2&gt;
  
  
  🖥 Render Tree
&lt;/h2&gt;

&lt;p&gt;DOM + CSSOM combine to form:&lt;/p&gt;

&lt;p&gt;👉 Render Tree&lt;/p&gt;

&lt;p&gt;This is what gets displayed on the screen.&lt;/p&gt;

&lt;p&gt;So do you understand so basically our webpage is consisting of three things HTML , Css , js , all these files are loaded on the browser and then rendering engine of the browser create a render tree behind the scene and the web page is shown on the screen ,so rendering engine make render tree when js file loads it is forwarded to V8 engine where it gets executed .&lt;/p&gt;

&lt;p&gt;V8 engine : It is a javascript engine created by : Google&lt;br&gt;
used in:  browser (google) , server(node.js)&lt;/p&gt;

&lt;p&gt;What V8 does&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parses JS&lt;/li&gt;
&lt;li&gt;Converts to AST&lt;/li&gt;
&lt;li&gt;Generates bytecode (Ignition)&lt;/li&gt;
&lt;li&gt;Optimizes using TurboFan&lt;/li&gt;
&lt;li&gt;Executes machine code&lt;/li&gt;
&lt;li&gt;Performs garbage collection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;what ever is written in the js is file is analysed and executed by this V8 engine it does not change DOM , or UI the code inside js uses browser APIs to do that , now you will be wondering what are browser’s apis ,so browser provides a lot api’s which Js can use and server different puropses .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browser gives JavaScript extra capabilities.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🔹 DOM APIs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;document&lt;/li&gt;
&lt;li&gt;getElementById&lt;/li&gt;
&lt;li&gt;querySelector&lt;/li&gt;
&lt;li&gt;createElement&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔹 Web APIs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;setTimeout&lt;/li&gt;
&lt;li&gt;fetch&lt;/li&gt;
&lt;li&gt;WebSocket&lt;/li&gt;
&lt;li&gt;localStorage&lt;/li&gt;
&lt;li&gt;sessionStorage&lt;/li&gt;
&lt;li&gt;geolocation&lt;/li&gt;
&lt;li&gt;history&lt;/li&gt;
&lt;li&gt;navigator&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Important:&lt;/p&gt;

&lt;p&gt;👉 These APIs are provided by browser&lt;/p&gt;

&lt;p&gt;👉 NOT by V8&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;V8 engine’s code is written in C++&lt;/strong&gt; &lt;br&gt;
main task is to convert the js code into machine code .So till now we have understood what a browser is what is contains , what is webpage , what is rendering engine , what is v8 engine what are browser apis . Now we will move towards event loop &lt;/p&gt;

&lt;p&gt;To understand event  loop we have to understand how the code inside the javascript file executes .&lt;/p&gt;

&lt;h2&gt;
  
  
  How code is executed inside the js engine .
&lt;/h2&gt;

&lt;p&gt;In a script.js file some code is written inside that ,which contains some variables ,some functions  , dom manupulation, timeouts, promises  , as we know javascript is a single threaded language so every instruction inside that file is executed line by line ,what js engine does is it creates a global execution context a big container which is further divided into two sections :&lt;/p&gt;

&lt;p&gt;1) variable enviornment&lt;br&gt;
2)code enviornment&lt;/p&gt;

&lt;p&gt;In the variable envioenment all the variables and functions are declared as undefined .&lt;br&gt;
In code enviornment section the code begins to executed line by line as soon as it gets a value it is assigned immediately in the variabl enviornment.when a new function is invoked a new execution context is created which also has these two sections in it ,all these are pushed into the stack know as call stack and executed in the LIFO manner .&lt;/p&gt;

&lt;p&gt;now when a promise comes it goes inside microtask queue and when a timeout is called then it goes inside the callback queue .when the call stack is empty then first the promises or you can say that the microtask queue is resolved first and then callback queue get its turn that is being tracked by a Event loop .That means event loop whose task is to perform the code execution fast and asynchronous .&lt;/p&gt;

&lt;p&gt;so this is the overview of how  js code execution works inside the browser&lt;/p&gt;

&lt;h1&gt;
  
  
  Full Page Rendering Flow (Complete Picture)
&lt;/h1&gt;

&lt;p&gt;When you open a website:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;Browser downloads HTML.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;HTML → DOM tree created.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;CSS → CSSOM created.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;DOM + CSSOM → Render Tree.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Render Tree → Layout + Paint → Screen.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6
&lt;/h3&gt;

&lt;p&gt;If JS exists:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JS sent to V8&lt;/li&gt;
&lt;li&gt;V8 executes JS&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If JS modifies DOM:&lt;/p&gt;

&lt;p&gt;→ Browser updates DOM&lt;/p&gt;

&lt;p&gt;→ Reflow/Repaint happens&lt;/p&gt;

&lt;p&gt;→ Screen updates&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Browser =&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rendering Engine (DOM + CSSOM)&lt;/li&gt;
&lt;li&gt;JavaScript Engine (V8)&lt;/li&gt;
&lt;li&gt;Web APIs&lt;/li&gt;
&lt;li&gt;Event Loop&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;V8 =&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Executes JS only&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript =&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DOM =&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser structure representation of HTML&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Thank you .
&lt;/h2&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Complete Guide to Web Security: Prevent XSS, Clickjacking, and Sniffing Attacks in Node.js</title>
      <dc:creator>Harsh Kamoriya</dc:creator>
      <pubDate>Tue, 24 Feb 2026 12:29:22 +0000</pubDate>
      <link>https://dev.to/harshkamoriya/complete-guide-to-web-security-prevent-xss-clickjacking-and-sniffing-attacks-in-nodejs-o9b</link>
      <guid>https://dev.to/harshkamoriya/complete-guide-to-web-security-prevent-xss-clickjacking-and-sniffing-attacks-in-nodejs-o9b</guid>
      <description>&lt;p&gt;First tell me what do you mean by secure .It means the if some hacker tries to access our website he should not be able to do that . Means there are lot of ways through which your website can be attacked like &lt;/p&gt;

&lt;p&gt;→ XSS attack &lt;br&gt;
→ clickJacking&lt;br&gt;
→ sniffing &lt;/p&gt;

&lt;p&gt;So these are some kind of attacks to which a website should be capable of preventing other wise the user’s security will get hampered &lt;/p&gt;

&lt;p&gt;In this article we will study each and every type of attack completely and will be understanding the working of that particular attack.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is Xss ?&lt;/li&gt;
&lt;li&gt;How many type of Xss attacks are there ?&lt;/li&gt;
&lt;li&gt;Understanding how these attacks happen .&lt;/li&gt;
&lt;li&gt;What damage these attacks can cause ?&lt;/li&gt;
&lt;li&gt;How to protect our website from these attacks ? &lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  What is XSS ?
&lt;/h2&gt;

&lt;p&gt;Xss means cross site scripting &lt;/p&gt;

&lt;p&gt;This is a kind of attack where user takes benefit of the forms which are present in your website . In this attack user tries to inject html or javascript code into your codebase via vulnerable or unsecure parameters means via form submisstion , comments , reviews , and all . &lt;br&gt;
let us look into it carefully so basically there are two kind of parameter which the hacker can take advantage of &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) inside get request url&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine your website has a search page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/search?q=harsh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now attacker will inject some script in this url like&lt;/p&gt;

&lt;p&gt;Attacker sends victim this URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/search?q=&amp;lt;script&amp;gt;alert('XSS Attack')&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this script could be malicious and can do any thing like attaker can access your cookies or tokens &lt;/p&gt;

&lt;p&gt;2) inputs of forms (ex - login form  , signup form , comments input , etc.)&lt;/p&gt;

&lt;p&gt;&lt;a href="" class="article-body-image-wrapper"&gt;&lt;img alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Attacker type or inject some sort of malicious javascript code or html code which will be executed by the client browser and &lt;strong&gt;boom&lt;/strong&gt; you are hacked&lt;/p&gt;

&lt;p&gt;&lt;a href=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How many types of XSS are there ?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Reflected XSS attack :
&lt;/h3&gt;

&lt;p&gt;In this type of attack sends a malicious link to the user and when the user clicks on that link a new interface get open in from of it inside that ui it is asked to enter its details like login id and password and boom that  data is now gone to the attacker . &lt;br&gt;
How it happens because inside that url some js script is present when that link is put into the browser then browser executes that script which can do anything ,like stealing the tokens , user information ,phishing etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tar2usx9cjxcjuzhqvo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tar2usx9cjxcjuzhqvo.png" alt=" " width="660" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is called &lt;strong&gt;reflected&lt;/strong&gt; because:&lt;/p&gt;

&lt;p&gt;Script comes in request and immediately reflects back in response.&lt;/p&gt;
&lt;h2&gt;
  
  
  Attacker creates malicious link
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://yourwebsite.com/search?q=&amp;lt;script&amp;gt;alert('Hacked')&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Victim clicks link
&lt;/h2&gt;

&lt;p&gt;Server responds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h2&amp;gt;Results for&amp;lt;script&amp;gt;alert('Hacked')&amp;lt;/script&amp;gt;&amp;lt;/h2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Browser executes script.&lt;/p&gt;

&lt;h3&gt;
  
  
  This is generally used in:
&lt;/h3&gt;

&lt;p&gt;1) Phishing emails&lt;/p&gt;

&lt;p&gt;2)Whatsapp messages&lt;br&gt;
3)fake login links&lt;/p&gt;

&lt;h2&gt;
  
  
  Harms it can cause
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;steal cookies&lt;/li&gt;
&lt;li&gt;steal jwt tokens&lt;/li&gt;
&lt;li&gt;Fake login form injection&lt;/li&gt;
&lt;li&gt;redirect ot malicious website&lt;/li&gt;
&lt;li&gt;perform actions on behalf of user&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to protect our website from reflected Xss ?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Input validation (using Zod , joi)&lt;/li&gt;
&lt;li&gt;Sanitization (Sanitize html)&lt;/li&gt;
&lt;li&gt;Output Escaping &lt;/li&gt;
&lt;li&gt;Add security Headers in http request (use helmet)&lt;/li&gt;
&lt;li&gt;Use CSP Headers (content script policy)&lt;/li&gt;
&lt;li&gt;store JWT tokens in HTTP only cookies &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can study each of the method in another article this section is just theoretical part .&lt;/p&gt;

&lt;p&gt;Now let us move on towards next Xss attack which is stored XSS&lt;/p&gt;

&lt;h2&gt;
  
  
  Stored Xss Attack :
&lt;/h2&gt;

&lt;p&gt;In this type of attack attacker inject some js script inside the parameters of forms like comment , reviews and all those comments are going to be saved in the database so along with that the script also get saved in database when those comments loads on browser of some users the browser executes that script and boom  * you’re hacked again *&lt;/p&gt;

&lt;p&gt;now you understood meaning of stored &lt;/p&gt;

&lt;p&gt;you can think of it like youtube comments someone comment and injects a script in that comment it get stored in db and when it loads it will execute on every other user’s youtube all are hacked&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoypomb9al1jzlrdacyr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoypomb9al1jzlrdacyr.png" alt=" " width="660" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Harms it can cause:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Account takeover&lt;/li&gt;
&lt;li&gt;steal JWT tokens&lt;/li&gt;
&lt;li&gt;steal passwords&lt;/li&gt;
&lt;li&gt;perform actions as victim&lt;/li&gt;
&lt;li&gt;Attack Admin Panel&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to prevent this attack from happening ?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Input validation&lt;/li&gt;
&lt;li&gt;Input sanitization&lt;/li&gt;
&lt;li&gt;Output escaping&lt;/li&gt;
&lt;li&gt;Helmet security headers&lt;/li&gt;
&lt;li&gt;contenct security policy&lt;/li&gt;
&lt;li&gt;use HttpOnly cookies&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let us move towards the last Xss attack &lt;/p&gt;

&lt;h2&gt;
  
  
  DOM Xss attack
&lt;/h2&gt;

&lt;p&gt;In this type of xss attack what attacker does is it goes to the repo of the website which he wants to attack and then it insert some malicious program or code into their codebase and then send those files to user when user run those file magic happens he got hacked  . Although this type of attack easily predictable like no user would run any kind of file coming from any unknown source so it is not that much dangerous .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0iy73gqgwwz5sbs289r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0iy73gqgwwz5sbs289r.png" alt=" " width="290" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;one more thing why it is called dom xss because it uses dom properties to hack&lt;br&gt;
like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;innerHTML&lt;/li&gt;
&lt;li&gt;outerHTML&lt;/li&gt;
&lt;li&gt;document.write&lt;/li&gt;
&lt;li&gt;insertAjacentHTML&lt;/li&gt;
&lt;li&gt;eval &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Harms it can cause
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Steal JWT token (if token is stored in localstorage)&lt;/li&gt;
&lt;li&gt;Perform actions as user(transfer money , delete account , change password)&lt;/li&gt;
&lt;li&gt;Keylogging attack&lt;/li&gt;
&lt;li&gt;redirect user&lt;/li&gt;
&lt;li&gt;complete frontend control&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to prevent DOM XSS ?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Never use innerHtml (use textcontent)&lt;/li&gt;
&lt;li&gt;Never use dangerouslySetInnerHTML&lt;/li&gt;
&lt;li&gt;Sanitize data before inserting&lt;/li&gt;
&lt;li&gt;Use content security policy &lt;/li&gt;
&lt;li&gt;Never store JWT in localstorage (use http only cookies)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This was all about the Xss attacks now we will move towards other attacks like &lt;/p&gt;

&lt;h2&gt;
  
  
  ClickJacking
&lt;/h2&gt;

&lt;p&gt;Clickjacking (also called &lt;strong&gt;UI redressing attack&lt;/strong&gt;) is a technique where an attacker tricks a user into clicking something different from what they think they are clicking.&lt;/p&gt;

&lt;p&gt;In this type of attack attacker embeds a webpage of another website into its own website using iframe tag and that page is shown on the screen but it is not visible on the similar page it makes some attractive and greedy buttons which he placed on some other critical button (like pay , delete transaction and all) so when user clicks the greedy button it clicks the underneath button which make transaction or can delete the user account and all that stuff &lt;/p&gt;

&lt;h2&gt;
  
  
  How Clickjacking Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step-by-step:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Attacker creates a malicious website.&lt;/li&gt;
&lt;li&gt;That website loads your real website inside an invisible &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The attacker places a fake button on top of your real button.&lt;/li&gt;
&lt;li&gt;When the user clicks the fake button, they are actually clicking your real button underneath.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So the user performs an action on your website without knowing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4ixizp2go0vr9u12fxe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4ixizp2go0vr9u12fxe.png" alt=" " width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Real world example &lt;/p&gt;

&lt;p&gt;Imagine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your website: &lt;code&gt;bank.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You have a button: &lt;strong&gt;"Transfer Money"&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;User must click it to confirm transaction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Attacker:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates &lt;code&gt;free-gifts.com&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Loads &lt;code&gt;bank.com&lt;/code&gt; inside an invisible iframe&lt;/li&gt;
&lt;li&gt;Places a fake button: &lt;strong&gt;"Click here to win iPhone"&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;User clicks it&lt;/li&gt;
&lt;li&gt;Actually clicks "Transfer Money"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💥 Money transferred without user realizing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Harms it can cause
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Account setting changes&lt;/li&gt;
&lt;li&gt;password changes&lt;/li&gt;
&lt;li&gt;unauthorized access&lt;/li&gt;
&lt;li&gt;camera and microphone access&lt;/li&gt;
&lt;li&gt;social media autolikes and autoshares&lt;/li&gt;
&lt;li&gt;admin action execution&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to prevent ClickJacking
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Use X-frame-Options header (using helmet)&lt;/li&gt;
&lt;li&gt;Use Content script policy (CSP)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;we will discuss these parts of implementaion in some  other article&lt;/p&gt;

&lt;p&gt;Now we will move towards a new attack know as packet sniffing&lt;/p&gt;

&lt;h2&gt;
  
  
  Sniffing
&lt;/h2&gt;

&lt;p&gt;So here basically there are two types of sniffing &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Packet Sniffing &lt;/li&gt;
&lt;li&gt;MIME Sniffing &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Packet Sniffing Attack
&lt;/h2&gt;

&lt;p&gt;As we know what ever data we are sending from one place to another is travelling through internet and we are not sending the whole data together what we do is we divide it into small small packets these packets travels from source to destination now the doubt is how these packets get reassemble at destination so each packet has some sort of details like each packet has one sequence number which helps all the packets to get reassemble at the destination so in this way our data is trnasferred or received . &lt;br&gt;
Now the how attacks happen so the attacker can read or capture these data packets using some tools like webshark and all these packets can contain critical information like username , password and all which is now know to the hacker and now he can access your account means you are wasted (hacked)&lt;/p&gt;

&lt;p&gt;How it happens because your website is using HTTP instead of HTTPS which is sending data as plain text.&lt;br&gt;
for security we use HTTPs which encrypts and decrypts the data at source and destination . due to which attacker is not able to read the data on traverlling on internet.&lt;/p&gt;

&lt;p&gt;If you are sending just plain text anyone &lt;/p&gt;

&lt;p&gt;connected to the internet can read or see&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passwords&lt;/li&gt;
&lt;li&gt;JWT tokens&lt;/li&gt;
&lt;li&gt;Session cookies&lt;/li&gt;
&lt;li&gt;API responses&lt;/li&gt;
&lt;li&gt;Credit card data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faztuonpdzx7847z8wxfs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faztuonpdzx7847z8wxfs.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Damage Can It Cause?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Session hijacking&lt;/li&gt;
&lt;li&gt;Credential theft&lt;/li&gt;
&lt;li&gt;Identity theft&lt;/li&gt;
&lt;li&gt;Data leaks&lt;/li&gt;
&lt;li&gt;Financial fraud&lt;/li&gt;
&lt;li&gt;Admin takeover&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Especially dangerous if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cookies are not secure&lt;/li&gt;
&lt;li&gt;JWT sent over HTTP&lt;/li&gt;
&lt;li&gt;No TLS encryption&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to Prevent these attacks ?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Always use HTTPS ( use SSL/TLS)&lt;/li&gt;
&lt;li&gt;Use reverse proxy , AWS or GCP , Let’s encrypt certificate&lt;/li&gt;
&lt;li&gt;Enforce Https in Express&lt;/li&gt;
&lt;li&gt;Secure Cookies&lt;/li&gt;
&lt;li&gt;Use HSTs (Http strict Transport Security) &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;you can study each of the method of prevention seperately or we will discuss them later in some other article&lt;/p&gt;

&lt;p&gt;Now let’s move towards MIME sniffing attack&lt;/p&gt;

&lt;h2&gt;
  
  
  MIME Sniffing Attack
&lt;/h2&gt;

&lt;p&gt;In this type of attack basically when our server sends some response it also send some information header like content-type header which is usually text/plain but the response is not plain -text it could be image , html or even js but content-type is wrong so when this response is received by the browser it analyse the content-type header and the response as the content-type is not matching with the response it tries to detect the correct content-type of the response by analysing first few bites of the response and imagine what happens it interpretes it incorrectly due to which if attacker has injected some malicious code inside that response get executed by the browser quickly &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2i4s27mmmgbiang8r0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd2i4s27mmmgbiang8r0k.png" alt=" " width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Harms it can lead to
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;XSS Attack &lt;/li&gt;
&lt;li&gt;CSP bypass &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to prevent this MIME Sniffing ?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;use X-content-type-options :nosniff header &lt;/li&gt;
&lt;li&gt;Set Proper content-types&lt;/li&gt;
&lt;li&gt;Validate Uploads&lt;/li&gt;
&lt;li&gt;Use Content-Disposition :attachment&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope this article will help you in understanding the security concepts of a website . we will see its implementation guide in some other article .&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
