<?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: kartavya</title>
    <description>The latest articles on DEV Community by kartavya (@kartavya_9c69f1c1352ec440).</description>
    <link>https://dev.to/kartavya_9c69f1c1352ec440</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%2F4232657%2Faae90b24-7e33-4ac0-a03d-c481c3bf201d.png</url>
      <title>DEV Community: kartavya</title>
      <link>https://dev.to/kartavya_9c69f1c1352ec440</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kartavya_9c69f1c1352ec440"/>
    <language>en</language>
    <item>
      <title>The Definitive Guide to Securing Production Web Applications in 2027</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Mon, 30 Nov 2026 15:20:36 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/the-definitive-guide-to-securing-production-web-applications-in-2027-1llg</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/the-definitive-guide-to-securing-production-web-applications-in-2027-1llg</guid>
      <description>&lt;p&gt;The complete engineering blueprint: Headers JWT authentication ORM security and CI/CD testing.&lt;/p&gt;

&lt;p&gt;Flagship technical guide for software architects developers and security practitioners.&lt;/p&gt;

&lt;p&gt;Modern web applications depend on APIs, cloud infrastructure, third-party packages, authentication systems, and automated deployment pipelines. Every integration introduces potential security risks. A single misconfigured header, poorly validated input, leaked credential, or outdated dependency can expose an otherwise well-designed application.&lt;/p&gt;

&lt;p&gt;Securing production web applications in 2027 requires more than adding a firewall or running a vulnerability scanner. Security must be integrated into application architecture, development workflows, deployment pipelines, and continuous monitoring.&lt;/p&gt;

&lt;p&gt;This guide covers five practical areas of production web application hardening, with code examples and terminal commands that developers can adapt to their own environments.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Harden HTTP Headers and Browser Security
&lt;/h2&gt;

&lt;p&gt;Security headers help browsers enforce protective rules when interacting with web applications. They reduce risks associated with clickjacking, content injection, insecure transport and unexpected browser behavior.&lt;/p&gt;

&lt;p&gt;A typical Express application can configure security headers using Helmet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Helmet:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install helmet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Vulnerable configuration:&lt;/strong&gt;&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&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="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&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="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;h1&amp;gt;Welcome&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&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;The application does not explicitly configure browser security policies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated configuration:&lt;/strong&gt;&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"express"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;helmet&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"helmet"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&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;helmet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;contentSecurityPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;directives&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;defaultSrc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"'self'"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;scriptSrc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"'self'"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;objectSrc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"'none'"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;baseUri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"'self'"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;frameAncestors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"'none'"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&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="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&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="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;h1&amp;gt;Welcome&amp;lt;/h1&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&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;The configuration establishes a restrictive Content Security Policy and other protections provided by Helmet.&lt;/p&gt;

&lt;p&gt;Additional production controls should include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTPS across all application routes.&lt;/li&gt;
&lt;li&gt;HSTS after confirming HTTPS is correctly deployed.&lt;/li&gt;
&lt;li&gt;Appropriate cookie attributes, including &lt;code&gt;Secure&lt;/code&gt;, &lt;code&gt;HttpOnly&lt;/code&gt; and &lt;code&gt;SameSite&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;CSP testing to prevent breaking legitimate resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Review the resulting headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sSI https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;example.com&lt;/code&gt; with a domain you own or are authorized to test.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Secure JWT Authentication and Session Management
&lt;/h2&gt;

&lt;p&gt;JSON Web Tokens (JWTs) are commonly used to authenticate API requests. Incorrect token validation can allow unauthorized access.&lt;/p&gt;

&lt;p&gt;A token should not be trusted merely because it contains a user ID or because its signature appears valid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable pattern:&lt;/strong&gt;&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;decoded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&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="n"&gt;decoded&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="n"&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;decoded&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&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;code&gt;decode()&lt;/code&gt; does not verify the token's cryptographic signature. The application must not use decoded claims as authenticated identity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated pattern:&lt;/strong&gt;&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"jsonwebtoken"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;authenticateToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&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="n"&gt;authHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;authHeader&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&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="n"&gt;token&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="n"&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="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="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Authentication required"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;JWT_PUBLIC_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;algorithms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"RS256"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;issuer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://auth.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;audience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"production-api"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&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="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="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Invalid or expired token"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&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;The example assumes an appropriately configured asymmetric key and a trusted issuer. Key rotation and identity verification must also be implemented.&lt;/p&gt;

&lt;p&gt;Production authentication should include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Short-lived access tokens.&lt;/li&gt;
&lt;li&gt;Secure refresh-token rotation.&lt;/li&gt;
&lt;li&gt;Server-side authorization checks for every protected resource.&lt;/li&gt;
&lt;li&gt;Protection against token leakage through logs, URLs and browser storage.&lt;/li&gt;
&lt;li&gt;Strong authentication and MFA for privileged accounts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Authentication confirms identity. Authorization determines what that identity can access. Both are essential.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Prevent Injection and ORM Security Vulnerabilities
&lt;/h2&gt;

&lt;p&gt;Injection vulnerabilities occur when untrusted input is interpreted as part of a query or executable instruction.&lt;/p&gt;

&lt;p&gt;Using an ORM does not automatically eliminate injection risks. Unsafe raw queries, dynamic SQL and improperly handled user input can still create vulnerabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable SQL query:&lt;/strong&gt;&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`SELECT * FROM users WHERE email = '${email}'`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&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;Concatenating user-controlled input into a query string can change the query's intended structure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated parameterized query:&lt;/strong&gt;&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s2"&gt;"SELECT * FROM users WHERE email = $1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;]&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;Parameters separate data from SQL instructions.&lt;/p&gt;

&lt;p&gt;When using an ORM, prefer safe query methods:&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&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="n"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUnique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;validatedEmail&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&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;Additional ORM security practices include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validate input using explicit schemas.&lt;/li&gt;
&lt;li&gt;Avoid unsafe raw-query APIs.&lt;/li&gt;
&lt;li&gt;Restrict database permissions.&lt;/li&gt;
&lt;li&gt;Never expose sensitive database fields in API responses.&lt;/li&gt;
&lt;li&gt;Apply authorization checks before accessing records.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Developers should also test object-level authorization, especially when APIs accept user IDs, document IDs, account IDs or other resource identifiers.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Secure Dependencies, Containers and Production Infrastructure
&lt;/h2&gt;

&lt;p&gt;Applications inherit risks from their dependencies, operating system packages, container images and infrastructure configuration.&lt;/p&gt;

&lt;p&gt;Dependency scanning should be part of development and deployment workflows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check npm dependencies:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm audit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check outdated packages:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm outdated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Build a Docker image:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build -t webapp:local .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Inspect the image:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image inspect webapp:local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check running containers:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands help developers review dependency vulnerabilities, package versions, image configuration and running container inventory.&lt;/p&gt;

&lt;p&gt;Production container hardening should include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use trusted and maintained base images.&lt;/li&gt;
&lt;li&gt;Pin dependency and image versions.&lt;/li&gt;
&lt;li&gt;Avoid running application processes as root.&lt;/li&gt;
&lt;li&gt;Remove unnecessary packages and utilities.&lt;/li&gt;
&lt;li&gt;Avoid storing secrets inside Docker images.&lt;/li&gt;
&lt;li&gt;Limit container capabilities and network access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For secret management, use a secure secret-management system or controlled environment injection rather than committing credentials to source code.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Integrate Security Testing into CI/CD
&lt;/h2&gt;

&lt;p&gt;Manual testing alone cannot keep pace with frequent deployments. Security testing should run alongside unit tests, code quality checks and build processes.&lt;/p&gt;

&lt;p&gt;A practical pipeline includes static analysis, dependency scanning, application testing and deployment validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run a Semgrep scan:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;semgrep scan --config auto .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check dependencies:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm audit --audit-level=high
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Run application tests:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check application response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sSI https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands are useful starting points for a security pipeline. CI runners should use pinned tool versions, controlled permissions and appropriately scoped credentials.&lt;/p&gt;

&lt;p&gt;A production security workflow should include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Static code analysis.&lt;/li&gt;
&lt;li&gt;Dependency vulnerability detection.&lt;/li&gt;
&lt;li&gt;Secrets detection.&lt;/li&gt;
&lt;li&gt;Automated security tests.&lt;/li&gt;
&lt;li&gt;Staging environment validation.&lt;/li&gt;
&lt;li&gt;Deployment monitoring and incident response.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Security findings should be prioritized according to exploitability, exposure, business impact and available remediation rather than severity labels alone.&lt;/p&gt;

&lt;p&gt;The objective is to make security a continuous engineering responsibility instead of a final deployment checkpoint.&lt;/p&gt;

&lt;p&gt;Production web application security is an ongoing process. Strong browser security policies, verified JWT authentication, safe database access, hardened infrastructure and continuous security testing create a practical foundation for resilient applications.&lt;/p&gt;

&lt;p&gt;Developers and security teams should regularly review their attack surface, test security controls and validate changes before deploying them to production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strengthen application security with continuous testing and practical security checks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=securing_web_2027" rel="noopener noreferrer"&gt;Download Complete Web Hardening Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore Hack My Website to assess authorized applications and identify opportunities to improve web security.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>devops</category>
      <category>security</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The Bug Hunter's Methodology for Passive Reconnaissance</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Fri, 27 Nov 2026 15:49:23 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/the-bug-hunters-methodology-for-passive-reconnaissance-41ko</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/the-bug-hunters-methodology-for-passive-reconnaissance-41ko</guid>
      <description>&lt;p&gt;Mapping attack surfaces using Certificate Transparency logs and passive DNS databases.&lt;/p&gt;

&lt;p&gt;Discovering unlinked subdomains and forgotten staging instances is one of the most valuable steps in security reconnaissance. Organizations often focus on their main production websites, while development environments, legacy services, temporary deployments, and forgotten subdomains remain outside routine visibility.&lt;/p&gt;

&lt;p&gt;Passive reconnaissance helps security researchers build a picture of an organization's external footprint without directly probing target systems. By using public datasets, DNS intelligence, certificate records, and historical archives, bug hunters can identify potential assets and organize them for authorized security testing.&lt;/p&gt;

&lt;p&gt;This guide walks through a practical passive reconnaissance methodology using publicly available data sources, command-line tools, and a structured asset review process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Passive Reconnaissance Matters
&lt;/h2&gt;

&lt;p&gt;Passive reconnaissance reduces unnecessary interaction with target infrastructure while helping researchers identify assets that may not appear in the organization's main website navigation.&lt;/p&gt;

&lt;p&gt;A forgotten staging environment, an old API hostname, or a subdomain associated with a previous deployment can reveal gaps in asset inventory. These findings are not automatically vulnerabilities; they are leads that require scope verification and responsible assessment.&lt;/p&gt;

&lt;p&gt;Common passive sources include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Certificate Transparency (CT) logs&lt;/li&gt;
&lt;li&gt;Passive DNS databases&lt;/li&gt;
&lt;li&gt;Search engine indexes&lt;/li&gt;
&lt;li&gt;Public code repositories&lt;/li&gt;
&lt;li&gt;Historical web archives&lt;/li&gt;
&lt;li&gt;Publicly available asset intelligence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The OWASP Web Security Testing Guide recommends attack surface identification as an information-gathering activity, including passive DNS and certificate transparency sources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discovering Unlinked Subdomains and Forgotten Staging Instances
&lt;/h2&gt;

&lt;p&gt;Certificate Transparency logs record publicly issued TLS certificates. When certificates contain subdomain names, those names can become useful clues for asset discovery.&lt;/p&gt;

&lt;p&gt;For example, a certificate may reveal names resembling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;staging.example.com&lt;/li&gt;
&lt;li&gt;dev.example.com&lt;/li&gt;
&lt;li&gt;api.example.com&lt;/li&gt;
&lt;li&gt;old-portal.example.com&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are illustrative names, not real discoveries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query CT records using crt.sh:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s &lt;span class="s2"&gt;"https://crt.sh/?q=%25.example.com&amp;amp;output=json"&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; jq -r &lt;span class="s1"&gt;'.[].name_value'&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; sort -u
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace example.com with an authorized domain. This query retrieves certificate-related names from the public crt.sh service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Subfinder for passive discovery:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subfinder -d example.com -silent -o subdomains.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Subfinder collects subdomain information from configured passive sources. Results depend on available sources and provider configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Amass in passive mode:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;amass enum -passive -d example.com -o amass.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output from different sources can be combined into an asset review list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat subdomains.txt amass.txt &lt;span class="o"&gt;|&lt;/span&gt; sort -u &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; combined-assets.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces a deduplicated list of candidate names for manual review. It does not confirm that the assets are active or in scope.&lt;/p&gt;

&lt;h2&gt;
  
  
  Historical URLs and Public Footprint Analysis
&lt;/h2&gt;

&lt;p&gt;Historical web archives can help identify paths that were once publicly accessible. Older URL records may reference retired documentation, previous application routes, legacy API paths, or forgotten pages.&lt;/p&gt;

&lt;p&gt;The gau tool can collect historical URLs from supported sources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collect historical URLs:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gau example.com &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; historical-urls.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Review the output for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retired application routes&lt;/li&gt;
&lt;li&gt;Old documentation pages&lt;/li&gt;
&lt;li&gt;Previously published API paths&lt;/li&gt;
&lt;li&gt;Legacy subdomains&lt;/li&gt;
&lt;li&gt;References to outdated application components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not treat historical URLs as current endpoints. Archived records may be outdated, incomplete, or associated with infrastructure that no longer belongs to the organization.&lt;/p&gt;

&lt;p&gt;The objective at this stage is to document and prioritize relevant findings, not to automatically test every archived path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vulnerable vs. Remediated Configuration Examples
&lt;/h2&gt;

&lt;p&gt;Passive reconnaissance may reveal a forgotten staging service or a publicly exposed development environment. Once an asset is confirmed to belong to an authorized assessment, configuration review can help determine whether exposure is intentional.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable configuration — example Docker Compose:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;staging&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"8080:80"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration publishes the service on the host's available interfaces by default, depending on the Docker networking configuration. If the host is publicly accessible, the service may be exposed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated configuration — local-only binding:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;staging&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"127.0.0.1:8080:80"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Binding to loopback limits direct access to the service through the host's external network interfaces. It is not a replacement for authentication, network controls, or secure deployment practices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable application configuration — debug enabled:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Example development configuration&lt;/span&gt;
&lt;span class="no"&gt;DEBUG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remediated application configuration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Production configuration&lt;/span&gt;
&lt;span class="no"&gt;DEBUG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Disabling debug output reduces the risk of exposing diagnostic information, internal paths, and application details. Configuration should be environment-specific and reviewed before deployment.&lt;/p&gt;

