<?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: Wilson Gouanet</title>
    <description>The latest articles on DEV Community by Wilson Gouanet (@wils3b).</description>
    <link>https://dev.to/wils3b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F482803%2F365492b1-48d7-496d-a4c8-22a8fc507b1d.png</url>
      <title>DEV Community: Wilson Gouanet</title>
      <link>https://dev.to/wils3b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wils3b"/>
    <language>en</language>
    <item>
      <title>Full Stack Security Essentials: Preventing CSRF, Clickjacking, and Ensuring Content Integrity in JavaScript</title>
      <dc:creator>Wilson Gouanet</dc:creator>
      <pubDate>Sun, 23 Feb 2025 12:42:03 +0000</pubDate>
      <link>https://dev.to/wils3b/full-stack-security-essentials-preventing-csrf-clickjacking-and-ensuring-content-integrity-in-4paf</link>
      <guid>https://dev.to/wils3b/full-stack-security-essentials-preventing-csrf-clickjacking-and-ensuring-content-integrity-in-4paf</guid>
      <description>&lt;p&gt;In today’s web development landscape, security is more than a buzzword—it’s a necessity. As full stack developers, we face a wide range of threats, from backend vulnerabilities to client-side exploits. In this article, we’ll explore three critical areas of JavaScript security: CSRF, clickjacking, and content integrity. We’ll discuss what each threat entails and provide practical tips on preventing them from both Node.js and in the browser environment.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. CSRF (Cross-Site Request Forgery)
&lt;/h2&gt;

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

&lt;p&gt;CSRF is an attack where a malicious website tricks a users browser into performing unwanted actions on a trusted site where the user is authenticated. This can lead to unexpected changes, unauthorized transactions, or data exposure.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Prevent CSRF
&lt;/h3&gt;

&lt;h4&gt;
  
  
  On the Node.js (Server-Side) End
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CSRF Tokens:&lt;/strong&gt; Use middleware (e.g., tiny-csrf in Express.js) to generate unique tokens for each session or form submission. Verify these tokens on every state-changing request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example using Express.js with tiny-csrf:&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;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; tiny-csrf express-session cookie-parser
&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;csurf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tiny-csrf&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cookieParser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cookie-parser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express-session&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlencoded&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;extended&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="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cookieParser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cookie-parser-secret&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;session&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keyboard cat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
  &lt;span class="c1"&gt;// Order matters: above three must come first&lt;/span&gt;
  &lt;span class="c1"&gt;// Setup csurf protection&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;csrfProtection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;csurf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;123456789iamasecret987654321look&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;csrfProtection&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/form&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Get the csrf token from the methog injected by the middeware to the request object&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;csrfToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;csrfToken&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// Token must be included in the rendered form&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;form action="/process" method="POST"&amp;gt;
                &amp;lt;input type="hidden" name="_csrf" value="&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;csrfToken&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;
                &amp;lt;input type="text" name="data"&amp;gt;
                &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
              &amp;lt;/form&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/process&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Process the request only if CSRF token is valid&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Form data processed safely.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nx"&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;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Server running on http://localhost:3000&lt;/span&gt;&lt;span class="dl"&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 example uses the module &lt;code&gt;tiny-csrf&lt;/code&gt;, which provides minimalist CSRF protection. For scenarios that require more robust security, consider the following alternatives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.npmjs.com/package/csrf-csrf" rel="noopener noreferrer"&gt;csrf-csrf&lt;/a&gt;:&lt;/strong&gt; This module offers the essential components to implement CSRF protection using the Double Submit Cookie Pattern—a stateless approach.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://www.npmjs.com/package/csrf-sync" rel="noopener noreferrer"&gt;csrf-sync&lt;/a&gt;:&lt;/strong&gt; Designed for the Synchroniser Token Pattern, this alternative is particularly suited for session-based authentication and offers stateful CSRF protection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both options provide enhanced flexibility depending on your specific security requirements.&lt;/p&gt;

&lt;h4&gt;
  
  
  In the Browser (Client-Side)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SameSite Cookies:&lt;/strong&gt; Set your cookies with the SameSite attribute to Lax or Strict to prevent them from being sent along with cross-domain requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Headers:&lt;/strong&gt; When making AJAX requests, include custom headers (like X-Requested-With) and validate them on the server to help identify legitimate requests.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Clickjacking
&lt;/h2&gt;

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

