<?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: Venkatesh j</title>
    <description>The latest articles on DEV Community by Venkatesh j (@venkatesh_j6fe71a).</description>
    <link>https://dev.to/venkatesh_j6fe71a</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4126652%2Fbda0f26b-535e-4b54-8ac7-7ea91427f9b0.jpg</url>
      <title>DEV Community: Venkatesh j</title>
      <link>https://dev.to/venkatesh_j6fe71a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/venkatesh_j6fe71a"/>
    <language>en</language>
    <item>
      <title>What is Web Security? A Simple Guide for Developers</title>
      <dc:creator>Venkatesh j</dc:creator>
      <pubDate>Tue, 15 Sep 2026 17:46:58 +0000</pubDate>
      <link>https://dev.to/venkatesh_j6fe71a/what-is-web-security-a-simple-guide-for-developers-35ml</link>
      <guid>https://dev.to/venkatesh_j6fe71a/what-is-web-security-a-simple-guide-for-developers-35ml</guid>
      <description>&lt;p&gt;Imagine this familiar scenario:&lt;/p&gt;

&lt;p&gt;You just finished building your full-stack application. You built a sleek frontend in &lt;strong&gt;React&lt;/strong&gt;, developed a fast REST API in &lt;strong&gt;Node.js &amp;amp; Express&lt;/strong&gt;, connected it to &lt;strong&gt;MongoDB&lt;/strong&gt;, styled everything with CSS, and deployed it to the cloud.&lt;/p&gt;

&lt;p&gt;Everything works smoothly. Forms submit, buttons respond, and data loads quickly.&lt;/p&gt;

&lt;p&gt;Then, a senior developer sits down beside you and asks a few simple questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;"If I open the browser DevTools, can I see another user's authentication token?"&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"What happens if I bypass your React frontend and call your delete API directly from Postman?"&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"Can an employee change the employee ID in the URL and view their manager's salary slip?"&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"If someone posts a malicious comment containing &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags, will it execute inside other users' browsers?"&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"What happens if an automated script sends 100,000 login requests to your API in one minute?"&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions do not mean your code is broken. They mean your code is currently built only for &lt;strong&gt;the happy path&lt;/strong&gt; — when users behave honestly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web security is the art and engineering of protecting your application, your data, and your users when people do NOT behave honestly.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What Exactly Are We Protecting?
&lt;/h2&gt;

&lt;p&gt;When developers hear "security," they often think of mysterious black screens with green text. In reality, web security is very concrete. As full-stack developers, we are protecting specific assets:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User Accounts &amp;amp; Identity&lt;/strong&gt;: Ensuring users only access their own profiles and preventing account takeovers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Passwords&lt;/strong&gt;: Guaranteeing that even if a database is leaked, raw user passwords cannot be recovered.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication Tokens &amp;amp; Sessions&lt;/strong&gt;: Protecting the digital keys that keep users logged in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Personal &amp;amp; Sensitive Information (PII)&lt;/strong&gt;: Phone numbers, addresses, and sensitive records.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Endpoints&lt;/strong&gt;: Preventing unauthorized users or automated bots from abusing backend logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Database&lt;/strong&gt;: Preventing malicious actors from reading, modifying, or deleting records via injection attacks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Business &amp;amp; Financial Logic&lt;/strong&gt;: Ensuring users cannot alter prices during checkout or skip subscription paywalls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Infrastructure&lt;/strong&gt;: Keeping your server CPU, memory, and bandwidth available without being taken down by Denial of Service (DoS) attacks.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  How Does a Typical Web Application Work?
&lt;/h2&gt;