&lt;p&gt;These examples illustrate common configuration risks associated with forgotten development and staging assets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Organizing Findings and Building a Reconnaissance Workflow
&lt;/h2&gt;

&lt;p&gt;The value of reconnaissance comes from turning raw data into a clear asset inventory. Instead of maintaining an unstructured list, organize discoveries by source, confidence, ownership, and follow-up status.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Asset&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;th&gt;Confidence&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;staging.example.com&lt;/td&gt;
&lt;td&gt;CT logs&lt;/td&gt;
&lt;td&gt;Candidate&lt;/td&gt;
&lt;td&gt;Scope verification&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;api.example.com&lt;/td&gt;
&lt;td&gt;Passive DNS&lt;/td&gt;
&lt;td&gt;Candidate&lt;/td&gt;
&lt;td&gt;Asset review&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;old.example.com&lt;/td&gt;
&lt;td&gt;Historical archive&lt;/td&gt;
&lt;td&gt;Candidate&lt;/td&gt;
&lt;td&gt;Ownership review&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These records are illustrative only.&lt;/p&gt;

&lt;p&gt;A practical workflow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Define scope:&lt;/strong&gt; Confirm the authorized domain and assessment rules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collect:&lt;/strong&gt; Gather passive DNS, CT, and historical URL data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Normalize:&lt;/strong&gt; Remove duplicates and format results consistently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Categorize:&lt;/strong&gt; Group assets by production, development, staging, API, and legacy labels where evidence supports it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify:&lt;/strong&gt; Confirm ownership and authorization before active testing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Document:&lt;/strong&gt; Record sources, dates, evidence, and recommended remediation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A well-maintained asset inventory can help security teams reduce forgotten infrastructure and improve their visibility into the external attack surface.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Download Passive Recon Playbook:&lt;/strong&gt; &lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=passive_recon_guide" rel="noopener noreferrer"&gt;https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=passive_recon_guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore Hack My Website to improve security visibility, identify potential weaknesses, and strengthen your web application security workflow.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>infosec</category>
      <category>security</category>
    </item>
    <item>
      <title>Financial Logic Flaws in Modern E-Commerce Platforms</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Thu, 26 Nov 2026 18:19:36 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/financial-logic-flaws-in-modern-e-commerce-platforms-4n59</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/financial-logic-flaws-in-modern-e-commerce-platforms-4n59</guid>
      <description>&lt;p&gt;Dissecting rounding errors, coupon race conditions, and currency arbitrage. A checkout system can appear secure on the surface while hiding serious financial logic flaws inside its calculations, payment workflows, and inventory management. These issues often emerge not because of traditional injection vulnerabilities, but because the application trusts the wrong values, performs calculations inconsistently, or allows business operations to execute in an unexpected order.&lt;br&gt;
Securing checkout state machines and implementing strict atomic transactions are essential for protecting modern e-commerce platforms. Developers must treat prices, discounts, inventory, payment states, and currency conversions as security-critical operations rather than ordinary application logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding Financial Logic Flaws in Checkout Systems
&lt;/h2&gt;

&lt;p&gt;Financial logic flaws occur when an application implements business rules incorrectly or fails to enforce them consistently. Unlike traditional vulnerabilities, these weaknesses may exist in perfectly valid application code.&lt;br&gt;
Common examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Price manipulation caused by trusting client-submitted values.&lt;/li&gt;
&lt;li&gt;Incorrect rounding during discount or tax calculations.&lt;/li&gt;
&lt;li&gt;Coupon abuse caused by missing usage restrictions.&lt;/li&gt;
&lt;li&gt;Race conditions during inventory updates.&lt;/li&gt;
&lt;li&gt;Currency conversion inconsistencies.&lt;/li&gt;
&lt;li&gt;Payment workflow bypasses caused by missing state validation.
For example, a shopping cart may calculate the total price in the browser and submit it to the backend. If the server accepts that total without independently calculating the amount, the application is trusting an unverified value.
The core security principle is simple: &lt;strong&gt;the server must control financial calculations and enforce business rules at every critical transaction boundary.&lt;/strong&gt;
## 2. Price Calculation, Rounding Errors, and Currency Handling
Financial calculations should use predictable numeric representations. Floating-point arithmetic can produce unexpected results because many decimal values cannot be represented exactly in binary floating-point formats.
### Vulnerable calculation
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Python: floating-point calculation&lt;/span&gt;
&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;19.99&lt;/span&gt;
&lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example illustrates why floating-point arithmetic should not be the default representation for financial amounts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remediated calculation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;decimal&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;ROUND_HALF_UP&lt;/span&gt;
&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"19.99"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;quantize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&amp;nbsp;&lt;span class="nc"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"0.01"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&amp;nbsp;&lt;span class="n"&gt;rounding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;ROUND_HALF_UP&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;Decimal&lt;/code&gt; provides predictable decimal arithmetic when the application defines and applies appropriate rounding rules.&lt;br&gt;
Currency conversion should also follow a consistent policy. A platform should define the source of exchange rates, rate timestamps, rounding rules, supported currencies, and the point at which a conversion is finalized.&lt;br&gt;
Do not rely on the browser to calculate authoritative tax, discount, currency, or payment values. Recalculate these values on the server using validated inputs and trusted configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Coupon Validation and Checkout State Machines
&lt;/h2&gt;

&lt;p&gt;Coupons are business-rule objects, not merely strings submitted by a customer. A secure coupon system must validate eligibility, expiration, redemption limits, user restrictions, and stacking policies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vulnerable coupon logic
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Simplified example of weak coupon validation&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;apply_coupon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;discount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&amp;nbsp;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;discount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function accepts a discount amount without validating its eligibility, authorization, expiration, or limits.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remediated coupon logic
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;decimal&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Decimal&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;apply_coupon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;coupon&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&amp;nbsp;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;coupon&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"active"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&amp;nbsp;&lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Coupon inactive"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;coupon&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"minimum_order"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&amp;nbsp;&lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Minimum order not met"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;coupon&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"discount"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;coupon&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"maximum_discount"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&amp;nbsp;&lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Discount exceeds limit"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;discount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;coupon&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"discount"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;discount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simplified illustration. Production systems must also validate coupon ownership, usage counts, expiration, eligible products, and concurrent redemption.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enforce checkout states
&lt;/h3&gt;

&lt;p&gt;A checkout should follow a controlled state machine, for example:&lt;br&gt;
&lt;code&gt;cart → checkout → payment_pending → paid → fulfilled&lt;/code&gt;&lt;br&gt;
Transitions should only occur when the relevant server-side conditions have been satisfied. A client request should not be able to declare an order paid or fulfilled without the trusted payment and order-processing logic confirming the transition.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Race Conditions and Strict Atomic Transactions
&lt;/h2&gt;

&lt;p&gt;Race conditions occur when multiple operations interact with shared state and the system does not safely coordinate their execution. In checkout systems, this can affect inventory, coupon redemption, payment processing, and order creation.&lt;br&gt;
For instance, inventory may be available when two requests independently check stock. If both checks succeed before either request updates inventory, the application may oversell.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vulnerable database pattern
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;Illustrative&lt;/span&gt; &lt;span class="k"&gt;check&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;update&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;stock&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'item_1'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="n"&gt;separate&lt;/span&gt; &lt;span class="k"&gt;update&lt;/span&gt; &lt;span class="n"&gt;may&lt;/span&gt; &lt;span class="n"&gt;follow&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'item_1'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The separate check and update are not guaranteed to be atomic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remediated atomic update
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'item_1'&lt;/span&gt;
&amp;nbsp;&lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;The&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt; &lt;span class="n"&gt;must&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;exactly&lt;/span&gt;
 &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt; &lt;span class="n"&gt;was&lt;/span&gt; &lt;span class="n"&gt;affected&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="n"&gt;proceeding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application must roll back if the operation fails or no row is affected. Database transactions, conditional updates, locking where appropriate, and unique constraints help enforce the intended rules.&lt;br&gt;
For payment workflows, use idempotency keys, transaction records, and consistent reconciliation. A repeated request should not accidentally create duplicate charges or duplicate order processing.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Testing, CLI Verification, and Secure Deployment
&lt;/h2&gt;

&lt;p&gt;Security testing should validate both application behavior and infrastructure configuration. Use an isolated Docker lab or local application environment to verify the code and workflow changes before deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax-check Python examples
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python -m py_compile checkout.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This checks Python syntax without executing the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run unit tests
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python -m unittest discover -s tests -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This runs the discovered Python unit tests in the specified test directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspect application response headers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sI http://localhost:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command displays HTTP response headers for a local application. Replace the port with the actual lab port.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run a local Docker environment
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose up - build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use an isolated test environment with test credentials, test payment integrations, and synthetic data. Never use real customer transactions for security experiments.&lt;br&gt;
Testing should cover negative quantities, expired coupons, invalid discounts, currency rounding, duplicate requests, unavailable inventory, and invalid payment-state transitions. Unit tests and integration tests should verify that these conditions fail safely.&lt;br&gt;
A secure checkout system combines correct financial arithmetic, server-side validation, controlled state transitions, atomic database operations, and reliable testing. These controls help reduce financial abuse while maintaining a predictable purchasing experience.&lt;br&gt;
 - -&lt;br&gt;
&lt;strong&gt;Build safer checkout workflows with practical security testing and validation.&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=ecommerce_logic_flaws" rel="noopener noreferrer"&gt;Download E-Commerce Security Guide&lt;/a&gt;&lt;br&gt;
Explore application security testing with &lt;strong&gt;Hack My Website&lt;/strong&gt; and strengthen the security of web application workflows.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>cybersecurity</category>
      <category>security</category>
    </item>
    <item>
      <title>Distributed Rate Limiting at Scale with Redis and Lua Scripts</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Wed, 25 Nov 2026 12:59:35 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/distributed-rate-limiting-at-scale-with-redis-and-lua-scripts-3l61</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/distributed-rate-limiting-at-scale-with-redis-and-lua-scripts-3l61</guid>
      <description>&lt;p&gt;&lt;strong&gt;Building atomic sliding window rate limiters that survive distributed bot attacks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Implementing sliding-window log algorithms in high-throughput API gateways is an important part of protecting modern applications. APIs handle thousands of requests from browsers, mobile applications, integrations, and automated clients. Without proper rate limiting, excessive traffic can overload backend services, increase infrastructure costs, and expose sensitive endpoints to automated abuse.&lt;/p&gt;

&lt;p&gt;Traditional rate limiters often store request counters in application memory. This approach becomes unreliable when an application runs across multiple servers or containers. Redis provides a shared storage layer, while Lua scripts make rate-limit operations atomic, helping distributed systems enforce consistent request limits.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Why Distributed Applications Need Rate Limiting
&lt;/h2&gt;

&lt;p&gt;Consider an API deployed across three application servers. Each server has its own request counter and allows 100 requests per minute.&lt;/p&gt;

&lt;p&gt;A client distributing requests across all three servers could potentially generate more traffic than the intended limit because each server tracks requests independently.&lt;/p&gt;

&lt;p&gt;This creates several security and performance problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inconsistent request limits across application instances.&lt;/li&gt;
&lt;li&gt;Counter resets after application restarts.&lt;/li&gt;
&lt;li&gt;Race conditions during concurrent requests.&lt;/li&gt;
&lt;li&gt;Increased exposure to automated bot traffic.&lt;/li&gt;
&lt;li&gt;Unnecessary backend resource consumption.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A centralized Redis-based rate limiter solves the shared-counter problem. Every application instance checks the same Redis data, allowing the system to enforce consistent limits.&lt;/p&gt;

&lt;p&gt;Rate limiting is particularly useful for login endpoints, payment APIs, password-reset workflows, search services, and other resource-intensive operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Understanding the Sliding-Window Log Algorithm
&lt;/h2&gt;

&lt;p&gt;The sliding-window log algorithm tracks individual request timestamps within a rolling time period.&lt;/p&gt;

&lt;p&gt;For example, an API might allow 100 requests per minute. Whenever a new request arrives, the rate limiter removes expired timestamps, counts the remaining requests, and decides whether the new request should be accepted.&lt;/p&gt;

&lt;p&gt;Redis sorted sets provide a convenient way to implement this algorithm.&lt;/p&gt;

&lt;p&gt;Each request is stored with its timestamp as the sorted-set score. Redis then performs the following operations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove timestamps outside the active window.&lt;/li&gt;
&lt;li&gt;Count the remaining requests.&lt;/li&gt;
&lt;li&gt;Reject the request if the limit has been reached.&lt;/li&gt;
&lt;li&gt;Otherwise, record the new request.&lt;/li&gt;
&lt;li&gt;Set an expiration on the Redis key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Unlike fixed-window counters, sliding windows avoid arbitrary time-boundary resets. This provides more consistent request enforcement.&lt;/p&gt;

&lt;p&gt;The main trade-off is memory consumption. A sliding-window log stores individual request entries, so high-throughput systems should evaluate whether a sliding-window counter or token-bucket algorithm would be more efficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Implementing Atomic Rate Limiting with Redis and Lua
&lt;/h2&gt;

&lt;p&gt;A basic implementation might use separate Redis commands to check a counter and increment it.&lt;/p&gt;

&lt;p&gt;However, concurrent requests can execute these operations simultaneously. Multiple clients might read the same counter before any of them updates it, allowing more requests than intended.&lt;/p&gt;

&lt;p&gt;Lua scripting addresses this problem by executing the complete rate-limit decision as one atomic Redis operation.&lt;/p&gt;

&lt;p&gt;Create a file named &lt;code&gt;sliding_window.lua&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;tonumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;member&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ARGV&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;cutoff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt;

&lt;span class="c1"&gt;-- Remove expired requests&lt;/span&gt;
&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"ZREMRANGEBYSCORE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"-inf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;cutoff&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;-- Count active requests&lt;/span&gt;
&lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ZCARD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;-- Reject requests when the limit is reached&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;-- Record the accepted request&lt;/span&gt;
&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ZADD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;member&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;-- Automatically expire the Redis key&lt;/span&gt;
&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PEXPIRE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script returns &lt;code&gt;1&lt;/code&gt; when a request is accepted and &lt;code&gt;0&lt;/code&gt; when the limit is reached.&lt;/p&gt;

