<?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: Ayman Eldawy</title>
    <description>The latest articles on DEV Community by Ayman Eldawy (@aymaneldawy).</description>
    <link>https://dev.to/aymaneldawy</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%2F185073%2F9f223d8a-2fa1-44b5-904e-6db1d3ff91c9.jpg</url>
      <title>DEV Community: Ayman Eldawy</title>
      <link>https://dev.to/aymaneldawy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aymaneldawy"/>
    <language>en</language>
    <item>
      <title>Oxlint vs ESLint: Which One Should You Use?</title>
      <dc:creator>Ayman Eldawy</dc:creator>
      <pubDate>Tue, 21 Jul 2026 08:25:14 +0000</pubDate>
      <link>https://dev.to/aymaneldawy/oxlint-vs-eslint-which-one-should-you-use-cfc</link>
      <guid>https://dev.to/aymaneldawy/oxlint-vs-eslint-which-one-should-you-use-cfc</guid>
      <description>&lt;p&gt;If you've worked with JavaScript or TypeScript, you've probably used &lt;strong&gt;ESLint&lt;/strong&gt; at some point.&lt;/p&gt;

&lt;p&gt;But recently, a new competitor has been gaining attention: &lt;strong&gt;Oxlint&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So, what's the difference, and which one should you choose?&lt;/p&gt;

&lt;p&gt;Let's start with the basics.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Linter?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;linter&lt;/strong&gt; is a tool that analyzes your code and reports potential issues before they reach production.&lt;/p&gt;

&lt;p&gt;Beyond catching bugs, it also helps teams maintain a consistent coding style by enforcing shared rules across the codebase.&lt;/p&gt;

&lt;p&gt;In short, it keeps your code cleaner, more predictable, and easier to maintain.&lt;/p&gt;




&lt;h2&gt;
  
  
  ESLint
&lt;/h2&gt;

&lt;p&gt;ESLint has been the standard linter for the JavaScript ecosystem for years.&lt;/p&gt;

&lt;p&gt;If you've built a React, Next.js, Vue, or Node.js application, chances are you've already worked with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A massive ecosystem.&lt;/li&gt;
&lt;li&gt;Thousands of plugins and shareable configurations.&lt;/li&gt;
&lt;li&gt;Excellent support for React, Next.js, Vue, TypeScript, testing libraries, and more.&lt;/li&gt;
&lt;li&gt;Easy to write custom rules.&lt;/li&gt;
&lt;li&gt;Mature and battle-tested.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Performance can become an issue in large projects.&lt;/li&gt;
&lt;li&gt;Every additional plugin increases linting time.&lt;/li&gt;
&lt;li&gt;Configuration can become complex as projects grow.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Oxlint
&lt;/h2&gt;

&lt;p&gt;Oxlint is a modern linter written in &lt;strong&gt;Rust&lt;/strong&gt;, designed from the ground up with one goal: &lt;strong&gt;speed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It's quickly becoming popular because of its impressive performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Often &lt;strong&gt;tens of times faster&lt;/strong&gt; than ESLint.&lt;/li&gt;
&lt;li&gt;Lower CPU and memory usage.&lt;/li&gt;
&lt;li&gt;Simple setup with an excellent developer experience.&lt;/li&gt;
&lt;li&gt;Great choice for large repositories and CI/CD pipelines.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The ecosystem is still much smaller than ESLint's.&lt;/li&gt;
&lt;li&gt;Not every ESLint rule or plugin is supported yet.&lt;/li&gt;
&lt;li&gt;Projects that rely heavily on custom ESLint plugins may still need ESLint.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Which one should you use?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Choose &lt;strong&gt;ESLint&lt;/strong&gt; if:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You're working on an existing project.&lt;/li&gt;
&lt;li&gt;Your project depends on many ESLint plugins.&lt;/li&gt;
&lt;li&gt;You need custom linting rules.&lt;/li&gt;
&lt;li&gt;You're using frameworks like Next.js with established ESLint configurations.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Choose &lt;strong&gt;Oxlint&lt;/strong&gt; if:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You're starting a new project.&lt;/li&gt;
&lt;li&gt;Performance is a top priority.&lt;/li&gt;
&lt;li&gt;Your project doesn't rely on many ESLint plugins.&lt;/li&gt;
&lt;li&gt;You want to significantly reduce linting time in CI.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why not use both?
&lt;/h2&gt;

&lt;p&gt;You don't necessarily have to choose one over the other.&lt;/p&gt;