&lt;p&gt;To secure a web application, you must first visualize how data travels between the user and your database:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    autonumber
    actor User
    participant Browser as Browser (React)
    participant Network as HTTPS / Network
    participant API as Backend API (Express)
    participant Auth as Auth &amp;amp; Middleware
    participant DB as Database (MongoDB/SQL)

    User-&amp;gt;&amp;gt;Browser: Enters email &amp;amp; password
    Browser-&amp;gt;&amp;gt;Network: Sends HTTP POST /api/login
    Network-&amp;gt;&amp;gt;API: Encrypted request delivered
    API-&amp;gt;&amp;gt;Auth: Validates input &amp;amp; checks password hash
    Auth-&amp;gt;&amp;gt;DB: Query user record
    DB--&amp;gt;&amp;gt;Auth: User record returned
    Auth--&amp;gt;&amp;gt;API: Authentication verified
    API--&amp;gt;&amp;gt;Network: Sends response + Auth Token / Cookie
    Network--&amp;gt;&amp;gt;Browser: Response received &amp;amp; stored
    Browser--&amp;gt;&amp;gt;User: Redirects to Dashboard&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Security risks can emerge at &lt;strong&gt;every single step&lt;/strong&gt; of this chain:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;What Happens Here&lt;/th&gt;
&lt;th&gt;Potential Security Risk&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Frontend (React)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;UI rendering, user input collection&lt;/td&gt;
&lt;td&gt;Untrusted input, XSS, exposed API secrets in JS bundles&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Network (HTTP/S)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Data in transit over Wi-Fi and the internet&lt;/td&gt;
&lt;td&gt;Packet sniffing, man-in-the-middle (MitM) eavesdropping&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Backend API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Request handling, routing, business rules&lt;/td&gt;
&lt;td&gt;Unauthenticated routes, missing rate limits, IDOR&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Auth Middleware&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Verifying identity and access permissions&lt;/td&gt;
&lt;td&gt;Broken access controls, expired or forged tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Permanent data storage&lt;/td&gt;
&lt;td&gt;SQL / NoSQL injection, unencrypted sensitive fields&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The Golden Rule of Web Security:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Never trust the frontend.&lt;/strong&gt; The user's browser is completely under the user's control. Anyone can inspect network traffic, modify JavaScript, or send raw HTTP requests using curl or Postman. All real security checks must happen on the backend server.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Authentication: Checking WHO You Are
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Authentication?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt; is the process of verifying that someone is who they claim to be.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-World Analogy
&lt;/h3&gt;

&lt;p&gt;Imagine entering your college campus or your company's tech park. At the front entrance, the security guard asks for your &lt;strong&gt;College ID Card&lt;/strong&gt; or &lt;strong&gt;Employee Badge&lt;/strong&gt;. The guard checks your photo and name to confirm your identity.&lt;/p&gt;

&lt;p&gt;The guard is answering one question: &lt;em&gt;"Are you really who you say you are?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That is &lt;strong&gt;Authentication&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Login Actually Works Behind the Scenes
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The user enters their email and plaintext password into a React form.&lt;/li&gt;
&lt;li&gt;React sends an HTTPS &lt;code&gt;POST&lt;/code&gt; request to &lt;code&gt;/api/v1/auth/login&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The Node.js backend searches for the user by email in the database.&lt;/li&gt;
&lt;li&gt;The backend takes the incoming password, hashes it using a cryptographic library like &lt;code&gt;bcrypt&lt;/code&gt;, and compares the hash with the stored hash in the database.&lt;/li&gt;
&lt;li&gt;If the hashes match, the backend issues an authentication credential (like a Session Cookie or a JWT) and sends it back to the browser.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// server.js - Simple Express.js Authentication Example&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bcrypt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./models/User.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/v1/auth/login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// 1. Check if user exists&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid email or password&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// 2. Safely compare the plain password with the stored hash&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isMatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isMatch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid email or password&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// 3. Identity confirmed! Issue session or token&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Login successful&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_id&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notice:&lt;/em&gt; We never compare passwords with &lt;code&gt;if (password === user.password)&lt;/code&gt;. We never store raw passwords. We store and verify salted hashes.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Authorization: Checking WHAT You Can Do
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Authorization?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt; is the process of checking what permissions an authenticated user has.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-World Analogy
&lt;/h3&gt;

&lt;p&gt;Once the security guard at your office park lets you through the front gate with your badge (Authentication), you walk inside. &lt;/p&gt;