&lt;p&gt;Because Redis executes the Lua script atomically, another Redis command cannot interrupt the sequence between checking the request count and recording the accepted request.&lt;/p&gt;

&lt;p&gt;For production systems, request members must be unique, timestamps must use consistent units, and Redis Cluster key-slot restrictions must be considered.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Testing the Implementation with Docker and Redis CLI
&lt;/h2&gt;

&lt;p&gt;A local Docker environment makes it possible to reproduce and test the rate limiter without connecting to a production API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Start a Redis container.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run -d \
  --name redis-rate-limit-lab \
  -p 6379:6379 \
  redis:7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check whether Redis is responding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; redis-rate-limit-lab redis-cli PING
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PONG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Copy the Lua script into the container.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker cp sliding_window.lua \
  redis-rate-limit-lab:/tmp/sliding_window.lua
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Execute a rate-limit test.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The following Linux shell example allows five requests within a 60-second window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;seq 1 7&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;NOW&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%s%3N&lt;span class="o"&gt;)&lt;/span&gt;

  docker &lt;span class="nb"&gt;exec&lt;/span&gt; redis-rate-limit-lab redis-cli \
    --eval /tmp/sliding_window.lua rl:demo , \
    &lt;span class="s2"&gt;"$NOW"&lt;/span&gt; 60000 5 &lt;span class="s2"&gt;"request-$i"&lt;/span&gt;

&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected behavior, assuming all seven requests arrive within the same window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
1
1
1
1
0
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;1&lt;/code&gt; represents an accepted request and &lt;code&gt;0&lt;/code&gt; represents a rejected request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Inspect stored requests.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; redis-rate-limit-lab redis-cli \
  ZCARD rl:demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inspect the request timestamps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; redis-rate-limit-lab redis-cli \
  ZRANGE rl:demo 0 -1 WITHSCORES
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sorted set should contain five accepted requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Clean up the testing environment.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker rm -f redis-rate-limit-lab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands provide a basic functional reproduction. A separate concurrency test and performance benchmark are necessary before considering the implementation production-ready.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Production Security and Scalability Best Practices
&lt;/h2&gt;

&lt;p&gt;Redis-based rate limiting is useful, but deploying it at scale requires careful configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory management:&lt;/strong&gt; Sliding-window logs store individual request records. High-volume APIs may benefit from token-bucket or sliding-window counter implementations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trusted client identity:&lt;/strong&gt; Never blindly trust client-controlled &lt;code&gt;X-Forwarded-For&lt;/code&gt; headers. Configure known reverse proxies and use authenticated account or API-key identities wherever possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redis Cluster compatibility:&lt;/strong&gt; Scripts accessing multiple keys must respect Redis Cluster's key-slot requirements. Related keys can use hash tags to keep them in the same slot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure handling:&lt;/strong&gt; Decide whether the application should fail open or fail closed when Redis becomes unavailable. Sensitive authentication and payment endpoints may require stricter controls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTP response handling:&lt;/strong&gt; Return HTTP 429 Too Many Requests when a client exceeds its configured limit. A &lt;code&gt;Retry-After&lt;/code&gt; header can communicate when another request may be attempted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitoring:&lt;/strong&gt; Track rejected requests, Redis latency, memory consumption, error rates, and unusual traffic patterns. Monitor aggregate behavior instead of relying only on individual IP addresses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security testing:&lt;/strong&gt; Test concurrent requests, distributed traffic patterns, proxy misconfigurations, and rate-limit bypass scenarios in an authorized environment.&lt;/p&gt;

&lt;p&gt;A strong rate-limiting strategy combines shared counters, atomic operations, trusted identity extraction, and continuous monitoring. Redis and Lua provide a practical foundation for building these controls across distributed API infrastructure.&lt;/p&gt;




&lt;h3&gt;
  
  
  Secure APIs Before Traffic Becomes a Threat
&lt;/h3&gt;

&lt;p&gt;Distributed rate limiting helps maintain API availability, control automated abuse, and protect backend resources. Combining Redis-based enforcement with continuous application security testing creates a stronger foundation for modern web applications.&lt;/p&gt;

&lt;p&gt;Explore &lt;strong&gt;&lt;a href="https://hackmywebsite.io/" rel="noopener noreferrer"&gt;automated DAST scanner&lt;/a&gt;&lt;/strong&gt; solutions and &lt;strong&gt;&lt;a href="https://hackmywebsite.io/" rel="noopener noreferrer"&gt;website security testing&lt;/a&gt;&lt;/strong&gt; resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://hackmywebsite.io/" rel="noopener noreferrer"&gt;Hack My Website&lt;/a&gt;&lt;/strong&gt; helps developers focus on identifying vulnerabilities and strengthening application security before attackers exploit weaknesses.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>performance</category>
      <category>redis</category>
    </item>
    <item>
      <title>Automated Secret Scanning and Remediation Pipelines</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Tue, 24 Nov 2026 08:45:45 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/automated-secret-scanning-and-remediation-pipelines-291b</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/automated-secret-scanning-and-remediation-pipelines-291b</guid>
      <description>&lt;p&gt;Integrating TruffleHog, Gitleaks and GitHub Secret Scanning in GitHub Actions.&lt;br&gt;
Building automated revocation pipelines that invalidate leaked cloud keys immediately is an important step toward preventing credential abuse before it affects production systems.&lt;/p&gt;

&lt;p&gt;API keys, database passwords, cloud credentials and access tokens are often exposed accidentally during development. A developer might commit an &lt;code&gt;.env&lt;/code&gt; file, push a configuration containing an API key, or share credentials through a public repository.&lt;/p&gt;

&lt;p&gt;Once exposed, these credentials can be used to access sensitive systems, retrieve customer information or modify cloud infrastructure.&lt;/p&gt;

&lt;p&gt;Manual security reviews are not enough to catch every mistake. Automated secret scanning provides an additional security layer by identifying exposed credentials during development, pull requests and CI/CD execution.&lt;/p&gt;

&lt;p&gt;This guide explains how to combine TruffleHog, Gitleaks and GitHub Secret Scanning to build an automated detection and remediation pipeline.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Understanding Automated Secret Scanning
&lt;/h2&gt;

&lt;p&gt;Automated secret scanning searches source code, Git history, configuration files and repositories for sensitive information.&lt;/p&gt;

&lt;p&gt;Common examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS access keys and secret keys.&lt;/li&gt;
&lt;li&gt;GitHub personal access tokens.&lt;/li&gt;
&lt;li&gt;Database connection credentials.&lt;/li&gt;
&lt;li&gt;Private SSH keys.&lt;/li&gt;
&lt;li&gt;Payment gateway API keys.&lt;/li&gt;
&lt;li&gt;Cloud service authentication tokens.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three tools can provide complementary protection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TruffleHog:&lt;/strong&gt; Detects credentials in repositories and other data sources. It can also verify certain detected credentials against their providers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gitleaks:&lt;/strong&gt; Scans Git repositories and files for exposed secrets using configurable detection rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Secret Scanning:&lt;/strong&gt; Identifies supported credentials in repositories and can provide alerts and push protection, depending on repository eligibility and settings.&lt;/p&gt;

&lt;p&gt;Using multiple detection layers helps identify secrets that might be missed by a single scanner.&lt;/p&gt;

&lt;p&gt;Official references:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/trufflesecurity/trufflehog" rel="noopener noreferrer"&gt;https://github.com/trufflesecurity/trufflehog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/gitleaks/gitleaks" rel="noopener noreferrer"&gt;https://github.com/gitleaks/gitleaks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/code-security/secret-scanning" rel="noopener noreferrer"&gt;https://docs.github.com/en/code-security/secret-scanning&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  2. Reproducing a Secret Leak: Vulnerable vs Remediated Code
&lt;/h2&gt;

&lt;p&gt;Consider a Node.js application that connects to a cloud service.&lt;/p&gt;

&lt;p&gt;A common mistake is storing credentials directly inside application code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable example:&lt;/strong&gt;&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="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;AWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aws-sdk"&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="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;accessKeyId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"AKIAIOSFODNN7EXAMPLE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;secretAccessKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"EXAMPLE_SECRET_KEY"&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="n"&gt;s3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;S3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;credentials&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Cloud service initialized"&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;This approach creates several security problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Credentials become part of the source code.&lt;/li&gt;
&lt;li&gt;Git history can preserve previously committed secrets.&lt;/li&gt;
&lt;li&gt;Anyone with repository access may retrieve them.&lt;/li&gt;
&lt;li&gt;Removing the credentials from the latest version does not invalidate them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Remediated example:&lt;/strong&gt;&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="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;AWS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"aws-sdk"&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="n"&gt;s3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;AWS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;S3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;AWS_REGION&lt;/span&gt;
&lt;span class="p"&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;// Credentials are supplied through&lt;/span&gt;
&lt;span class="c1"&gt;// the AWS SDK credential provider chain.&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Cloud service initialized"&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;For production deployments, prefer IAM roles and temporary credentials instead of long-lived access keys.&lt;/p&gt;

&lt;p&gt;For local development, use a secure credential provider or environment configuration that is excluded from Git.&lt;/p&gt;

&lt;p&gt;Add the following to &lt;code&gt;.gitignore&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.env
.env.*
!.env.example

secrets/
*.pem
credentials.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An &lt;code&gt;.env.example&lt;/code&gt; file can contain variable names without real credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AWS_REGION=ap-south-1
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the required configuration clear without exposing sensitive values.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Implementing TruffleHog and Gitleaks in GitHub Actions
&lt;/h2&gt;

&lt;p&gt;The next step is integrating automated scanners into the development workflow.&lt;/p&gt;

&lt;p&gt;Start by installing the tools.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Gitleaks on macOS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew install gitleaks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check the installation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gitleaks version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Scan the current Git repository:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gitleaks git -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gitleaks can inspect Git history and identify potential credentials.&lt;/p&gt;

&lt;p&gt;For TruffleHog, the following Docker command provides a reproducible repository scan:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run --rm \
  -v &lt;span class="s2"&gt;"$(pwd):/repo"&lt;/span&gt; \
  trufflesecurity/trufflehog:latest \
  git file:///repo \
  --results=verified,unknown
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For repeatable production builds, pin the Docker image to a reviewed version or digest rather than relying on &lt;code&gt;latest&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now create a GitHub Actions workflow:&lt;/p&gt;

&lt;p&gt;File: &lt;code&gt;.github/workflows/secret-security.yml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Automated Secret Security&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;secret-scan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout repository&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v6&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;fetch-depth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run Gitleaks&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gitleaks/gitleaks-action@v3&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;GITHUB_TOKEN&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GITHUB_TOKEN }}&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run TruffleHog&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;trufflesecurity/trufflehog@main&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;extra_args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;--results=verified,unknown&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Gitleaks action checks repository changes, while TruffleHog provides another detection layer.&lt;/p&gt;

&lt;p&gt;For production, replace mutable action references with reviewed, full commit SHAs. Also review the TruffleHog action's permissions and pin its reference before deployment.&lt;/p&gt;

&lt;p&gt;GitHub's native Secret Scanning and Push Protection should also be enabled where available.&lt;/p&gt;

&lt;p&gt;Push protection can prevent supported secrets from being pushed in the first place.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Building Automated Cloud Credential Revocation Pipelines
&lt;/h2&gt;

&lt;p&gt;Detecting a leaked credential is only the first part of incident response.&lt;/p&gt;

&lt;p&gt;The next priority is preventing the exposed credential from being used.&lt;/p&gt;

&lt;p&gt;A remediation pipeline can connect secret detection alerts to a cloud security response service.&lt;/p&gt;

&lt;p&gt;A practical architecture looks like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developer commit → GitHub Actions → Secret scanner → Security alert → Incident handler → Credential revocation → Replacement credential → Verification.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For AWS, an IAM access key can be deactivated using the AWS CLI.&lt;/p&gt;

&lt;p&gt;First, identify the affected IAM user and access key through an authorized incident-response process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check the access key:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam list-access-keys \
  --user-name incident-test-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Immediately deactivate the exposed key:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam update-access-key \
  --user-name incident-test-user \
  --access-key-id AKIAEXAMPLE123456789 \
  --status Inactive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Verify its status:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam list-access-keys \
  --user-name incident-test-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected result is an access key with status &lt;code&gt;Inactive&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;These commands are intended for an authorized test IAM user. Never run them against production credentials without validating the affected identity and incident.&lt;/p&gt;

&lt;p&gt;An automated response service can perform these steps after receiving a verified security alert.&lt;/p&gt;

&lt;p&gt;A recommended remediation sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receive a secret-scanning alert.&lt;/li&gt;
&lt;li&gt;Identify the provider and credential type.&lt;/li&gt;
&lt;li&gt;Verify the alert and determine the affected identity.&lt;/li&gt;
&lt;li&gt;Deactivate or revoke the exposed credential.&lt;/li&gt;
&lt;li&gt;Generate a replacement credential or temporary identity.&lt;/li&gt;
&lt;li&gt;Update the relevant application configuration.&lt;/li&gt;
&lt;li&gt;Test application connectivity.&lt;/li&gt;
&lt;li&gt;Record the incident and close the alert after verification.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For automation, AWS EventBridge, Lambda and IAM APIs can be combined to handle the response.&lt;/p&gt;

&lt;p&gt;However, automatic revocation should use provider-specific handlers, identity allowlists, audit logging and safeguards against false positives. A detection result alone should not authorize an unrestricted production credential deletion.&lt;/p&gt;

&lt;p&gt;Also, deactivation does not remove the secret from Git history. Historical exposure must be addressed separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Testing, Monitoring and Continuous Security Improvement
&lt;/h2&gt;

&lt;p&gt;A security pipeline should be tested before it is trusted with production incidents.&lt;/p&gt;

&lt;p&gt;Create a temporary test repository and add a clearly fake credential:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir secret-scanning-lab
&lt;span class="nb"&gt;cd&lt;/span&gt; secret-scanning-lab

git init

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'API_KEY=FAKE_TEST_SECRET_123456789'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .env