&lt;p&gt;Clickjacking involves tricking a user into clicking on a disguised UI element, often hidden or overlaid by another element, which can lead to unintended actions like authorizing an action, sharing data, or even performing administrative tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Prevent Clickjacking
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;X-Frame-Options Header:&lt;/strong&gt; Use the X-Frame-Options HTTP header to control whether your content can be embedded in frames. Options include:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;DENY&lt;/code&gt;: Prevent all framing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SAMEORIGIN&lt;/code&gt;: Allow framing only from the same origin.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Example in Express.js:&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="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;X-Frame-Options&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SAMEORIGIN&lt;/span&gt;&lt;span class="dl"&gt;'&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Content Security Policy (CSP):&lt;/strong&gt; Use the &lt;code&gt;frame-ancestors&lt;/code&gt; directive in your CSP headers to control what domains can embed your pages. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Security-Policy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;frame-ancestors 'self'&lt;/span&gt;&lt;span class="dl"&gt;"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frame Busting Scripts:&lt;/strong&gt; While these can be implemented using JavaScript to “bust out” of frames, they are less reliable than server-side HTTP headers and should be used as a secondary measure.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Content Integrity
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Content Integrity?
&lt;/h3&gt;

&lt;p&gt;Content integrity ensures that the content served by your site (e.g., scripts, stylesheets) remains unchanged from its original, trusted source. This is crucial in preventing tampering and man-in-the-middle attacks, especially when using third-party resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why We Should Add It
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trust:&lt;/strong&gt; Users can trust that the data and code are coming from verified sources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Protect against situations where third-party content may be compromised.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compliance:&lt;/strong&gt; Meet security and compliance standards that require integrity assurances.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to Implement Content Integrity
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subresource Integrity (SRI):&lt;/strong&gt; SRI allows browsers to verify that files they fetch (like JavaScript libraries) are delivered without unexpected manipulation. It involves including a cryptographic hash attribute in the HTML tag linking the resource.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/library.js"&lt;/span&gt;
          &lt;span class="na"&gt;integrity=&lt;/span&gt;&lt;span class="s"&gt;"sha384-oqVuAfXRKap7fdgcCY5uykM6+R9Wu0g6a3JmGDXVbDt+u6p1mCA/t9zqXQGHbQ8c"&lt;/span&gt;
          &lt;span class="na"&gt;crossorigin=&lt;/span&gt;&lt;span class="s"&gt;"anonymous"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CSP Hashes:&lt;/strong&gt; When inline scripts are necessary, you can use CSP hashes to specify the expected hash of the script contents, ensuring that only approved code executes.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Incorporating solid security practices into your JavaScript applications is not optional—it’s fundamental. By understanding the risks associated with CSRF, clickjacking, and the importance of content integrity, you can implement robust measures that safeguard both your application and its users.&lt;/p&gt;

&lt;p&gt;Whether you’re tweaking your Node.js backend or reinforcing client-side defenses, these strategies help ensure that your applications remain secure in an increasingly hostile online environment. Security is a continuous journey—stay vigilant, keep your dependencies updated, and always be mindful of emerging threats.&lt;/p&gt;




&lt;h2&gt;
  
  
  Further readings
&lt;/h2&gt;

&lt;p&gt;To explore the concepts in this article further, you can read the following resources that provide more detailed information about CSRF, clickjacking, and content integrity.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://owasp.org/www-community/attacks/csrf" rel="noopener noreferrer"&gt;https://owasp.org/www-community/attacks/csrf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html" rel="noopener noreferrer"&gt;https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://owasp.org/www-community/attacks/Clickjacking" rel="noopener noreferrer"&gt;https://owasp.org/www-community/attacks/Clickjacking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html" rel="noopener noreferrer"&gt;https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>csrf</category>
      <category>node</category>
    </item>
    <item>
      <title>Demystifying Disappearing Dropdowns: A Chrome Developer's Guide to Inspecting Volatile UI Elements</title>
      <dc:creator>Wilson Gouanet</dc:creator>
      <pubDate>Tue, 12 Nov 2024 17:24:28 +0000</pubDate>
      <link>https://dev.to/wils3b/demystifying-disappearing-dropdowns-a-chrome-developers-guide-to-inspecting-volatile-ui-elements-5g5g</link>
      <guid>https://dev.to/wils3b/demystifying-disappearing-dropdowns-a-chrome-developers-guide-to-inspecting-volatile-ui-elements-5g5g</guid>
      <description>&lt;p&gt;As web developers, we often encounter the frustrating scenario of trying to inspect dynamic UI elements, such as dropdowns, that seem to disappear the moment we try to interact with them.&lt;/p&gt;