&lt;p&gt;Can you open the door to the &lt;strong&gt;Executive Boardroom&lt;/strong&gt; or the &lt;strong&gt;Server Room&lt;/strong&gt;? &lt;/p&gt;

&lt;p&gt;Your badge gets scanned again at those doors. If you are a junior software engineer, the door stays locked. Only system administrators and executives have clearance for those rooms.&lt;/p&gt;

&lt;p&gt;The door scanner is answering: &lt;em&gt;"Do you have permission to enter this room?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That is &lt;strong&gt;Authorization&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Developer Example: An Employee Portal
&lt;/h3&gt;

&lt;p&gt;Consider an employee management application with three roles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Employee&lt;/code&gt; (can view their own profile and payslip)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Manager&lt;/code&gt; (can approve leaves for their team)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Admin&lt;/code&gt; (can view all salaries, edit roles, and delete accounts)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A common mistake is checking only if a user is logged in, but forgetting to verify their role:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ⚠️ INSECURE: DO NOT USE IN PRODUCTION&lt;/span&gt;
&lt;span class="c1"&gt;// Any logged-in employee can change the ID in the URL to view anyone's salary!&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/v1/salaries/:employeeId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authenticateUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Salary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;employeeId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;employeeId&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the secure approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ✅ RECOMMENDED: Enforcing Authorization Rules&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/v1/salaries/:employeeId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;authenticateUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requestingUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requestedId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;employeeId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Rule: You can only view your own salary, unless you are an Admin&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isOwner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;requestingUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;requestedId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isAdmin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;requestingUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isOwner&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isAdmin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Access denied. Unauthorized request.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Salary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;employeeId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;requestedId&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;401 Unauthorized&lt;/strong&gt;: &lt;em&gt;"I don't know who you are (please log in)."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;403 Forbidden&lt;/strong&gt;: &lt;em&gt;"I know who you are, but you are not allowed to do this."&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Cookies: The Browser's Built-in Memory
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is a Cookie?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Cookie&lt;/strong&gt; is a small piece of text (usually less than 4KB) stored by the web browser. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why Do Browsers Use Cookies?
&lt;/h3&gt;

&lt;p&gt;The HTTP protocol is &lt;strong&gt;stateless&lt;/strong&gt;. This means when you click a button to view your cart, the server has no memory of the fact that you logged in five seconds ago. &lt;/p&gt;

&lt;p&gt;To solve this, after you log in, the server sends a cookie containing a unique Session ID. Every time your browser makes another request to that server, it &lt;strong&gt;automatically attaches that cookie&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Essential Security Flags for Cookies
&lt;/h3&gt;

&lt;p&gt;If you configure cookies carelessly, malicious JavaScript can steal them. Always use these three flags in production:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Express.js cookie configuration&lt;/span&gt;
&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sessionId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sessionToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Prevents JavaScript from reading the cookie&lt;/span&gt;
  &lt;span class="na"&gt;secure&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// Transmitted ONLY over encrypted HTTPS connections&lt;/span&gt;
  &lt;span class="na"&gt;sameSite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lax&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Protects against Cross-Site Request Forgery (CSRF)&lt;/span&gt;
  &lt;span class="na"&gt;maxAge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="c1"&gt;// 1 day in milliseconds&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;HttpOnly&lt;/code&gt;&lt;/strong&gt;: When enabled, &lt;code&gt;document.cookie&lt;/code&gt; in JavaScript cannot read this cookie. Even if an attacker injects malicious JavaScript into your page (XSS), they cannot easily extract your session cookie!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Secure&lt;/code&gt;&lt;/strong&gt;: The browser will never send this cookie over unencrypted plain HTTP. It requires HTTPS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SameSite&lt;/code&gt;&lt;/strong&gt;: Restricts whether cookies are sent along with requests originating from third-party websites (preventing CSRF attacks).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. JWT (JSON Web Tokens): Portable Digital Passes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is a JWT?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;JSON Web Token (JWT)&lt;/strong&gt; is a compact, URL-safe string formatted into three parts separated by dots (&lt;code&gt;.&lt;/code&gt;):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Header.Payload.Signature&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt;: Describes the signing algorithm (e.g., HMAC-SHA256).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payload&lt;/strong&gt;: Contains the data claims (e.g., &lt;code&gt;userId: "123"&lt;/code&gt;, &lt;code&gt;role: "developer"&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: A cryptographic hash created using your server's secret key. If anyone alters the payload, the signature becomes invalid.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Critical JWT Myth to Avoid
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;JWT is Signed, NOT Encrypted!&lt;/strong&gt; Anyone can take a JWT, paste it into jwt.io, and read everything inside the payload in plain text. &lt;strong&gt;Never store passwords, secrets, or sensitive personal data inside a JWT payload.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where should you store a JWT?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Storing JWTs in browser &lt;code&gt;localStorage&lt;/code&gt; leaves them exposed to theft via Cross-Site Scripting (XSS). In modern web applications, storing authentication tokens in &lt;strong&gt;&lt;code&gt;HttpOnly&lt;/code&gt;, &lt;code&gt;Secure&lt;/code&gt; cookies&lt;/strong&gt; is the recommended best practice.&lt;/p&gt;