&lt;p&gt;Many teams combine them to get the best of both worlds.&lt;/p&gt;

&lt;p&gt;A common workflow looks like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;Oxlint&lt;/strong&gt; during development for extremely fast feedback.&lt;/li&gt;
&lt;li&gt;Run &lt;strong&gt;ESLint&lt;/strong&gt; before commits or in CI to enforce all project-specific rules and plugins.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach provides a great developer experience without sacrificing the flexibility of ESLint.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;There's no universal winner.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ESLint&lt;/strong&gt; wins when you need flexibility, a mature ecosystem, and extensive plugin support.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Oxlint&lt;/strong&gt; wins when speed and developer experience are your highest priorities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For many modern teams, using &lt;strong&gt;both&lt;/strong&gt; is becoming an increasingly popular choice.&lt;/p&gt;




&lt;p&gt;This is the first post in my new &lt;strong&gt;Frontend Battles&lt;/strong&gt; series, where I'll compare popular frontend tools, libraries, and technologies to help you understand their strengths, trade-offs, and when to choose each one.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Where Should You Store Your JWT?</title>
      <dc:creator>Ayman Eldawy</dc:creator>
      <pubDate>Wed, 15 Jul 2026 07:19:14 +0000</pubDate>
      <link>https://dev.to/aymaneldawy/where-should-you-store-your-jwt-19ad</link>
      <guid>https://dev.to/aymaneldawy/where-should-you-store-your-jwt-19ad</guid>
      <description>&lt;p&gt;One of the first questions developers face when implementing an authentication flow is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where should I store the JWT?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After all, your application needs easy access to the token so it can send it in the &lt;code&gt;Authorization&lt;/code&gt; header when making authenticated requests.&lt;/p&gt;

&lt;p&gt;The two most common options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local Storage&lt;/li&gt;
&lt;li&gt;HttpOnly Cookies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's compare them.&lt;/p&gt;




&lt;h2&gt;
  
  
  Option 1: Local Storage
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;localStorage&lt;/code&gt; is a browser storage API that allows JavaScript to store and retrieve data.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The biggest advantage is convenience.&lt;/p&gt;

&lt;p&gt;Your token is easy to access from anywhere in your frontend application.&lt;/p&gt;

&lt;p&gt;However, that convenience comes with an important security trade-off.&lt;/p&gt;

&lt;p&gt;Since JavaScript has full access to Local Storage, &lt;strong&gt;any JavaScript running on your page can also read your token.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your application is vulnerable to &lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt; and an attacker manages to inject malicious JavaScript, they can simply read the token and send it to their own server.&lt;/p&gt;

&lt;p&gt;That's one of the main reasons security professionals discourage storing JWTs in Local Storage.&lt;/p&gt;

&lt;p&gt;But security isn't the only drawback.&lt;/p&gt;

&lt;p&gt;Because Local Storage only exists in the browser, it isn't available during server-side rendering.&lt;/p&gt;

&lt;p&gt;That means if your authentication relies on a token stored in Local Storage, your authenticated requests typically have to be made from the client.&lt;/p&gt;

&lt;p&gt;For frameworks like &lt;strong&gt;Next.js&lt;/strong&gt;, this means giving up many of the benefits of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server Components&lt;/li&gt;
&lt;li&gt;Server-side rendering (SSR)&lt;/li&gt;
&lt;li&gt;Server-side data fetching&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simply put, the server cannot access Local Storage.&lt;/p&gt;




&lt;h2&gt;
  
  
  Option 2: HttpOnly Cookies
&lt;/h2&gt;

&lt;p&gt;A much more secure option is storing the token inside an &lt;strong&gt;HttpOnly Cookie&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The key advantage is that JavaScript &lt;strong&gt;cannot read HttpOnly cookies.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even if an attacker successfully exploits an XSS vulnerability, they still can't directly access the token stored inside the cookie.&lt;/p&gt;

&lt;p&gt;This provides a significant security improvement.&lt;/p&gt;

&lt;p&gt;Another major benefit is that cookies are automatically included with requests to your server.&lt;/p&gt;

&lt;p&gt;That means the token is available on both:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The client&lt;/li&gt;
&lt;li&gt;The server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is especially valuable in frameworks like &lt;strong&gt;Next.js&lt;/strong&gt;, where Server Components and SSR often need access to the authenticated user's session.&lt;/p&gt;




&lt;h2&gt;
  
  
  Is HttpOnly Cookie always better?
&lt;/h2&gt;