git add .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run Gitleaks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gitleaks dir .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, test Git history scanning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config user.name &lt;span class="s2"&gt;"Security Tester"&lt;/span&gt;
git config user.email &lt;span class="s2"&gt;"security@example.test"&lt;/span&gt;

git commit -m &lt;span class="s2"&gt;"Add temporary test credential"&lt;/span&gt;

gitleaks git -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected outcome is that the scanner reports a matching finding when its detection rules recognize the test pattern.&lt;/p&gt;

&lt;p&gt;For TruffleHog, test with known-safe test fixtures and review its verified and unverified findings separately.&lt;/p&gt;

&lt;p&gt;A successful pipeline should demonstrate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Detection of known test credentials.&lt;/li&gt;
&lt;li&gt;Prevention of accidental commits or merges.&lt;/li&gt;
&lt;li&gt;GitHub Actions failure when a blocking finding is detected.&lt;/li&gt;
&lt;li&gt;Security alerts reaching the incident-response system.&lt;/li&gt;
&lt;li&gt;Credential deactivation in an isolated test account.&lt;/li&gt;
&lt;li&gt;Successful application recovery using replacement credentials.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Teams should also review scanner results regularly, reduce false positives through carefully maintained configuration and monitor secret-scanning alerts.&lt;/p&gt;

&lt;p&gt;GitHub provides REST API endpoints for retrieving and updating secret-scanning alerts, making it possible to integrate detection results with security operations.&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://docs.github.com/en/rest/secret-scanning/secret-scanning" rel="noopener noreferrer"&gt;https://docs.github.com/en/rest/secret-scanning/secret-scanning&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final takeaway:&lt;/strong&gt; Secret security should not depend on developers remembering every security rule. Combining pre-commit checks, repository scanning, CI/CD enforcement and automated credential revocation creates multiple layers of protection.&lt;/p&gt;

&lt;p&gt;Preventing a secret from entering Git is better than detecting it after publication. When exposure happens, immediate credential revocation and controlled recovery can significantly reduce the potential impact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Protect every commit before it reaches production.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explore Hack My Website:&lt;/strong&gt; &lt;a href="https://hackmywebsite.io" rel="noopener noreferrer"&gt;https://hackmywebsite.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download Secret Scanning Workflow:&lt;/strong&gt; &lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=secret_scanning_pipeline" rel="noopener noreferrer"&gt;https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=secret_scanning_pipeline&lt;/a&gt;&lt;/p&gt;

</description>
      <category>automation</category>
      <category>devops</category>
      <category>github</category>
      <category>security</category>
    </item>
    <item>
      <title>Deep Dive into AWS IMDSv2 Architecture and Exploitation</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Mon, 23 Nov 2026 16:34:21 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/deep-dive-into-aws-imdsv2-architecture-and-exploitation-1pk4</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/deep-dive-into-aws-imdsv2-architecture-and-exploitation-1pk4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Why session-oriented metadata requests prevent SSRF and how to enforce it at scale.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cloud infrastructure security is not just about protecting public endpoints. Some of the most sensitive information is available through internal services that applications use every day.&lt;/p&gt;

&lt;p&gt;One important example is the Amazon EC2 Instance Metadata Service (IMDS). It provides running EC2 instances with information about their environment, including instance identity and temporary IAM credentials.&lt;/p&gt;

&lt;p&gt;When an application contains a Server-Side Request Forgery (SSRF) vulnerability, attackers may attempt to use it to access internal metadata endpoints. If successful, this can expose sensitive information and potentially provide access to AWS resources.&lt;/p&gt;

&lt;p&gt;AWS introduced Instance Metadata Service Version 2 (IMDSv2) to make this attack path harder through session-oriented authentication, request validation, and additional network protections.&lt;/p&gt;

&lt;p&gt;This guide explores how IMDSv2 works, how SSRF can target metadata endpoints, and how to enforce secure configurations using AWS CLI, Terraform, and AWS Organizations Service Control Policies (SCPs).&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding AWS IMDS Architecture
&lt;/h2&gt;

&lt;p&gt;The Instance Metadata Service is an internal endpoint available to applications running on EC2 instances.&lt;/p&gt;

&lt;p&gt;The standard IPv4 endpoint is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://169.254.169.254/latest/meta-data/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Applications use this endpoint to retrieve information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instance ID and instance type.&lt;/li&gt;
&lt;li&gt;Availability zone and region.&lt;/li&gt;
&lt;li&gt;Network interface information.&lt;/li&gt;
&lt;li&gt;IAM role names and temporary credentials.&lt;/li&gt;
&lt;li&gt;Instance identity documents.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AWS supports two metadata service versions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IMDSv1:&lt;/strong&gt; Uses direct HTTP GET requests without requiring a session token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IMDSv2:&lt;/strong&gt; Requires a session token before metadata can be retrieved.&lt;/p&gt;

&lt;p&gt;The difference is important because an attacker exploiting an SSRF vulnerability may be able to trigger a simple HTTP request but may not be able to perform the additional operations required by IMDSv2.&lt;/p&gt;

&lt;p&gt;IMDSv2 introduces a two-stage authentication process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Send an HTTP PUT request to the token endpoint.&lt;/li&gt;
&lt;li&gt;Receive a temporary session token.&lt;/li&gt;
&lt;li&gt;Include that token in the HTTP header of subsequent GET requests.&lt;/li&gt;
&lt;li&gt;Retrieve metadata while the token remains valid.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The token can have a lifetime between one second and six hours.&lt;/p&gt;

&lt;p&gt;This session-oriented design provides an additional security layer against common SSRF techniques.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. How SSRF Exploitation Targets IMDS
&lt;/h2&gt;

&lt;p&gt;SSRF occurs when an application makes server-side HTTP requests to destinations controlled or influenced by user input.&lt;/p&gt;

&lt;p&gt;Consider an application that accepts a URL and fetches its contents without validating the destination.&lt;/p&gt;

&lt;p&gt;A vulnerable implementation might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/fetch"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&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="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is that the application does not restrict which destinations can be accessed.&lt;/p&gt;

&lt;p&gt;In an authorized security lab, an attacker could attempt to make the application request an internal metadata endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://169.254.169.254/latest/meta-data/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the instance permits IMDSv1 and the application can reach the endpoint, metadata may be exposed.&lt;/p&gt;

&lt;p&gt;Potential consequences include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exposure of instance information.&lt;/li&gt;
&lt;li&gt;Access to temporary IAM credentials.&lt;/li&gt;
&lt;li&gt;Unauthorized access to AWS resources, depending on the attached IAM permissions.&lt;/li&gt;
&lt;li&gt;Further compromise of cloud workloads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How IMDSv2 changes the attack path&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;IMDSv2 requires a PUT request to obtain a token before metadata requests can succeed.&lt;/p&gt;

&lt;p&gt;A simple SSRF vulnerability that only permits ordinary GET requests is therefore less likely to retrieve metadata.&lt;/p&gt;

&lt;p&gt;However, IMDSv2 does not eliminate SSRF. If an attacker can control both HTTP methods and headers, or abuse another internal service to obtain a token, additional attack paths may remain.&lt;/p&gt;

&lt;p&gt;IMDSv2 should therefore be combined with application-level SSRF protection, restricted IAM permissions, and network controls.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Reproducing IMDSv2 Requests Using AWS CLI and cURL
&lt;/h2&gt;

&lt;p&gt;The following commands demonstrate legitimate metadata access from an authorized EC2 instance.&lt;/p&gt;

&lt;p&gt;First, request an IMDSv2 session token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;curl -sS -X PUT \
  &lt;span class="s2"&gt;"http://169.254.169.254/latest/api/token"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"X-aws-ec2-metadata-token-ttl-seconds: 21600"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, use the token to retrieve the instance ID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sS \
  -H &lt;span class="s2"&gt;"X-aws-ec2-metadata-token: $TOKEN"&lt;/span&gt; \
  &lt;span class="s2"&gt;"http://169.254.169.254/latest/meta-data/instance-id"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Retrieve the instance type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sS \
  -H &lt;span class="s2"&gt;"X-aws-ec2-metadata-token: $TOKEN"&lt;/span&gt; \
  &lt;span class="s2"&gt;"http://169.254.169.254/latest/meta-data/instance-type"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check the current metadata configuration from an authorized administrative workstation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 describe-instances \
  --instance-ids i-xxxxxxxxxxxxxxxxx \
  --query &lt;span class="s1"&gt;'Reservations[].Instances[].MetadataOptions'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To require IMDSv2 on an existing instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 modify-instance-metadata-options \
  --instance-id i-xxxxxxxxxxxxxxxxx \
  --http-tokens required \
  --http-endpoint enabled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the example instance ID with an actual instance ID.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expected security behaviour:&lt;/strong&gt; When IMDSv2 is required, metadata requests without a valid token should fail.&lt;/p&gt;

&lt;p&gt;These commands follow AWS's documented command syntax. They have not been executed against a live AWS account as part of this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Enforcing IMDSv2 Through Terraform and Launch Templates
&lt;/h2&gt;

&lt;p&gt;Configuring individual instances manually is not a scalable security strategy.&lt;/p&gt;

&lt;p&gt;Infrastructure as Code (IaC) makes it possible to enforce security settings consistently across environments.&lt;/p&gt;

&lt;p&gt;A Terraform EC2 launch template can require IMDSv2 by configuring its metadata options.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Terraform launch template example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_launch_template"&lt;/span&gt; &lt;span class="s2"&gt;"secure_instance"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;name_prefix&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"secure-imdsv2-"&lt;/span&gt;
  &lt;span class="n"&gt;image_id&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ami_id&lt;/span&gt;
  &lt;span class="n"&gt;instance_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t3.micro"&lt;/span&gt;

  &lt;span class="n"&gt;metadata_options&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;http_endpoint&lt;/span&gt;               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"enabled"&lt;/span&gt;
    &lt;span class="n"&gt;http_tokens&lt;/span&gt;                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"required"&lt;/span&gt;
    &lt;span class="n"&gt;http_put_response_hop_limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;tag_specifications&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;resource_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"instance"&lt;/span&gt;

    &lt;span class="n"&gt;tags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;Name&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Secure-EC2"&lt;/span&gt;
      &lt;span class="nc"&gt;Environment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Production"&lt;/span&gt;
    &lt;span class="p"&gt;}&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;Important configuration settings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;http_endpoint = enabled&lt;/code&gt; keeps metadata access available.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;http_tokens = required&lt;/code&gt; disables IMDSv1 access.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;http_put_response_hop_limit = 2&lt;/code&gt; allows the token response to travel two network hops.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A hop limit of 2 is often appropriate for container workloads, but it should be evaluated against the actual network architecture. A smaller hop limit can provide additional isolation where compatible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validate the Terraform configuration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init

terraform fmt -check

terraform validate

terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Review the plan before applying it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Auto Scaling Groups, use the secure launch template as the instance configuration source.&lt;/p&gt;

&lt;p&gt;This ensures newly launched instances inherit the required metadata settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Enforcing IMDSv2 at Scale Using AWS SCPs and Remediation
&lt;/h2&gt;

&lt;p&gt;Terraform protects infrastructure managed through its configuration, but organizations also need controls against manual changes and alternative deployment methods.&lt;/p&gt;

&lt;p&gt;AWS Organizations Service Control Policies provide an additional governance layer.&lt;/p&gt;

&lt;p&gt;An SCP can deny EC2 launch and metadata modification operations when IMDSv2 is not required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example SCP policy:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"RequireIMDSv2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Deny"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s2"&gt;"ec2:RunInstances"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"ec2:ModifyInstanceMetadataOptions"&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"StringNotEquals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nl"&gt;"ec2:MetadataHttpTokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"required"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&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;This policy demonstrates the use of the &lt;code&gt;ec2:MetadataHttpTokens&lt;/code&gt; condition key to reject operations that do not require IMDSv2.&lt;/p&gt;

&lt;p&gt;Test the policy carefully in a non-production organizational unit before attaching it broadly. An SCP does not grant permissions, and it can block legitimate infrastructure changes if deployed without checking existing workloads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional enforcement through account-level defaults&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AWS also provides an account-level mechanism to require IMDSv2.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 modify-instance-metadata-defaults \
  --region us-east-1 \
  --http-tokens required \
  --http-tokens-enforced enabled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents new instances from launching with IMDSv1-enabled configurations in the specified Region.&lt;/p&gt;

&lt;p&gt;Verify the settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 get-instance-metadata-defaults \
  --region us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Account-level enforcement should be rolled out after identifying applications and agents that still depend on IMDSv1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final security checklist&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Require IMDSv2 on EC2 instances.&lt;/li&gt;
&lt;li&gt;[ ] Use secure Terraform launch templates.&lt;/li&gt;
&lt;li&gt;[ ] Enforce metadata requirements through SCPs or account-level controls.&lt;/li&gt;
&lt;li&gt;[ ] Restrict IAM instance-profile permissions.&lt;/li&gt;
&lt;li&gt;[ ] Validate user-controlled URLs in applications.&lt;/li&gt;
&lt;li&gt;[ ] Block unnecessary access to internal network destinations.&lt;/li&gt;
&lt;li&gt;[ ] Review metadata access logs and CloudWatch metrics.&lt;/li&gt;
&lt;li&gt;[ ] Test existing workloads before organization-wide enforcement.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;IMDSv2 adds an important layer of protection to AWS infrastructure by requiring session tokens for metadata requests.&lt;/p&gt;

&lt;p&gt;However, strong cloud security requires more than changing one EC2 setting. Application-level SSRF prevention, least-privilege IAM permissions, secure launch templates, and organization-wide policies must work together.&lt;/p&gt;

&lt;p&gt;By combining Terraform, AWS CLI, and Service Control Policies, engineering teams can make IMDSv2 enforcement part of their standard infrastructure deployment process rather than relying on manual configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secure the infrastructure before attackers find the gaps.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download IMDSv2 Terraform Template:&lt;/strong&gt; &lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=aws_imdsv2_guide" rel="noopener noreferrer"&gt;https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=aws_imdsv2_guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;References&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS EC2 – &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html" rel="noopener noreferrer"&gt;How IMDSv2 works&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;AWS – &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html" rel="noopener noreferrer"&gt;Configure instance metadata options&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;AWS Organizations – &lt;a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ec2_syntax.html" rel="noopener noreferrer"&gt;EC2 policy syntax&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;HashiCorp – &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template.html" rel="noopener noreferrer"&gt;Terraform AWS Launch Template&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>cloud</category>
      <category>infrastructure</category>
      <category>security</category>
    </item>
    <item>
      <title>Why Automated Security Scanners Miss Complex Business Logic Flaws</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Fri, 20 Nov 2026 15:40:00 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/why-automated-security-scanners-miss-complex-business-logic-flaws-8hi</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/why-automated-security-scanners-miss-complex-business-logic-flaws-8hi</guid>
      <description>&lt;p&gt;Analyzing the cognitive limitations of regex-based DAST and SAST scanning engines.&lt;/p&gt;