&lt;p&gt;Recently, I was working on an app that uses Material UI components, and I encountered this exact issue when trying to inspect an &lt;a href="https://mui.com/material-ui/react-autocomplete/" rel="noopener noreferrer"&gt;autocomplete&lt;/a&gt; dropdown. The problem was that the dropdown would vanish as soon as the document lost focus, making it nearly impossible to inspect using the standard Chrome DevTools.&lt;/p&gt;

&lt;p&gt;However, there is a clever solution to this problem: the &lt;strong&gt;"Page Focus Emulation"&lt;/strong&gt; feature in Chrome DevTools. By activating this feature, you can keep the dropdown visible and accessible for inspection, even when the document is not in focus.&lt;/p&gt;

&lt;p&gt;Here's how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Chrome DevTools (You can find easy tips for that &lt;a href="https://www.linkedin.com/posts/wilson-gouanet_chromedevtools-frontenddevelopment-webdevelopment-activity-7258923497064701954-_-ik" rel="noopener noreferrer"&gt;here&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Navigate to the "Rendering" tab in the DevTools panel, or click the &lt;em&gt;:hov&lt;/em&gt; button on the action bar in &lt;strong&gt;Elements &amp;gt; Styles&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Check the &lt;strong&gt;Emulate a focused page&lt;/strong&gt; checkbox.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now you can freely interact with the dropdown and use the Chrome DevTools to inspect its structure, styles, and behavior.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/NFjnc7yKJoo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;
How to use page focus emulation






&lt;p&gt;It's important to note that the "Page Focus Emulation" feature is designed to help with debugging purposes only. Once you've completed your inspection, remember to disable this feature to ensure your web application behaves as expected in a real-world scenario.&lt;/p&gt;

&lt;p&gt;By mastering this technique, you can overcome the challenges of inspecting disappearing UI elements and gain a deeper understanding of your web application's inner workings. Happy debugging!&lt;/p&gt;




&lt;h2&gt;
  
  
  Further exploration:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/docs/devtools/rendering/apply-effects#emulate_a_focused_page" rel="noopener noreferrer"&gt;https://developer.chrome.com/docs/devtools/rendering/apply-effects#emulate_a_focused_page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/blog/devtools-tips-35" rel="noopener noreferrer"&gt;https://developer.chrome.com/blog/devtools-tips-35&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>javascript</category>
      <category>html</category>
    </item>
    <item>
      <title>Mastering Chrome Developer Tools: Essential Tips for Front-End Developers</title>
      <dc:creator>Wilson Gouanet</dc:creator>
      <pubDate>Sat, 02 Nov 2024 20:34:08 +0000</pubDate>
      <link>https://dev.to/wils3b/mastering-chrome-developer-tools-essential-tips-for-front-end-developers-5cm4</link>
      <guid>https://dev.to/wils3b/mastering-chrome-developer-tools-essential-tips-for-front-end-developers-5cm4</guid>
      <description>&lt;p&gt;In today's tech landscape, JavaScript has emerged as one of the leading programming languages, consistently ranking among the &lt;a href="https://www.statista.com/statistics/793628/worldwide-developer-survey-most-used-languages/" rel="noopener noreferrer"&gt;top five&lt;/a&gt; most used and in-demand languages. It enables developers to build entire applications with ease. To effectively harness the power of JavaScript, every software developer should master the tools that provide insights into their applications. When issues arise or when you need to understand the behavior of your app, utilizing developer tools (&lt;em&gt;DevTools&lt;/em&gt;) is essential. In this article, I will share valuable insights and tips I've discovered while working on numerous front-end applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Unlocking Efficiency: The Power of DevTools Shortcuts
&lt;/h2&gt;

&lt;p&gt;As front-end developers, we frequently need to access our DevTools, and while opening them manually may seem quick, using keyboard shortcuts can save significant time over repeated use. By incorporating shortcuts into your workflow, you can work more efficiently and focus on what truly matters—building great applications. Here are some useful shortcuts to get you started. For a comprehensive list of shortcuts, you can refer to the official documentation here: &lt;a href="https://developer.chrome.com/docs/devtools/shortcuts/" rel="noopener noreferrer"&gt;Chrome DevTools Shortcuts&lt;/a&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Mac&lt;/th&gt;
&lt;th&gt;Windows / Linux&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Open whatever panel you used last&lt;/td&gt;
&lt;td&gt;Command+Option+I&lt;/td&gt;
&lt;td&gt;F12 or Control+Shift+I&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Open the &lt;strong&gt;Console&lt;/strong&gt; panel&lt;/td&gt;
&lt;td&gt;Command+Option+J&lt;/td&gt;
&lt;td&gt;Control+Shift+J&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Open the &lt;strong&gt;Elements&lt;/strong&gt; panel&lt;/td&gt;
&lt;td&gt;Command+Shift+C or Command+Option+C&lt;/td&gt;
&lt;td&gt;Control+Shift+C&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  2. The Console Can Appear on Every Tab, Not Just the Console Tab
&lt;/h2&gt;