&lt;p&gt;Not necessarily.&lt;/p&gt;

&lt;p&gt;Like most engineering decisions, it's a trade-off.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local Storage
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Very simple to implement&lt;/li&gt;
&lt;li&gt;Easy to access from JavaScript&lt;/li&gt;
&lt;li&gt;Works well for purely client-side applications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vulnerable to XSS attacks&lt;/li&gt;
&lt;li&gt;Not available during server-side rendering&lt;/li&gt;
&lt;li&gt;Forces authentication logic to stay on the client&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  HttpOnly Cookies
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Much more resistant to XSS attacks&lt;/li&gt;
&lt;li&gt;Available to both the client and the server&lt;/li&gt;
&lt;li&gt;Works naturally with SSR and Server Components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More complex to implement&lt;/li&gt;
&lt;li&gt;Requires proper cookie configuration (&lt;code&gt;HttpOnly&lt;/code&gt;, &lt;code&gt;Secure&lt;/code&gt;, &lt;code&gt;SameSite&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;You also need to consider CSRF protection, since cookies are automatically sent with requests&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  So... which one should you choose?
&lt;/h2&gt;

&lt;p&gt;For modern web applications—especially those built with frameworks like &lt;strong&gt;Next.js&lt;/strong&gt;—&lt;strong&gt;HttpOnly Cookies are generally the recommended approach.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They provide stronger security, work seamlessly with server-side rendering, and align better with modern authentication architectures.&lt;/p&gt;

&lt;p&gt;Local Storage is easier to use, but that convenience comes with meaningful security and architectural limitations.&lt;/p&gt;




&lt;p&gt;This is the third post in my &lt;strong&gt;Frontend Security&lt;/strong&gt; series.&lt;/p&gt;

&lt;p&gt;Follow me to stay updated with the next episodes of my Frontend Security series&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>cookie</category>
      <category>frontend</category>
    </item>
    <item>
      <title>XSS Attacks</title>
      <dc:creator>Ayman Eldawy</dc:creator>
      <pubDate>Mon, 06 Jul 2026 07:16:42 +0000</pubDate>
      <link>https://dev.to/aymaneldawy/understanding-the-different-types-of-xss-attacks-39ih</link>
      <guid>https://dev.to/aymaneldawy/understanding-the-different-types-of-xss-attacks-39ih</guid>
      <description>&lt;p&gt;You’ve probably heard about &lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt; before, but did you know that it comes in multiple forms?&lt;/p&gt;

&lt;p&gt;Each type targets a different part of your application, and understanding the differences is essential for building secure frontend applications.&lt;/p&gt;

&lt;p&gt;Let's start with the basics.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is XSS?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt; is a security vulnerability that allows an attacker to inject malicious code, typically JavaScript, into a web page.&lt;/p&gt;

&lt;p&gt;When that code is executed in another user's browser, the attacker may be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Steal cookies or authentication tokens&lt;/li&gt;
&lt;li&gt;Read sensitive information&lt;/li&gt;
&lt;li&gt;Modify the page content&lt;/li&gt;
&lt;li&gt;Perform actions on behalf of the user&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most XSS vulnerabilities happen because applications don't safely handle user input.&lt;/p&gt;




&lt;h2&gt;
  
  
  The three main types of XSS
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Stored XSS&lt;/li&gt;
&lt;li&gt;Reflected XSS&lt;/li&gt;
&lt;li&gt;DOM-Based XSS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's look at each one.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Stored XSS
&lt;/h2&gt;

&lt;p&gt;This is generally considered the most dangerous type of XSS.&lt;/p&gt;

&lt;p&gt;It occurs when malicious user input is &lt;strong&gt;stored in the database&lt;/strong&gt; and later displayed to other users without proper sanitization or output encoding.&lt;/p&gt;

&lt;p&gt;Common places where this happens include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Comments&lt;/li&gt;
&lt;li&gt;Product reviews&lt;/li&gt;
&lt;li&gt;Forum posts&lt;/li&gt;
&lt;li&gt;User profiles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Imagine an attacker submits the following comment:&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&amp;gt;&lt;/span&gt;
  &lt;span class="c1"&gt;// malicious JavaScript&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the application stores and renders that content without sanitizing it, &lt;strong&gt;every user who visits the page will execute the attacker's script.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's why it's called &lt;strong&gt;"stored XSS";&lt;/strong&gt; the payload is permanently stored on the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Impact
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Large-scale attacks affecting many users&lt;/li&gt;
&lt;li&gt;Session hijacking&lt;/li&gt;
&lt;li&gt;Account compromise&lt;/li&gt;
&lt;li&gt;Data theft&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Validate and sanitize user input.&lt;/li&gt;
&lt;li&gt;Apply proper output encoding before rendering content.&lt;/li&gt;
&lt;li&gt;Use trusted sanitization libraries such as &lt;strong&gt;DOMPurify&lt;/strong&gt; when rendering HTML.&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;Content Security Policy (CSP)&lt;/strong&gt; as an additional defense layer.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Reflected XSS
&lt;/h2&gt;

&lt;p&gt;Unlike Stored XSS, the malicious payload is &lt;strong&gt;not stored&lt;/strong&gt; anywhere.&lt;/p&gt;

&lt;p&gt;Instead, it is reflected back to the user immediately through request data such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search inputs&lt;/li&gt;
&lt;li&gt;Query parameters&lt;/li&gt;
&lt;li&gt;URL fragments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A common attack looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The attacker crafts a malicious URL.&lt;/li&gt;
&lt;li&gt;The victim clicks the link.&lt;/li&gt;
&lt;li&gt;The application reflects the input back into the page without escaping it.&lt;/li&gt;
&lt;li&gt;The browser executes the injected JavaScript.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because the payload only exists in that request, the victim must interact with the malicious link for the attack to work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Impact
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Cookie or token theft&lt;/li&gt;
&lt;li&gt;Session hijacking&lt;/li&gt;
&lt;li&gt;Redirecting users to phishing websites&lt;/li&gt;
&lt;li&gt;Executing actions on behalf of the victim&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Validate incoming input.&lt;/li&gt;
&lt;li&gt;Always apply proper output encoding.&lt;/li&gt;
&lt;li&gt;Never render raw user input directly into HTML.&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;Content Security Policy (CSP)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. DOM-Based XSS
&lt;/h2&gt;

&lt;p&gt;This type is especially important for frontend developers because the vulnerability exists &lt;strong&gt;entirely inside the browser&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The server may never be involved.&lt;/p&gt;

&lt;p&gt;It happens when JavaScript reads data from an untrusted source and writes it directly into the DOM without proper sanitization.&lt;/p&gt;

&lt;p&gt;Common unsafe APIs include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;innerHTML&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;outerHTML&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;insertAdjacentHTML&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;document.write()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're using React, you're already safer because React automatically escapes text by default.&lt;/p&gt;

&lt;p&gt;However, that protection disappears when using APIs like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;dangerouslySetInnerHTML&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the HTML you're rendering comes from an untrusted source, you can easily introduce a DOM XSS vulnerability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Impact
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Data theft&lt;/li&gt;
&lt;li&gt;Page manipulation&lt;/li&gt;
&lt;li&gt;Executing arbitrary JavaScript&lt;/li&gt;
&lt;li&gt;Session hijacking&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Avoid using &lt;code&gt;innerHTML&lt;/code&gt; whenever possible.&lt;/li&gt;
&lt;li&gt;Avoid &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; with untrusted content.&lt;/li&gt;
&lt;li&gt;Sanitize HTML before rendering it.&lt;/li&gt;
&lt;li&gt;Review dangerous DOM sinks in your application.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The golden rule
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Never trust user input.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Whether the data comes from a form, a URL, an API, or even your own database, treat it as untrusted until you've validated, sanitized, and safely rendered it.&lt;/p&gt;

&lt;p&gt;Defense against XSS isn't a single technique; it's a combination of secure coding practices, proper output encoding, sanitization, and browser protections like CSP.&lt;/p&gt;




&lt;p&gt;This is the second post in my &lt;strong&gt;Frontend Security&lt;/strong&gt; series.&lt;/p&gt;

&lt;p&gt;In the previous post, we explored &lt;strong&gt;Content Security Policy (CSP)&lt;/strong&gt; and how it helps mitigate XSS attacks.&lt;br&gt;
if you'd like to check it out.&lt;br&gt;
&lt;a href="https://dev.to/aymaneldawy/what-is-content-security-policy-csp-p6p"&gt;https://dev.to/aymaneldawy/what-is-content-security-policy-csp-p6p&lt;/a&gt;&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>security</category>
      <category>javascript</category>
      <category>xss</category>
    </item>
    <item>
      <title>What is Content Security Policy (CSP)?</title>
      <dc:creator>Ayman Eldawy</dc:creator>
      <pubDate>Thu, 02 Jul 2026 07:43:56 +0000</pubDate>
      <link>https://dev.to/aymaneldawy/what-is-content-security-policy-csp-p6p</link>
      <guid>https://dev.to/aymaneldawy/what-is-content-security-policy-csp-p6p</guid>
      <description>&lt;p&gt;One of the most important, yet often underrated, topics in frontend security is &lt;strong&gt;Content Security Policy (CSP)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can think of CSP as a set of instructions you give the browser, telling it &lt;strong&gt;what is allowed to run and what should be blocked&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's break it down.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is CSP?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Content Security Policy (CSP)&lt;/strong&gt; is an &lt;strong&gt;HTTP response header&lt;/strong&gt; that you configure on your server to tell the browser which sources are trusted for loading resources such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;li&gt;Videos&lt;/li&gt;
&lt;li&gt;Fonts&lt;/li&gt;
&lt;li&gt;And other assets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Imagine the browser has a &lt;strong&gt;whitelist&lt;/strong&gt; of trusted sources. Whenever it tries to load a resource, it checks whether that source is on the list.&lt;/p&gt;

&lt;p&gt;If the source isn't trusted, the browser simply blocks it.&lt;/p&gt;

&lt;p&gt;This makes it much harder for attackers to inject and execute malicious code on your website.&lt;/p&gt;




&lt;h2&gt;
  
  
  What problem does CSP solve?
&lt;/h2&gt;

&lt;p&gt;The primary problem CSP helps mitigate is &lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;An XSS attack allows an attacker to inject malicious JavaScript into your application. Once executed, that script could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Steal cookies&lt;/li&gt;
&lt;li&gt;Read data from Local Storage&lt;/li&gt;
&lt;li&gt;Modify the page&lt;/li&gt;
&lt;li&gt;Perform actions on behalf of the user&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How does CSP stop this?
&lt;/h3&gt;

&lt;p&gt;Even if an attacker successfully injects JavaScript into your page, the browser will first check your CSP policy.&lt;/p&gt;

&lt;p&gt;If that script doesn't come from an approved source, &lt;strong&gt;the browser refuses to execute it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In many cases, the attack simply fails before any malicious code runs.&lt;/p&gt;




&lt;h2&gt;
  
  
  CSP helps with more than XSS
&lt;/h2&gt;

&lt;p&gt;Although CSP is mainly known for mitigating XSS attacks, it can also help reduce other security risks, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clickjacking&lt;/li&gt;
&lt;li&gt;Loading untrusted third-party resources&lt;/li&gt;
&lt;li&gt;Restricting iframes&lt;/li&gt;
&lt;li&gt;Controlling redirects&lt;/li&gt;
&lt;li&gt;Restricting form submissions&lt;/li&gt;
&lt;li&gt;Controlling where images, fonts, stylesheets, and scripts can be loaded from&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Despite being "just an HTTP header," CSP offers a surprisingly powerful security layer.&lt;/p&gt;

&lt;p&gt;The downside?&lt;/p&gt;

&lt;p&gt;Implementing a strict CSP can be challenging because you'll often need to carefully define every trusted resource your application depends on.&lt;/p&gt;




&lt;h2&gt;
  
  
  A simple example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Content-Security-Policy:
  default-src 'self';
  script-src 'self' https://example.com;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What does this mean?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;default-src 'self'&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By default, resources should only be loaded from your own domain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;script-src 'self' https://example.com&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaScript is only allowed to execute if it comes from your own website or from &lt;code&gt;https://example.com&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Any script loaded from another source will be blocked by the browser.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;The stricter your policy becomes, the stronger your security.&lt;/p&gt;

&lt;p&gt;Of course, finding the right balance between security and usability can take some effort.&lt;/p&gt;

&lt;p&gt;If you're using &lt;strong&gt;Next.js&lt;/strong&gt;, you can follow this guide to show you how to configure CSP in your application.&lt;br&gt;
&lt;a href="https://nextjs.org/docs/app/guides/content-security-policy" rel="noopener noreferrer"&gt;https://nextjs.org/docs/app/guides/content-security-policy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're using &lt;strong&gt;Angular&lt;/strong&gt;, you'll also find official documentation covering CSP support.&lt;/p&gt;




&lt;p&gt;This is the first post in a series about &lt;strong&gt;Frontend Security&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Over the next few posts, we'll explore more real-world security topics that every frontend developer should understand.&lt;/p&gt;

</description>
      <category>csp</category>
      <category>security</category>
      <category>frontend</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