&lt;p&gt;Automated security scanners have become an important part of modern application security. They help developers identify SQL injection, cross-site scripting (XSS), exposed endpoints, insecure configurations, and other common vulnerabilities. However, even advanced scanning tools have limitations when it comes to understanding how an application is supposed to behave.&lt;/p&gt;

&lt;p&gt;A scanner might identify an insecure API response or a suspicious request parameter, but can it understand whether a customer has already received a discount? Can it determine whether a normal user is attempting to approve an administrator-only transaction?&lt;/p&gt;

&lt;p&gt;These situations require more than pattern matching. They require an understanding of application workflows, user permissions, transaction states, and business requirements.&lt;/p&gt;

&lt;p&gt;This explains why human context is irreplaceable when testing access control and business transactions. Automated tools are excellent at identifying technical weaknesses, but complex business logic flaws often require manual investigation.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding the Limitations of Automated Security Scanners
&lt;/h2&gt;

&lt;p&gt;Dynamic Application Security Testing (DAST) examines a running application by sending requests and analyzing responses. Static Application Security Testing (SAST) examines source code to identify potentially unsafe patterns.&lt;/p&gt;

&lt;p&gt;Both approaches provide valuable security coverage, but neither automatically understands every business rule.&lt;/p&gt;

&lt;p&gt;For example, consider an e-commerce application with a discount system. A scanner may successfully detect an exposed coupon API, but it may not understand that a particular coupon should only be available to first-time customers.&lt;/p&gt;

&lt;p&gt;Similarly, a SAST tool might identify an API endpoint that accepts a user ID without immediately recognizing that the endpoint allows one customer to access another customer's private information.&lt;/p&gt;

&lt;p&gt;Common limitations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Limited understanding of application-specific business rules.&lt;/li&gt;
&lt;li&gt;Difficulty identifying multi-step workflow manipulation.&lt;/li&gt;
&lt;li&gt;Incomplete understanding of user roles and permissions.&lt;/li&gt;
&lt;li&gt;Limited coverage of complex transaction sequences.&lt;/li&gt;
&lt;li&gt;Difficulty detecting abuse involving multiple legitimate requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Regex-based detection can identify known patterns, but business logic vulnerabilities frequently depend on relationships between otherwise valid operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. How Business Logic Vulnerabilities Occur
&lt;/h2&gt;

&lt;p&gt;Business logic vulnerabilities happen when an application allows users to perform actions that violate its intended rules.&lt;/p&gt;

&lt;p&gt;Consider a banking application where users can transfer money between accounts. The application may correctly validate the request format and authenticate the user. However, if it does not verify account ownership and transaction limits on the server, an attacker may manipulate the workflow.&lt;/p&gt;

&lt;p&gt;Some common examples include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Insecure Direct Object Reference (IDOR):&lt;/strong&gt; A user changes an object identifier to access another user's information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Broken Function-Level Authorization:&lt;/strong&gt; A regular user accesses an administrative function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Coupon Abuse:&lt;/strong&gt; A single-use discount is redeemed multiple times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Race Conditions:&lt;/strong&gt; Multiple simultaneous requests bypass transaction restrictions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Payment Manipulation:&lt;/strong&gt; The application trusts an amount supplied by the client instead of calculating it using trusted server-side records.&lt;/p&gt;

&lt;p&gt;These problems are closely related to OWASP categories such as Broken Access Control and Insecure Design.&lt;/p&gt;

&lt;p&gt;A particularly important example is API1:2023, Broken Object Level Authorization (BOLA), from the OWASP API Security Top 10.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Practical Demonstration: Vulnerable vs Remediated Code
&lt;/h2&gt;

&lt;p&gt;Consider a Node.js application that provides access to customer orders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable implementation:&lt;/strong&gt;&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="n"&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="s2"&gt;"/api/orders/:id"&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="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&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="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUnique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&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="n"&gt;order&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="n"&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;404&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Order not found"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&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="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&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;The problem is that the endpoint checks whether an order exists but does not verify whether the authenticated user owns it.&lt;/p&gt;

&lt;p&gt;An attacker could potentially change the order ID and access another customer's information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated implementation:&lt;/strong&gt;&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="n"&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="s2"&gt;"/api/orders/:id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;authenticate&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="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&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="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&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="n"&gt;order&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="n"&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;404&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Order not found"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&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="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&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;The updated implementation checks ownership using the authenticated user's identity.&lt;/p&gt;

&lt;p&gt;The important difference is that authorization is enforced by the server rather than relying on a user-provided identifier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing the endpoint with CLI:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"http://localhost:3000"&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"TEST_USER_TOKEN"&lt;/span&gt;

curl -i &lt;span class="s2"&gt;"$BASE_URL/api/orders/1001"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $TOKEN"&lt;/span&gt;

curl -i &lt;span class="s2"&gt;"$BASE_URL/api/orders/1002"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $TOKEN"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use two test orders belonging to different test accounts. The second request must not disclose another user's order.&lt;/p&gt;

&lt;p&gt;Expected secure behavior is a successful response for the user's own order and an appropriate 403 or 404 response for an order they do not own.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Why Manual Penetration Testing Still Matters
&lt;/h2&gt;

&lt;p&gt;Automated scanners can generate thousands of requests, but they do not necessarily understand the purpose of every application action.&lt;/p&gt;

&lt;p&gt;Manual penetration testing adds context to security testing.&lt;/p&gt;

&lt;p&gt;A penetration tester can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Study the application's intended user workflows.&lt;/li&gt;
&lt;li&gt;Identify differences between normal and privileged accounts.&lt;/li&gt;
&lt;li&gt;Test whether authorization is enforced at every endpoint.&lt;/li&gt;
&lt;li&gt;Examine whether transaction limits can be bypassed.&lt;/li&gt;
&lt;li&gt;Investigate how multiple requests interact.&lt;/li&gt;
&lt;li&gt;Verify whether business rules are enforced on the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, consider a checkout process with three stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an order.&lt;/li&gt;
&lt;li&gt;Complete payment.&lt;/li&gt;
&lt;li&gt;Confirm the order.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An application may protect each endpoint individually but fail to verify that payment was completed before order confirmation.&lt;/p&gt;

&lt;p&gt;A manual tester can examine the complete sequence and identify whether the application accepts an invalid transaction state.&lt;/p&gt;

&lt;p&gt;This is where human reasoning adds value. The tester understands what should happen, what actually happens, and where the two differ.&lt;/p&gt;

&lt;p&gt;Automated tools should support this process rather than replace it.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Building a Better Security Testing Strategy
&lt;/h2&gt;

&lt;p&gt;A reliable application security strategy combines automated scanning, manual testing, and secure development practices.&lt;/p&gt;

&lt;p&gt;The following practices can help reduce business logic risks:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Enforce authorization server-side.&lt;/strong&gt; Never trust client-supplied user IDs, roles, prices, or transaction statuses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Validate transaction states.&lt;/strong&gt; Ensure that payment, order confirmation, refunds, and account changes follow the correct sequence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Use atomic database operations.&lt;/strong&gt; Prevent race conditions through transactions, locking, and appropriate database constraints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Test with different user roles.&lt;/strong&gt; Verify access using regular users, administrators, and separate test accounts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Combine DAST and SAST with manual testing.&lt;/strong&gt; Automated scanners identify technical weaknesses, while manual investigation evaluates application-specific behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Retest after remediation.&lt;/strong&gt; A vulnerability should only be considered resolved after the corrected behavior has been verified.&lt;/p&gt;

&lt;p&gt;Security testing should also reference established standards, including OWASP Top 10, OWASP API Security Top 10, and the OWASP Web Security Testing Guide.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Automated security scanners are essential for identifying common vulnerabilities quickly and consistently. However, complex business logic flaws require an understanding of how an application works and what its users are allowed to do.&lt;/p&gt;

&lt;p&gt;A technically valid request can still represent an unauthorized business action.&lt;/p&gt;

&lt;p&gt;The strongest application security approach combines automated detection with manual penetration testing, proper authorization checks, and continuous verification.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Want to strengthen application security beyond automated scanning?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=logic_flaws_whitepaper" rel="noopener noreferrer"&gt;Read Business Logic Whitepaper&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore how Hack My Website approaches application security testing, vulnerability detection, and developer-focused remediation.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>security</category>
      <category>testing</category>
    </item>
    <item>
      <title>WordPress Security Internals: Hooks, Nonces and Filters</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Thu, 19 Nov 2026 14:05:35 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/wordpress-security-internals-hooks-nonces-and-filters-2ap8</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/wordpress-security-internals-hooks-nonces-and-filters-2ap8</guid>
      <description>&lt;p&gt;Understanding how WordPress core handles authentication and sanitization.&lt;/p&gt;

&lt;p&gt;WordPress powers millions of websites through its flexible themes, plugins and REST API. However, this flexibility also creates security challenges when developers write custom functionality without following secure coding practices.&lt;/p&gt;

&lt;p&gt;A small mistake in a plugin or theme can expose sensitive information, allow unauthorized actions or introduce vulnerabilities such as SQL Injection (SQLi) and Cross-Site Scripting (XSS).&lt;/p&gt;

&lt;p&gt;Understanding how WordPress core handles authentication and sanitization is essential for writing secure custom themes and plugins without introducing SQLi or XSS.&lt;/p&gt;

&lt;p&gt;This guide explores WordPress hooks, nonces, filters, database queries and practical security testing techniques that developers can apply to real projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding WordPress Hooks: Actions and Filters
&lt;/h2&gt;

&lt;p&gt;Hooks are one of the most important parts of WordPress architecture. They allow developers to interact with WordPress core without modifying its original files.&lt;/p&gt;

&lt;p&gt;WordPress provides two main types of hooks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Actions:&lt;/strong&gt; Execute custom functionality at specific points during WordPress execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filters:&lt;/strong&gt; Modify data before it is returned, displayed or processed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, an action can execute code when a plugin loads, while a filter can modify content before it appears on a website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Using an Action Hook&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;error_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Custom security plugin initialized.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&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;This executes when WordPress initializes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Using a Filter Hook&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'the_content'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$content&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="nv"&gt;$content&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;p&amp;gt;Security information updated.&amp;lt;/p&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&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;This modifies post content before it is displayed.&lt;/p&gt;

&lt;p&gt;Developers should remember that filters do not automatically make data safe. Output must still be escaped according to its context.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. WordPress Nonces and Authentication Security
&lt;/h2&gt;

&lt;p&gt;A nonce is a security token used by WordPress to help protect against Cross-Site Request Forgery (CSRF).&lt;/p&gt;

&lt;p&gt;It verifies that a request contains a valid token associated with a particular action and user context.&lt;/p&gt;

&lt;p&gt;However, a nonce is not a replacement for authentication or authorization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable approach:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'delete_item'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;wp_delete_post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'delete_item'&lt;/span&gt;&lt;span class="p"&gt;]&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="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;This code processes a deletion request without checking the user's capability or verifying a nonce.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated approach:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'delete_item'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nf"&gt;check_admin_referer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'delete_item_action'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nv"&gt;$post_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;absint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;wp_unslash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'delete_item'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&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="nf"&gt;current_user_can&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'delete_post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$post_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;wp_die&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Unauthorized request.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;wp_delete_post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$post_id&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="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;The improved implementation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verifies the request nonce.&lt;/li&gt;
&lt;li&gt;Converts the supplied post ID into an integer.&lt;/li&gt;
&lt;li&gt;Checks whether the current user can delete that particular post.&lt;/li&gt;
&lt;li&gt;Performs the operation only after security checks pass.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach reduces the risk of unauthorized deletion and CSRF attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Preventing SQL Injection and XSS in Custom Plugins
&lt;/h2&gt;

&lt;p&gt;SQL Injection happens when untrusted input is inserted into database queries without proper handling.&lt;/p&gt;

&lt;p&gt;Consider this vulnerable example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable SQL query:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SELECT * FROM {$wpdb-&amp;gt;users}
          WHERE ID = $user_id"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_results&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&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;Directly inserting request data into a SQL query can introduce SQL injection vulnerabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated SQL query:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;absint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;wp_unslash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"SELECT * FROM {$wpdb-&amp;gt;users}
     WHERE ID = %d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nv"&gt;$user_id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_results&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&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;Using &lt;code&gt;$wpdb-&amp;gt;prepare()&lt;/code&gt; ensures that the supplied value is handled as a parameter rather than being directly inserted into the SQL statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preventing Cross-Site Scripting (XSS)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;XSS occurs when untrusted data is displayed in a browser without appropriate output escaping.&lt;/p&gt;

&lt;p&gt;Vulnerable example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&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;Remediated example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;sanitize_text_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;wp_unslash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&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;WordPress provides different escaping functions for different contexts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;esc_html()&lt;/code&gt; – HTML text.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;esc_attr()&lt;/code&gt; – HTML attributes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;esc_url()&lt;/code&gt; – URLs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wp_kses_post()&lt;/code&gt; – Permitted post HTML.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sanitization and escaping serve different purposes. Sanitize incoming data according to its intended use and escape it when displaying it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Securing WordPress REST API Endpoints
&lt;/h2&gt;

&lt;p&gt;Custom REST API endpoints can expose sensitive functionality when authentication and authorization are not implemented correctly.&lt;/p&gt;