&lt;h2&gt;
  
  
  5. HTTPS and TLS: The Encrypted Highway
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Why Does HTTPS Exist?
&lt;/h3&gt;

&lt;p&gt;When you send data over plain &lt;strong&gt;HTTP&lt;/strong&gt;, every packet travels across the internet in readable text. If you are sitting in a café, airport, or college canteen on public Wi-Fi, anyone running packet-inspection software on that network can read your emails, passwords, and form submissions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTP&lt;/strong&gt; is like sending a postcard through the postal service. Every postal worker and neighbor along the road can read your postcard.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTPS&lt;/strong&gt; is putting your letter inside a sealed titanium briefcase locked with an unbreakable key. Only you and the intended recipient have the keys to unlock it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Key Terms Clarified:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TLS (Transport Layer Security)&lt;/strong&gt;: The actual cryptographic protocol that encrypts network traffic. (SSL is the older, retired predecessor of TLS).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTPS&lt;/strong&gt;: Simply HTTP running over an encrypted TLS connection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL/TLS Certificate&lt;/strong&gt;: A digital identity passport issued by a recognized Certificate Authority (CA) proving that your domain really belongs to you.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  6. CORS: The Browser's Cross-Origin Traffic Police
&lt;/h2&gt;

&lt;p&gt;Have you ever seen this red error in your browser console?&lt;br&gt;&lt;br&gt;
&lt;code&gt;Access to fetch at 'http://api.myapp.com' from origin 'http://localhost:3000' has been blocked by CORS policy.&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is CORS Actually Doing?
&lt;/h3&gt;

&lt;p&gt;By default, browsers follow the &lt;strong&gt;Same-Origin Policy (SOP)&lt;/strong&gt;. A web page loaded from &lt;code&gt;website-a.com&lt;/code&gt; is forbidden from reading data from &lt;code&gt;website-b.com&lt;/code&gt;. This prevents a malicious site from secretly reading your bank balance in another tab.&lt;/p&gt;

&lt;p&gt;When your React app runs on &lt;code&gt;http://localhost:3000&lt;/code&gt; and requests data from your Node API on &lt;code&gt;http://localhost:5000&lt;/code&gt;, the origins are different (different ports).&lt;/p&gt;