&lt;p&gt;Sometimes, you may want to access the console to execute commands or monitor logs without switching to the Console tab. Fortunately, you can do this from any tab in DevTools. Simply press the &lt;code&gt;Esc&lt;/code&gt; key to bring up the console, allowing you to interact with it seamlessly while working in other panels. The following image illustrates a case where the &lt;strong&gt;Console&lt;/strong&gt; appears under the &lt;strong&gt;Elements&lt;/strong&gt; tab.&lt;/p&gt;

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






&lt;h2&gt;
  
  
  3.You Can Get the Computed Style Value of Every Element—and Filter Them
&lt;/h2&gt;

&lt;p&gt;In the Elements tab, instead of scrolling through each group of properties, you can use the Computed Styles section to quickly determine the current value of any property you are interested in.&lt;/p&gt;

&lt;p&gt;In the following image, you can see that when inspecting an element under the Elements tab, selecting the Computed sub-tab provides an overview of the layout &lt;strong&gt;&lt;em&gt;(0)&lt;/em&gt;&lt;/strong&gt; of that element, including its border, margin, padding, and inner size. You can also filter &lt;em&gt;&lt;strong&gt;(1)&lt;/strong&gt;&lt;/em&gt; the CSS properties to find the value of a specific property. These properties may appear grouped &lt;em&gt;&lt;strong&gt;(2)&lt;/strong&gt;&lt;/em&gt;, and you have the option to display all properties &lt;strong&gt;&lt;em&gt;(3)&lt;/em&gt;&lt;/strong&gt;, including user agent default values (which appear semi-transparent in the list) and properties that have been overridden by your app’s code (which appear opaque).&lt;/p&gt;

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






&lt;h2&gt;
  
  
  4. Never Lose a Log: Preserving Your Console and Network Logs
&lt;/h2&gt;

&lt;p&gt;In some cases, you may want to preserve logs when reloading the app or navigating away, whether to see what happens before users leave the app or for other use cases. To achieve this, both the Network and Console tabs have a "Preserve logs" checkbox that you can enable. Once checked, your logs will be preserved.&lt;/p&gt;

&lt;p&gt;In the Network tab, the "Preserve logs" checkbox is located on the toolbar beneath the tabs.&lt;/p&gt;

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



&lt;p&gt;For the Console tab, you first need to click on the gear icon (cog) in the top left corner, just below the close button. This will reveal a list where you can find the checkbox to preserve logs, as shown in the accompanying image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8ig5xcx8lfvmoa610wg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8ig5xcx8lfvmoa610wg.png" alt="Preseve console logs, in chrome developer tools" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;
Preserve console logs






&lt;h2&gt;
  
  
  5. You Don't Need to Use Console.log All the Time
&lt;/h2&gt;

&lt;p&gt;Sometimes, you may want to log a value that changes frequently in your console. A common approach is to use &lt;code&gt;console.log&lt;/code&gt; directly in your code, allowing you to see the latest value with each change. However, this method can be limiting, as some value changes do not trigger any events.&lt;/p&gt;

&lt;p&gt;Fortunately, there is a powerful tool that allows you to watch the result of an expression directly in your Chrome console: it’s called “Live Expression.” To create a live expression, simply navigate to the Console tab and click on the eye button. You can then enter any &lt;a href="https://en.wikipedia.org/wiki/Expression_(computer_science)" rel="noopener noreferrer"&gt;expression&lt;/a&gt;, and every time the evaluation of that expression changes, the updated value will appear in your console under the live expression. You can see an example in the following video.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Fk4ObbYe-wY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In summary, mastering Chrome Developer Tools can significantly enhance your front-end development experience. From utilizing shortcuts to leveraging features like Live Expressions, these tools can streamline your workflow and improve your debugging process. I’d love to hear about your experiences with Chrome DevTools! Please leave a comment below sharing your tips, tricks, or any challenges you've faced. Let’s learn from each other and continue to grow as developers! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>productivity</category>
      <category>css</category>
    </item>
  </channel>
</rss>