&lt;p&gt;WordPress allows developers to register custom routes using &lt;code&gt;register_rest_route()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable implementation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'rest_api_init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nf"&gt;register_rest_route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'custom/v1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'methods'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="s1"&gt;'callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&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="p"&gt;[&lt;/span&gt;
                &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_param&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&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;The endpoint does not define an explicit permission callback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated implementation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'rest_api_init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nf"&gt;register_rest_route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'secure/v1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;

        &lt;span class="s1"&gt;'methods'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="s1"&gt;'callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sanitize_text_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_param&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&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="nf"&gt;rest_ensure_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="s1"&gt;'success'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="s1"&gt;'permission_callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&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="nf"&gt;current_user_can&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'edit_posts'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="s1"&gt;'args'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="s1"&gt;'required'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'sanitize_callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sanitize_text_field'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'validate_callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&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="nf"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                        &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&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;The remediated version includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An explicit permission callback.&lt;/li&gt;
&lt;li&gt;Capability-based authorization.&lt;/li&gt;
&lt;li&gt;Input sanitization.&lt;/li&gt;
&lt;li&gt;Input validation.&lt;/li&gt;
&lt;li&gt;A structured REST API response.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For cookie-authenticated REST API requests, WordPress also supports the &lt;code&gt;X-WP-Nonce&lt;/code&gt; header using a nonce generated for the &lt;code&gt;wp_rest&lt;/code&gt; action.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Practical Security Testing Using CLI Tools
&lt;/h2&gt;

&lt;p&gt;Writing secure code is only one part of application security. Developers should also test their implementations before deploying them.&lt;/p&gt;

&lt;p&gt;The following commands can be used in an authorized local WordPress Docker lab.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check the WordPress REST API:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i http://localhost/wp-json/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Inspect the custom endpoint:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i -X POST \
  http://localhost/wp-json/secure/v1/profile \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"name":"Security Test"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An unauthenticated request should be rejected when the endpoint requires an authorized user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check installed WordPress plugins:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp plugin list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check WordPress core version:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp core version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Run WordPress coding standards checks:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require --dev \
  wp-coding-standards/wpcs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vendor/bin/phpcs \
  --standard=WordPress \
  wp-content/plugins/my-security-plugin/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Check PHP syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find wp-content/plugins/my-security-plugin \
  -name &lt;span class="s2"&gt;"*.php"&lt;/span&gt; -exec php -l &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; \&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands help identify coding-standard violations and PHP syntax errors. They do not independently prove that an application is secure.&lt;/p&gt;

&lt;p&gt;A useful security testing checklist includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check authorization on every sensitive endpoint.&lt;/li&gt;
&lt;li&gt;Verify nonce handling for state-changing browser requests.&lt;/li&gt;
&lt;li&gt;Use prepared SQL statements.&lt;/li&gt;
&lt;li&gt;Sanitize and validate incoming data.&lt;/li&gt;
&lt;li&gt;Escape output according to its context.&lt;/li&gt;
&lt;li&gt;Review plugin dependencies and known vulnerabilities.&lt;/li&gt;
&lt;li&gt;Test unauthorized and invalid requests in a controlled environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Get started with secure WordPress development:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Download Secure WordPress Plugin Boilerplate: &lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=wp_internals" rel="noopener noreferrer"&gt;https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=wp_internals&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hack My Website provides security-focused resources for developers working to identify and address web application vulnerabilities.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WordPress security depends on understanding how its internal components work together.&lt;/p&gt;

&lt;p&gt;Hooks provide flexibility, nonces help protect against CSRF, filters allow controlled data modification, and capability checks ensure that users can only perform authorized actions.&lt;/p&gt;

&lt;p&gt;Prepared database queries, proper input handling and context-aware output escaping help prevent common vulnerabilities such as SQL Injection and XSS.&lt;/p&gt;

&lt;p&gt;Building secure WordPress themes and plugins is not about adding security checks at the end. It is about making security part of the development process from the beginning.&lt;/p&gt;

</description>
      <category>php</category>
      <category>security</category>
      <category>wordpress</category>
    </item>
    <item>
      <title>XSS in the Modern Era: Bypassing CSP and DOMPurify Configurations</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Wed, 18 Nov 2026 13:42:28 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/xss-in-the-modern-era-bypassing-csp-and-dompurify-configurations-lbk</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/xss-in-the-modern-era-bypassing-csp-and-dompurify-configurations-lbk</guid>
      <description>&lt;p&gt;When outdated sanitizers and misconfigured CSP script hashes leave gaps, even modern web applications can become vulnerable to Cross-Site Scripting (XSS). Frameworks such as React, Vue, and Angular provide useful security protections, but they cannot automatically secure every interaction between user input, JavaScript, and the browser DOM.&lt;/p&gt;

&lt;p&gt;Modern applications frequently process dynamic content, API responses, URL parameters, and user-generated HTML. If these inputs reach unsafe DOM methods, attackers may find opportunities to execute unwanted scripts.&lt;/p&gt;

&lt;p&gt;This guide explores how DOM-based XSS develops, why Content Security Policy (CSP) and DOMPurify configurations sometimes fail, and how developers can strengthen application security using safer DOM APIs, Trusted Types, and practical testing methods.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding Modern XSS and DOM-Based Vulnerabilities
&lt;/h2&gt;

&lt;p&gt;Cross-Site Scripting occurs when an application allows untrusted input to execute as browser-side code.&lt;/p&gt;

&lt;p&gt;There are three common categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reflected XSS:&lt;/strong&gt; Malicious input is included in an immediate server response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stored XSS:&lt;/strong&gt; Untrusted content is saved and displayed to other users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DOM-based XSS:&lt;/strong&gt; Client-side JavaScript processes untrusted data and inserts it into an unsafe DOM location.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Single-page applications (SPAs) require particular attention because they frequently update page content without reloading the entire document.&lt;/p&gt;

&lt;p&gt;Consider this vulnerable JavaScript implementation:&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;search&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="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&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="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#output"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is the use of &lt;code&gt;innerHTML&lt;/code&gt;. It interprets the supplied value as HTML instead of displaying it as ordinary text.&lt;/p&gt;

&lt;p&gt;A safer implementation is:&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;search&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="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&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="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#output"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;textContent&lt;/code&gt; prevents the browser from interpreting the supplied value as HTML.&lt;/p&gt;

&lt;p&gt;The main lesson is that developers should identify every location where external data enters the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. How CSP Misconfigurations Create Security Gaps
&lt;/h2&gt;

&lt;p&gt;Content Security Policy is a browser security mechanism that controls which resources can execute or load on a website.&lt;/p&gt;

&lt;p&gt;A properly configured CSP can reduce the impact of XSS vulnerabilities by restricting unauthorized JavaScript execution.&lt;/p&gt;

&lt;p&gt;However, weak policies may create unnecessary opportunities for script injection.&lt;/p&gt;

&lt;p&gt;Common configuration problems include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allowing &lt;code&gt;unsafe-inline&lt;/code&gt; in script directives.&lt;/li&gt;
&lt;li&gt;Allowing &lt;code&gt;unsafe-eval&lt;/code&gt; without a clear requirement.&lt;/li&gt;
&lt;li&gt;Using broad script source allowlists.&lt;/li&gt;
&lt;li&gt;Reusing predictable CSP nonces.&lt;/li&gt;
&lt;li&gt;Forgetting to update script hashes after modifying inline scripts.&lt;/li&gt;
&lt;li&gt;Trusting third-party script loaders without reviewing their behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A stronger policy can use nonces and additional restrictions.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Security&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Policy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="s1"&gt;'self'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;script&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="s1"&gt;'self'&lt;/span&gt; &lt;span class="s1"&gt;'nonce-{RANDOM_NONCE}'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="s1"&gt;'none'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt; &lt;span class="s1"&gt;'none'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ancestors&lt;/span&gt; &lt;span class="s1"&gt;'self'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;require&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;trusted&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="s1"&gt;'script'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;trusted&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sanitizer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The nonce must be generated securely for each response and must match the nonce attached to authorized script elements.&lt;/p&gt;

&lt;p&gt;For static pages, hash-based CSP policies can be useful. However, hashes must match the exact inline script content. Any modification requires recalculating the corresponding hash.&lt;/p&gt;

&lt;p&gt;Developers should also understand that &lt;code&gt;strict-dynamic&lt;/code&gt; transfers trust from a nonce- or hash-authorized script to scripts dynamically loaded by that trusted script. This makes the behavior of trusted script loaders especially important.&lt;/p&gt;

&lt;p&gt;CSP is an additional security layer, not a replacement for fixing unsafe application code.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. DOMPurify Configurations and Advanced Payload Handling
&lt;/h2&gt;

&lt;p&gt;DOMPurify is a widely used HTML sanitization library. It removes unsafe HTML elements and attributes before content is inserted into the DOM.&lt;/p&gt;

&lt;p&gt;However, using a sanitizer does not automatically guarantee application security.&lt;/p&gt;

&lt;p&gt;Potential problems include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running outdated DOMPurify versions.&lt;/li&gt;
&lt;li&gt;Modifying sanitized HTML afterward.&lt;/li&gt;
&lt;li&gt;Using unsafe configuration options.&lt;/li&gt;
&lt;li&gt;Allowing unnecessary HTML elements or attributes.&lt;/li&gt;
&lt;li&gt;Processing content differently across application components.&lt;/li&gt;
&lt;li&gt;Trusting sanitized output without checking the destination context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Advanced XSS research also examines encoding differences, parser behavior, mutation-based XSS (mXSS), and script gadgets.&lt;/p&gt;

&lt;p&gt;A script gadget is an existing piece of trusted application code that can unintentionally turn attacker-controlled data into executable behavior.&lt;/p&gt;

&lt;p&gt;For example, an application may sanitize HTML correctly but later pass a value into an unsafe JavaScript function. This can undermine the original security protection.&lt;/p&gt;

&lt;p&gt;A basic DOMPurify implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install dompurify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;DOMPurify&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"dompurify"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;untrustedContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="s2"&gt;"&amp;lt;p&amp;gt;Welcome to the application&amp;lt;/p&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="n"&gt;sanitizedContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nc"&gt;DOMPurify&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;untrustedContent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#content"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="n"&gt;sanitizedContent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For applications that need to render HTML, sanitization should happen immediately before the content reaches the HTML sink.&lt;/p&gt;

&lt;p&gt;Avoid changing the sanitized output afterward.&lt;/p&gt;

&lt;p&gt;The security team should also review sanitizer versions and configuration whenever application dependencies change.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Trusted Types Enforcement and Secure Implementation
&lt;/h2&gt;

&lt;p&gt;Trusted Types provide an additional browser-level mechanism for controlling data passed into dangerous DOM injection points.&lt;/p&gt;

&lt;p&gt;Instead of allowing arbitrary strings to reach HTML sinks, applications can require values created through approved Trusted Types policies.&lt;/p&gt;

&lt;p&gt;This is particularly useful for large SPAs with multiple developers and shared UI components.&lt;/p&gt;

&lt;p&gt;Example implementation using DOMPurify:&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="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;DOMPurify&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"dompurify"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sanitizerPolicy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trustedTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createPolicy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"app-sanitizer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;createHTML&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;DOMPurify&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="no"&gt;RETURN_TRUSTED_TYPE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&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="n"&gt;untrustedContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="s2"&gt;"&amp;lt;p&amp;gt;Approved sample content&amp;lt;/p&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="n"&gt;safeHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="n"&gt;sanitizerPolicy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;untrustedContent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#content"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="n"&gt;safeHTML&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;RETURN_TRUSTED_TYPE: false&lt;/code&gt; option ensures DOMPurify returns a string to the Trusted Types policy, which then creates the TrustedHTML value.&lt;/p&gt;

&lt;p&gt;A matching CSP directive can enforce Trusted Types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Security&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Policy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;require&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;trusted&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="s1"&gt;'script'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;trusted&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sanitizer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This restricts direct assignment of ordinary strings to protected DOM injection sinks in supporting browsers.&lt;/p&gt;

&lt;p&gt;An important distinction: Trusted Types do not sanitize content by themselves. The security of the implementation depends on the transformation function used by the approved policy.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. CLI Testing, Remediation, and Security Checklist
&lt;/h2&gt;

&lt;p&gt;A controlled local environment is useful for identifying DOM-based XSS risks without testing against production users or third-party websites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a local project.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir modern-xss-lab
&lt;span class="nb"&gt;cd&lt;/span&gt; modern-xss-lab

npm init -y
npm install dompurify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Inspect installed dependencies.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm list dompurify
npm audit
npm audit --omit=dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands help identify installed versions and reported dependency vulnerabilities. Review the audit output before applying upgrades.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Check HTTP security headers.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sSI https://hackmywebsite.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Review the response for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Content-Security-Policy&lt;/li&gt;
&lt;li&gt;Strict-Transport-Security&lt;/li&gt;
&lt;li&gt;X-Content-Type-Options&lt;/li&gt;
&lt;li&gt;X-Frame-Options&lt;/li&gt;
&lt;li&gt;Referrer-Policy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Review unsafe JavaScript patterns.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grep -RInE \
&lt;span class="s1"&gt;'innerHTML|outerHTML|document.write|eval\('&lt;/span&gt; \
src/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a basic source-code search, not a complete security scanner. Each match requires manual review.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Validate the remediation.&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Security test&lt;/th&gt;
&lt;th&gt;Expected result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Plain text rendering&lt;/td&gt;
&lt;td&gt;Input displayed as text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HTML sanitization&lt;/td&gt;
&lt;td&gt;Disallowed elements removed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CSP validation&lt;/td&gt;
&lt;td&gt;Unauthorized scripts blocked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Trusted Types&lt;/td&gt;
&lt;td&gt;Untrusted strings rejected at protected sinks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dependency audit&lt;/td&gt;
&lt;td&gt;Known vulnerabilities reviewed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DOM review&lt;/td&gt;
&lt;td&gt;Unsafe injection paths remediated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For production applications, CSP should initially be monitored using &lt;code&gt;Content-Security-Policy-Report-Only&lt;/code&gt; before switching to enforcement. This helps identify legitimate application resources that may be affected by the new policy.&lt;/p&gt;

&lt;p&gt;The final security review should also include OWASP XSS Prevention guidance and a manual review of application-specific DOM manipulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modern XSS prevention requires more than installing a security library or adding a CSP header. It requires understanding how data travels through an application and identifying where that data reaches browser execution contexts.&lt;/p&gt;

&lt;p&gt;DOMPurify, strict CSP policies, safe DOM APIs, and Trusted Types work best as complementary defenses. Regular dependency updates and security testing help ensure that these protections remain effective as applications evolve.&lt;/p&gt;