&lt;p&gt;The browser intercepts this and asks your Node.js server: &lt;em&gt;"Is &lt;code&gt;http://localhost:3000&lt;/code&gt; allowed to read your data?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If your Node server includes the proper CORS header (&lt;code&gt;Access-Control-Allow-Origin: http://localhost:3000&lt;/code&gt;), the browser delivers the data to your React code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Express.js with the 'cors' package&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// ✅ RECOMMENDED: Only allow your specific frontend domain&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://myblogapp.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; CORS is NOT a firewall for your API! CORS is enforced strictly by web browsers. Attackers using Postman, Python, or curl bypass CORS completely. CORS does not replace proper Authentication and Authorization.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  7. Common Web Security Attacks (Quick Overview)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;XSS (Cross-Site Scripting)&lt;/strong&gt;: An attacker injects malicious JavaScript into your site (e.g., via a comment box), which runs in other users' browsers and steals session tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSRF (Cross-Site Request Forgery)&lt;/strong&gt;: A malicious site tricks an authenticated user's browser into performing unwanted actions on another site (like transferring funds).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SQL / NoSQL Injection&lt;/strong&gt;: An attacker enters malicious database queries into input fields to bypass login or dump tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IDOR (Insecure Direct Object Reference)&lt;/strong&gt;: Altering an ID in a request (e.g., &lt;code&gt;/api/orders/501&lt;/code&gt; to &lt;code&gt;/api/orders/502&lt;/code&gt;) to view another customer's private data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Brute Force &amp;amp; Credential Stuffing&lt;/strong&gt;: Automated bots testing millions of leaked passwords against your login API.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  8. Common Beginner Mistakes to Avoid
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Storing Passwords in Plaintext&lt;/strong&gt;: Storing unhashed passwords in your database is dangerous and irresponsible. Always use &lt;code&gt;bcrypt&lt;/code&gt; or &lt;code&gt;argon2&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trusting Frontend Validation Alone&lt;/strong&gt;: Disabling a submit button in React with &lt;code&gt;disabled={!isValid}&lt;/code&gt; is great for UX, but attackers can send requests directly to the endpoint. Always re-validate on the backend.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leaking Secrets in React Code&lt;/strong&gt;: Any environment variable prefixed with &lt;code&gt;REACT_APP_&lt;/code&gt; or &lt;code&gt;VITE_&lt;/code&gt; is bundled into public JavaScript. Keep database keys and payment private keys strictly in the backend &lt;code&gt;.env&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verifying Authentication but Omitting Authorization&lt;/strong&gt;: Confirming &lt;em&gt;who&lt;/em&gt; is logged in, but forgetting to verify &lt;em&gt;if they own the resource&lt;/em&gt; they are editing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storing Sensitive Tokens in &lt;code&gt;localStorage&lt;/code&gt;&lt;/strong&gt;: Tokens in &lt;code&gt;localStorage&lt;/code&gt; can be read by any JavaScript running on the page, leaving them vulnerable to XSS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Detailed Error Stack Traces in Production&lt;/strong&gt;: Returning raw database errors gives attackers valuable clues about your architecture.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Simple Developer Security Checklist
&lt;/h2&gt;

&lt;p&gt;Use this checklist when building your next full-stack project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] &lt;strong&gt;HTTPS Enforced&lt;/strong&gt;: All traffic is redirected to &lt;code&gt;https://&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Passwords Hashed&lt;/strong&gt;: Passwords are hashed with &lt;code&gt;bcrypt&lt;/code&gt; (salt rounds ≥ 10) or &lt;code&gt;argon2&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Input Validated on Backend&lt;/strong&gt;: Validated using libraries like Zod, Joi, or express-validator.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Cookies Hardened&lt;/strong&gt;: Session cookies use &lt;code&gt;HttpOnly&lt;/code&gt;, &lt;code&gt;Secure&lt;/code&gt;, and &lt;code&gt;SameSite&lt;/code&gt; flags.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Secrets Stored in Backend &lt;code&gt;.env&lt;/code&gt;&lt;/strong&gt;: Never commit secrets or &lt;code&gt;.env&lt;/code&gt; files to GitHub.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Authorization Checked&lt;/strong&gt;: Every protected endpoint verifies resource ownership and user roles.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Rate Limiting Added&lt;/strong&gt;: Sensitive endpoints (like &lt;code&gt;/login&lt;/code&gt; and &lt;code&gt;/forgot-password&lt;/code&gt;) have rate limits.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Security Headers Configured&lt;/strong&gt;: Added &lt;code&gt;helmet&lt;/code&gt; middleware in Express.&lt;/li&gt;
&lt;li&gt;[ ] &lt;strong&gt;Generic Error Messages&lt;/strong&gt;: Database errors are logged internally, not exposed to the user.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  10 Common Interview Questions &amp;amp; Answers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. What is the difference between Authentication and Authorization?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: Authentication verifies &lt;em&gt;who you are&lt;/em&gt; (e.g., verifying email and password). Authorization determines &lt;em&gt;what you are allowed to do&lt;/em&gt; (e.g., checking if a user has admin rights to delete a post).&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Why should passwords never be stored in plaintext?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: If the database is compromised or leaked, plaintext passwords immediately expose all users. Passwords must be hashed using a slow cryptographic algorithm like bcrypt with a salt to prevent rainbow table attacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. What does the &lt;code&gt;HttpOnly&lt;/code&gt; flag on a cookie do?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: It prevents client-side JavaScript from accessing the cookie via &lt;code&gt;document.cookie&lt;/code&gt;. This provides a critical defense against session hijacking via Cross-Site Scripting (XSS).&lt;/p&gt;