&lt;p&gt;For developers building modern web applications, identifying and fixing these weaknesses early can significantly reduce application security risks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explore application security testing with Hack My Website:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=modern_xss_guide" rel="noopener noreferrer"&gt;Read Modern XSS Guide&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>frontend</category>
      <category>javascript</category>
      <category>security</category>
    </item>
    <item>
      <title>Zero-Day Dispatch: Stored XSS in Popular Open-Source CMS</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Wed, 18 Nov 2026 13:37:24 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/zero-day-dispatch-stored-xss-in-popular-open-source-cms-202c</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/zero-day-dispatch-stored-xss-in-popular-open-source-cms-202c</guid>
      <description>&lt;p&gt;How an Unescaped Comment Author Field Can Lead to Administrator Account Compromise&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Vulnerability overview
&lt;/h3&gt;

&lt;p&gt;Stored Cross-Site Scripting (XSS) occurs when an application saves untrusted user input and later displays it without proper output encoding or sanitization.&lt;/p&gt;

&lt;p&gt;Comment systems are particularly important to review because they accept content from users who may have limited privileges.&lt;/p&gt;

&lt;p&gt;A seemingly harmless comment author name, website URL, or profile field can become a security risk when the application inserts it directly into an HTML attribute.&lt;/p&gt;

&lt;p&gt;In a real-world example, CVE-2026-27469 affected the Isso commenting platform. Incomplete HTML escaping left quotation marks unescaped, allowing unsafe values to break out of their intended HTML attribute context.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Technical vulnerability trace
&lt;/h3&gt;

&lt;p&gt;The following trace illustrates the vulnerability pattern in a controlled example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 1: Input collection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A user submits a comment containing an author name and website URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 2: Database storage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The application stores the submitted values without applying the correct validation and output-handling rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 3: Unsafe rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The application builds an HTML link by concatenating stored values into an HTML attribute.&lt;/p&gt;

&lt;p&gt;Vulnerable illustrative 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;// Vulnerable rendering pattern&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;authorLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="s2"&gt;"&amp;lt;a href='"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;website&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"'&amp;gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
  &lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;author&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
  &lt;span class="s2"&gt;"&amp;lt;/a&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#comments"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insertAdjacentHTML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"beforeend"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;authorLink&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;strong&gt;Stage 4: Browser interpretation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The browser interprets the generated HTML. If untrusted data changes the intended HTML structure, unwanted script execution may become possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 5: Potential security impact&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the affected content is viewed by an administrator, the vulnerability may expose privileged application functionality to unauthorized actions.&lt;/p&gt;

&lt;p&gt;The actual impact depends on the application's permissions, session protections, available actions, and browser security controls.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Safe local reproduction
&lt;/h3&gt;