&lt;h3&gt;
  
  
  4. What does the &lt;code&gt;Secure&lt;/code&gt; flag on a cookie do?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: It ensures that the browser will only transmit the cookie over encrypted HTTPS connections, preventing it from being intercepted over unencrypted HTTP.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Is a JWT encrypted by default?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: No. A standard JWT is digitally signed, not encrypted. Anyone can decode and view the payload. Sensitive information should never be stored in a JWT payload.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Where is the most secure place to store a session token in a web app?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: In an &lt;code&gt;HttpOnly&lt;/code&gt;, &lt;code&gt;Secure&lt;/code&gt;, &lt;code&gt;SameSite&lt;/code&gt; cookie. This prevents client-side JavaScript access while protecting against unauthorized cross-site requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Does CORS protect my backend API from attackers using Postman or Python?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: No. CORS is a browser-only security feature. Tools like Postman, curl, and automated scripts bypass CORS entirely. APIs must rely on authentication, authorization, and rate limiting for protection.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. What is the difference between HTTP and HTTPS?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: HTTP transmits data in unencrypted plaintext, vulnerable to eavesdropping. HTTPS encrypts all communication using TLS (Transport Layer Security), ensuring confidentiality and integrity.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. What is Cross-Site Scripting (XSS)?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: An attack where malicious JavaScript is injected into a trusted website. When other users view the page, their browsers execute the script, which can steal cookies or session tokens.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. What is an IDOR vulnerability?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt;: Insecure Direct Object Reference occurs when an application exposes a direct database reference (like &lt;code&gt;/api/invoices/1042&lt;/code&gt;) without verifying whether the requesting user actually owns that invoice.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Web security is about defense-in-depth&lt;/strong&gt;: Never rely on a single layer of protection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never trust the client&lt;/strong&gt;: Always validate input, enforce authentication, and check authorization on the server.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication confirms identity; Authorization enforces permissions.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protect tokens&lt;/strong&gt;: Use &lt;code&gt;HttpOnly&lt;/code&gt;, &lt;code&gt;Secure&lt;/code&gt;, and &lt;code&gt;SameSite&lt;/code&gt; cookies whenever possible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTPS is non-negotiable&lt;/strong&gt;: Encrypt all traffic in transit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CORS is a browser mechanism&lt;/strong&gt;, not a substitute for backend authentication.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;👉 &lt;strong&gt;Read Part 2: &lt;a href="https://spiderworld.in/blog/authentication-vs-authorization/" rel="noopener noreferrer"&gt;Authentication vs Authorization — What's the Real Difference?&lt;/a&gt; exclusively on SPIDERWORLD!&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://spiderworld.in/blog/what-is-web-security/" rel="noopener noreferrer"&gt;SPIDERWORLD&lt;/a&gt;. Explore full guides, system design breakdowns, and technical talks on &lt;a href="https://spiderworld.in" rel="noopener noreferrer"&gt;spiderworld.in&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