&lt;p&gt;Use an ordinary HTML marker to demonstrate the unsafe rendering behavior without executing JavaScript.&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Demo Author"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;website&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Controlled XSS test"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Unsafe HTML construction&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="sb"&gt;`&amp;lt;div class="comment"&amp;gt;
    &amp;lt;a href="${comment.website}"&amp;gt;
      ${comment.author}
    &amp;lt;/a&amp;gt;
    &amp;lt;p&amp;gt;${comment.message}&amp;lt;/p&amp;gt;
  &amp;lt;/div&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#comments"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The issue is not limited to one field. Every user-controlled value inserted into HTML needs context-appropriate handling.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Remediation payload
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Option A: Safe text rendering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When rich HTML is not required, use DOM APIs that treat input as text.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;renderComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comment&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="n"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"div"&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="n"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"span"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"p"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#comments"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;)&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;strong&gt;Option B: Validate website URLs&lt;/strong&gt;&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;validateWebsite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&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="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"http:"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;)&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="kc"&gt;null&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="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&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;strong&gt;Option C: Safe HTML sanitization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If rich HTML is necessary, use a maintained allowlist-based sanitizer such as DOMPurify.&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="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;DOMPurify&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"dompurify"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sanitizeComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;html&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="nc"&gt;DOMPurify&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sanitize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;USE_PROFILES&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;html&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="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&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;Apply sanitization immediately before inserting HTML into the DOM. Avoid modifying sanitized output afterward.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Security verification checklist
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Validate author names and website URLs.&lt;/li&gt;
&lt;li&gt;Escape output according to its HTML context.&lt;/li&gt;
&lt;li&gt;Avoid unsafe HTML string concatenation.&lt;/li&gt;
&lt;li&gt;Use DOMPurify for permitted rich HTML.&lt;/li&gt;
&lt;li&gt;Restrict comment editing and moderation permissions.&lt;/li&gt;
&lt;li&gt;Keep CMS dependencies updated.&lt;/li&gt;
&lt;li&gt;Implement CSP and Trusted Types as additional protections.&lt;/li&gt;
&lt;li&gt;Review administrator-facing pages for stored user content.&lt;/li&gt;
&lt;li&gt;Retest all comment creation and editing endpoints.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stored XSS can remain unnoticed because the malicious input may be saved long before it reaches the browser. Comment author fields, website links, and moderation interfaces should all be included in security reviews.&lt;/p&gt;

&lt;p&gt;The most reliable defense is to validate input, encode output correctly, avoid unsafe DOM operations, and enforce consistent security controls across every rendering path.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>opensource</category>
      <category>security</category>
    </item>
    <item>
      <title>Automated Subdomain Reconnaissance at Scale: Building an Asset Pipeline</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Tue, 17 Nov 2026 13:53:03 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/automated-subdomain-reconnaissance-at-scale-building-an-asset-pipeline-38he</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/automated-subdomain-reconnaissance-at-scale-building-an-asset-pipeline-38he</guid>
      <description>&lt;p&gt;Combining passive DNS sources, certificate transparency logs, and active bruteforcing creates a much clearer picture of an organization's external attack surface. A company may know about its main website and production API, but what about old staging environments, forgotten development servers, and subdomains created during previous projects?&lt;/p&gt;

&lt;p&gt;These assets can remain accessible long after the original teams stop maintaining them.&lt;/p&gt;

&lt;p&gt;Manual subdomain discovery is useful for small assessments, but it becomes difficult to maintain when an organization manages hundreds of domains. An automated asset pipeline helps security teams discover, validate, organize, and monitor these assets continuously.&lt;/p&gt;

&lt;p&gt;This guide explains how to combine OWASP Amass, Subfinder, and ShuffleDNS into a repeatable reconnaissance workflow using Linux CLI commands and scheduled cron jobs.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding the Subdomain Reconnaissance Pipeline
&lt;/h2&gt;

&lt;p&gt;Subdomain reconnaissance is the process of identifying subdomains associated with an authorized root domain.&lt;/p&gt;

&lt;p&gt;For example, an organization might have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.example.com" rel="noopener noreferrer"&gt;www.example.com&lt;/a&gt; – Main website&lt;/li&gt;
&lt;li&gt;api.example.com – Application API&lt;/li&gt;
&lt;li&gt;dev.example.com – Development environment&lt;/li&gt;
&lt;li&gt;staging.example.com – Testing environment&lt;/li&gt;
&lt;li&gt;admin.example.com – Administrative portal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not all these assets will appear in the company's documentation.&lt;/p&gt;

&lt;p&gt;A useful pipeline combines three discovery methods:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Passive reconnaissance:&lt;/strong&gt; Collects information from public sources without directly querying every discovered host. Sources include certificate transparency logs, passive DNS databases, and search engines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active DNS resolution:&lt;/strong&gt; Checks whether discovered domain names currently resolve through DNS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active bruteforcing:&lt;/strong&gt; Generates potential subdomain names using a wordlist and checks whether they resolve. This should only be performed against domains explicitly authorized for testing.&lt;/p&gt;

&lt;p&gt;No individual source provides a complete inventory. Combining multiple sources improves discovery coverage.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Setting Up Amass, Subfinder and ShuffleDNS
&lt;/h2&gt;

&lt;p&gt;Before building the pipeline, install the required tools on a Linux testing environment.&lt;/p&gt;

&lt;p&gt;Subfinder collects subdomains from passive sources, while OWASP Amass provides broader attack-surface discovery capabilities. ShuffleDNS uses MassDNS to resolve candidate names and perform wordlist-based discovery with wildcard handling.&lt;/p&gt;

&lt;p&gt;Install the tools:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go install github.com/projectdiscovery/subfinder/v2/cmd/subfinder@latest

go install github.com/projectdiscovery/shuffledns/cmd/shuffledns@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install OWASP Amass using its official installation instructions.&lt;/p&gt;

&lt;p&gt;Check that the tools are available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;amass -version
subfinder -version
shuffledns -version
massdns -h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ShuffleDNS requires MassDNS, a valid resolver list, and a wordlist for bruteforce operations.&lt;/p&gt;

&lt;p&gt;Create a working directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir -p ~/subdomain-pipeline/&lt;span class="o"&gt;{&lt;/span&gt;input,output,logs&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ~/subdomain-pipeline
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an authorized target file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"example.com"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; input/domains.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the example domain with an organization-owned domain or an explicitly authorized assessment target.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Combining Passive Discovery and Active DNS Enumeration
&lt;/h2&gt;

&lt;p&gt;The first stage collects information from different sources.&lt;/p&gt;

&lt;p&gt;Run Subfinder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subfinder \
  -d example.com \
  -all \
  -silent \
  -o output/subfinder.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-all&lt;/code&gt; option queries all supported passive sources, which may take longer than the default discovery mode.&lt;/p&gt;

&lt;p&gt;Next, run Amass in passive mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;amass enum \
  -passive \
  -d example.com \
  -o output/amass.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands collect potential subdomains without requiring active wordlist-based enumeration.&lt;/p&gt;

&lt;p&gt;Combine the results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat output/subfinder.txt output/amass.txt \
  &lt;span class="o"&gt;|&lt;/span&gt; sort -u \
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; output/passive-assets.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now validate the discovered names using ShuffleDNS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;shuffledns \
  -d example.com \
  -list output/passive-assets.txt \
  -r resolvers.txt \
  -mode resolve \
  -o output/resolved-assets.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resolver file should contain valid DNS resolver addresses.&lt;/p&gt;

&lt;p&gt;For additional discovery, use an approved wordlist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;shuffledns \
  -d example.com \
  -w wordlist.txt \
  -r resolvers.txt \
  -mode bruteforce \
  -sw \
  -o output/bruteforce-assets.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-sw&lt;/code&gt; option enables strict wildcard checking.&lt;/p&gt;

&lt;p&gt;Finally, combine both result sets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cat output/resolved-assets.txt \
    output/bruteforce-assets.txt \
    &lt;span class="o"&gt;|&lt;/span&gt; sort -u \
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; output/all-assets.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resulting file becomes the initial asset inventory.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Automating the Pipeline with Shell Scripts and Cron
&lt;/h2&gt;

&lt;p&gt;Running commands manually every day is inefficient. A scheduled pipeline makes asset discovery repeatable.&lt;/p&gt;

&lt;p&gt;Create a script named &lt;code&gt;run-pipeline.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -Eeuo pipefail

&lt;span class="nv"&gt;DOMAIN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"example.com"&lt;/span&gt;
&lt;span class="nv"&gt;BASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$HOME/subdomain-pipeline"&lt;/span&gt;
&lt;span class="nv"&gt;DATE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%F&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nv"&gt;OUT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$BASE/output/$DATE"&lt;/span&gt;
&lt;span class="nv"&gt;LOG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$BASE/logs"&lt;/span&gt;

mkdir -p &lt;span class="s2"&gt;"$OUT"&lt;/span&gt; &lt;span class="s2"&gt;"$LOG"&lt;/span&gt;

&lt;span class="c"&gt;# Passive discovery&lt;/span&gt;
subfinder -d &lt;span class="s2"&gt;"$DOMAIN"&lt;/span&gt; -all -silent \
  -o &lt;span class="s2"&gt;"$OUT/subfinder.txt"&lt;/span&gt;

amass enum -passive -d &lt;span class="s2"&gt;"$DOMAIN"&lt;/span&gt; \
  -o &lt;span class="s2"&gt;"$OUT/amass.txt"&lt;/span&gt;

&lt;span class="c"&gt;# Combine passive findings&lt;/span&gt;
cat &lt;span class="s2"&gt;"$OUT/subfinder.txt"&lt;/span&gt; &lt;span class="s2"&gt;"$OUT/amass.txt"&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; sort -u &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"$OUT/passive.txt"&lt;/span&gt;

&lt;span class="c"&gt;# Resolve discovered subdomains&lt;/span&gt;
shuffledns -d &lt;span class="s2"&gt;"$DOMAIN"&lt;/span&gt; \
  -list &lt;span class="s2"&gt;"$OUT/passive.txt"&lt;/span&gt; \
  -r &lt;span class="s2"&gt;"$BASE/resolvers.txt"&lt;/span&gt; \
  -mode resolve \
  -o &lt;span class="s2"&gt;"$OUT/resolved.txt"&lt;/span&gt;

&lt;span class="c"&gt;# Perform authorized wordlist discovery&lt;/span&gt;
shuffledns -d &lt;span class="s2"&gt;"$DOMAIN"&lt;/span&gt; \
  -w &lt;span class="s2"&gt;"$BASE/wordlist.txt"&lt;/span&gt; \
  -r &lt;span class="s2"&gt;"$BASE/resolvers.txt"&lt;/span&gt; \
  -mode bruteforce \
  -sw \
  -o &lt;span class="s2"&gt;"$OUT/bruteforce.txt"&lt;/span&gt;

&lt;span class="c"&gt;# Build final inventory&lt;/span&gt;
cat &lt;span class="s2"&gt;"$OUT/resolved.txt"&lt;/span&gt; &lt;span class="s2"&gt;"$OUT/bruteforce.txt"&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; sort -u &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"$OUT/all-assets.txt"&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Pipeline completed: $OUT"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make the script executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;chmod 700 run-pipeline.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script assumes that the required tools, resolver list, and wordlist are already installed and configured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable scheduling example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* * * * * bash ~/run-pipeline.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration runs every minute. It can create unnecessary DNS traffic, overlapping processes, and excessive log output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated scheduling example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 2 * * 1 /bin/bash /home/user/subdomain-pipeline/run-pipeline.sh &amp;gt;&amp;gt; /home/user/subdomain-pipeline/logs/cron.log 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This schedules the pipeline once every Monday at 2 AM.&lt;/p&gt;

&lt;p&gt;For production use, add a process lock, execution timeout, explicit target allowlist, and log rotation. Store API credentials securely rather than placing them directly in scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Validating Findings, Remediating Risks and Maintaining the Asset Inventory
&lt;/h2&gt;

&lt;p&gt;Discovery is only the first part of reconnaissance. Security teams must also determine which findings represent actual risks.&lt;/p&gt;

&lt;p&gt;Consider a development subdomain that still resolves to an outdated cloud service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vulnerable configuration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dev.example.com CNAME old-service.example-cloud.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the cloud resource has been deleted but the DNS record remains, the organization may have a dangling DNS reference.&lt;/p&gt;

&lt;p&gt;This does not automatically mean the resource can be claimed. The cloud provider, resource state, ownership, and verification requirements must be checked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated configuration:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Remove the obsolete CNAME record
# Or restore the intended service and verify ownership.

dev.example.com CNAME active-service.example-cloud.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The correct action depends on whether the service is still required.&lt;/p&gt;

&lt;p&gt;For every discovered asset, maintain an inventory containing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Subdomain name&lt;/li&gt;
&lt;li&gt;DNS record type&lt;/li&gt;
&lt;li&gt;Resolved IP or CNAME&lt;/li&gt;
&lt;li&gt;Discovery source&lt;/li&gt;
&lt;li&gt;First-seen and last-seen dates&lt;/li&gt;
&lt;li&gt;Business owner&lt;/li&gt;
&lt;li&gt;Environment classification&lt;/li&gt;
&lt;li&gt;Verification status&lt;/li&gt;
&lt;li&gt;Remediation status&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compare new results with previous scans to identify newly discovered assets, removed records, and unexpected DNS changes.&lt;/p&gt;

&lt;p&gt;A simple comparison can identify new findings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;comm -13 \
  previous-assets.txt \
  current-assets.txt \
  &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; newly-discovered.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For reliable comparisons, keep both input files sorted and normalized.&lt;/p&gt;

&lt;p&gt;Teams should investigate unexpected changes rather than automatically treating every new hostname as a vulnerability.&lt;/p&gt;

&lt;p&gt;A continuous asset pipeline helps organizations identify forgotten infrastructure, reduce exposure, and improve visibility across development and production environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final takeaway:&lt;/strong&gt; Automated subdomain reconnaissance is not just about collecting more hostnames. It is about maintaining an accurate, continuously updated inventory and ensuring every exposed asset has an owner and a remediation plan.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>cybersecurity</category>
      <category>security</category>
      <category>tooling</category>
    </item>
    <item>
      <title>The Definitive Guide to Server-Side Request Forgery (SSRF)</title>
      <dc:creator>kartavya</dc:creator>
      <pubDate>Mon, 16 Nov 2026 10:54:55 +0000</pubDate>
      <link>https://dev.to/kartavya_9c69f1c1352ec440/the-definitive-guide-to-server-side-request-forgery-ssrf-24hh</link>
      <guid>https://dev.to/kartavya_9c69f1c1352ec440/the-definitive-guide-to-server-side-request-forgery-ssrf-24hh</guid>
      <description>&lt;p&gt;From internal port scanning to cloud instance metadata exfiltration. Server-Side Request Forgery (SSRF) is a serious web application security vulnerability that allows attackers to manipulate a server into sending requests to unintended destinations.&lt;/p&gt;

&lt;p&gt;Unlike traditional attacks that target a user's browser, SSRF abuses the trust placed in a backend server. When an application fetches URLs supplied by users without proper validation, attackers may reach internal services, access restricted endpoints, or interact with cloud infrastructure.&lt;/p&gt;

&lt;p&gt;For developers building modern web applications, understanding SSRF is essential. This guide explains how SSRF works, demonstrates a controlled testing environment, and covers a complete remediation guide: hardening internal DNS egress proxies and IMDSv2.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Understanding SSRF and How It Works
&lt;/h2&gt;

&lt;p&gt;SSRF occurs when an application accepts a URL from a user and makes a server-side HTTP request without sufficiently validating the destination.&lt;/p&gt;

&lt;p&gt;Consider a website that provides a URL preview feature. A user submits a URL, and the backend retrieves its contents to generate a preview.&lt;/p&gt;

&lt;p&gt;A vulnerable implementation might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/preview"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&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="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is that the application accepts arbitrary URLs. It does not check whether the destination is public, private, or internal.&lt;/p&gt;

&lt;p&gt;Potential SSRF targets include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Internal application services.&lt;/li&gt;
&lt;li&gt;Localhost and private network addresses.&lt;/li&gt;
&lt;li&gt;Internal DNS services.&lt;/li&gt;
&lt;li&gt;Cloud instance metadata endpoints.&lt;/li&gt;
&lt;li&gt;Administrative dashboards and APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes SSRF particularly dangerous in cloud environments where backend services may have access to sensitive infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Common SSRF Techniques and Decimal IP Notation
&lt;/h2&gt;

&lt;p&gt;Attackers may attempt different address representations to bypass weak URL filters.&lt;/p&gt;

&lt;p&gt;One example is decimal IP notation.&lt;/p&gt;

&lt;p&gt;The IPv4 address &lt;code&gt;127.0.0.1&lt;/code&gt; can also be represented as the decimal integer &lt;code&gt;2130706433&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Test the conversion using Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ipaddress&lt;/span&gt;

&lt;span class="n"&gt;decimal_ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2130706433&lt;/span&gt;

&lt;span class="n"&gt;converted_ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ipaddress&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ip_address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;decimal_ip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Original decimal:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;decimal_ip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Converted IPv4:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;converted_ip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Original decimal: 2130706433
Converted IPv4: 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A string-based security filter might recognize the dotted address but fail to recognize alternative representations.&lt;/p&gt;

&lt;p&gt;Other areas that require testing include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IPv4 and IPv6 representations.&lt;/li&gt;
&lt;li&gt;DNS resolution and rebinding.&lt;/li&gt;
&lt;li&gt;Redirect handling.&lt;/li&gt;
&lt;li&gt;URL encoding and normalization.&lt;/li&gt;
&lt;li&gt;Alternative hostname representations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a controlled local Docker lab, start a test server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python -m http.server 8000 --bind 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test both representations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://127.0.0.1:8000
curl http://2130706433:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These requests demonstrate how different representations can resolve to the same loopback destination on compatible systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security lesson:&lt;/strong&gt; Never depend on simple string matching to validate URLs or IP addresses.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Building a Controlled SSRF Testing Environment
&lt;/h2&gt;

&lt;p&gt;A local testing environment helps developers understand how backend requests behave without targeting external systems.&lt;/p&gt;

&lt;p&gt;Create a project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir ssrf-security-lab
&lt;span class="nb"&gt;cd&lt;/span&gt; ssrf-security-lab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a Docker Compose configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;internal-service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:alpine&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ssrf-internal&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"127.0.0.1:8081:80"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the local service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://127.0.0.1:8081
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected result: an Nginx welcome page.&lt;/p&gt;

&lt;p&gt;Check the running container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stop the lab after testing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This environment provides a simple internal service for understanding how applications interact with backend resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Vulnerable vs. Remediated Code: Complete SSRF Protection
&lt;/h2&gt;

&lt;p&gt;The vulnerable implementation accepts any URL and sends a backend request.&lt;/p&gt;

&lt;p&gt;A safer implementation should enforce strict destination validation, use an allowlist, restrict redirects, and apply request timeouts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remediated Python example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;abort&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parse&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urlparse&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ipaddress&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="no"&gt;ALLOWED_HOSTS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"example.com"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;urlparse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scheme&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"https"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;ALLOWED_HOSTS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;addresses&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getaddrinfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="mi"&gt;443&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SOCK_STREAM&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;addresses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;addresses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ipaddress&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ip_address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_global&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OSError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&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="kc"&gt;False&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;


&lt;span class="nd"&gt;@app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/preview"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&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="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;validate_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;abort&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="s2"&gt;"Destination not allowed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&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="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;allow_redirects&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;

    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RequestException&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;502&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Request failed"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a baseline defensive example, not a complete production-grade SSRF control. DNS validation followed by a separate HTTP connection can still permit DNS rebinding or resolution changes.&lt;/p&gt;

&lt;p&gt;Production applications should enforce destination restrictions at the network egress layer as well. The proxy must validate the actual resolved and connected IP address, including IPv4 and IPv6, and reject private, loopback, link-local, and other prohibited destinations.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Complete Remediation Guide: DNS Egress Proxies and IMDSv2
&lt;/h2&gt;

&lt;p&gt;Application-level validation alone is not enough. Strong SSRF protection requires multiple security layers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A. Harden internal DNS and egress proxies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An outbound proxy should enforce destination policies before allowing backend requests.&lt;/p&gt;

&lt;p&gt;Recommended controls:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allow only approved destination domains.&lt;/li&gt;
&lt;li&gt;Block private, loopback, and link-local address ranges.&lt;/li&gt;
&lt;li&gt;Validate resolved IPv4 and IPv6 addresses.&lt;/li&gt;
&lt;li&gt;Prevent DNS rebinding and resolution inconsistencies.&lt;/li&gt;
&lt;li&gt;Restrict outbound ports and protocols.&lt;/li&gt;
&lt;li&gt;Disable unrestricted redirects.&lt;/li&gt;
&lt;li&gt;Maintain logs for blocked outbound requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, a Squid proxy can use destination ACLs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="nc"&gt;SSL_ports&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="mi"&gt;443&lt;/span&gt;
&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="nc"&gt;Safe_ports&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt; &lt;span class="mi"&gt;443&lt;/span&gt;
&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="no"&gt;CONNECT&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="no"&gt;CONNECT&lt;/span&gt;

&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;Safe_ports&lt;/span&gt;
&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="no"&gt;CONNECT&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;SSL_ports&lt;/span&gt;

&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="n"&gt;blocked_private&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt; &lt;span class="mf"&gt;10.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="n"&gt;blocked_loopback&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt; &lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="n"&gt;blocked_linklocal&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt; &lt;span class="mf"&gt;169.254&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;
&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="n"&gt;blocked_private_v6&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="n"&gt;blocked_private_v6&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt; &lt;span class="n"&gt;fc00&lt;/span&gt;&lt;span class="o"&gt;::/&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;
&lt;span class="n"&gt;acl&lt;/span&gt; &lt;span class="n"&gt;blocked_linklocal_v6&lt;/span&gt; &lt;span class="n"&gt;dst&lt;/span&gt; &lt;span class="n"&gt;fe80&lt;/span&gt;&lt;span class="o"&gt;::/&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;

&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="n"&gt;blocked_private&lt;/span&gt;
&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="n"&gt;blocked_loopback&lt;/span&gt;
&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="n"&gt;blocked_linklocal&lt;/span&gt;
&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="n"&gt;blocked_private_v6&lt;/span&gt;
&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="n"&gt;blocked_linklocal_v6&lt;/span&gt;

&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;allow&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt;
&lt;span class="n"&gt;http_access&lt;/span&gt; &lt;span class="n"&gt;deny&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an illustrative baseline. Production proxy policies must also account for all prohibited address ranges, DNS resolution behavior, and the actual network architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. Enable AWS IMDSv2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cloud metadata services can expose sensitive instance information if applications are vulnerable to SSRF.&lt;/p&gt;

&lt;p&gt;AWS Instance Metadata Service Version 2 (IMDSv2) introduces session-oriented access using tokens.&lt;/p&gt;

&lt;p&gt;Enable token requirements using AWS CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 modify-instance-metadata-options \
  --instance-id i-xxxxxxxxxxxxxxxxx \
  --http-tokens required \
  --http-endpoint enabled \
  --http-put-response-hop-limit 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the instance ID with the authorized test instance.&lt;/p&gt;

&lt;p&gt;Verify the configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ec2 describe-instances \
  --instance-ids i-xxxxxxxxxxxxxxxxx \
  --query &lt;span class="s2"&gt;"Reservations[].Instances[].MetadataOptions"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test token-based metadata access from the authorized instance without displaying credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;curl -s -X PUT \
  &lt;span class="s2"&gt;"http://169.254.169.254/latest/api/token"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"X-aws-ec2-metadata-token-ttl-seconds: 60"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"X-aws-ec2-metadata-token: $TOKEN"&lt;/span&gt; \
  &lt;span class="s2"&gt;"http://169.254.169.254/latest/meta-data/"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The token requirement makes simple unauthenticated metadata requests insufficient. However, IMDSv2 is not a replacement for SSRF prevention. Applications should still block access to metadata endpoints through their egress controls and avoid exposing unnecessary instance permissions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. Final SSRF Security Checklist&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Validate and normalize every user-supplied URL.&lt;/li&gt;
&lt;li&gt;[ ] Use strict destination allowlists.&lt;/li&gt;
&lt;li&gt;[ ] Block private and reserved IP ranges.&lt;/li&gt;
&lt;li&gt;[ ] Validate IPv4 and IPv6 DNS results.&lt;/li&gt;
&lt;li&gt;[ ] Prevent DNS rebinding.&lt;/li&gt;
&lt;li&gt;[ ] Disable unrestricted redirects.&lt;/li&gt;
&lt;li&gt;[ ] Configure outbound proxy restrictions.&lt;/li&gt;
&lt;li&gt;[ ] Require IMDSv2 on AWS EC2 instances.&lt;/li&gt;
&lt;li&gt;[ ] Apply least-privilege IAM permissions.&lt;/li&gt;
&lt;li&gt;[ ] Monitor and log suspicious outbound requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SSRF is not just a URL validation problem. It is an infrastructure security issue that affects application code, internal networking, DNS resolution, and cloud permissions.&lt;/p&gt;

&lt;p&gt;A strong defense combines secure coding practices, restricted network egress, hardened DNS proxies, and cloud metadata protection.&lt;/p&gt;

&lt;p&gt;Developers should test these controls regularly rather than relying on a single validation function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Want to strengthen application security?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hackmywebsite.io/?utm_source=med&amp;amp;utm_campaign=definitive_ssrf" rel="noopener noreferrer"&gt;Download SSRF Remediation Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore &lt;strong&gt;Hack My Website&lt;/strong&gt; for automated DAST scanning and practical web application security testing.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>cloud</category>
      <category>cybersecurity</category>
      <category>security</category>
    </item>
  </channel>
</rss>
