<?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: Ayomidejhay</title>
    <description>The latest articles on DEV Community by Ayomidejhay (@ayomidejhay).</description>
    <link>https://dev.to/ayomidejhay</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%2F3987487%2F58736841-fc05-41e7-a888-89e7cbf8e7fc.png</url>
      <title>DEV Community: Ayomidejhay</title>
      <link>https://dev.to/ayomidejhay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayomidejhay"/>
    <language>en</language>
    <item>
      <title>React vs. XSS: Where the Guardrails End</title>
      <dc:creator>Ayomidejhay</dc:creator>
      <pubDate>Tue, 16 Jun 2026 15:18:41 +0000</pubDate>
      <link>https://dev.to/ayomidejhay/react-vs-xss-where-the-guardrails-end-6p2</link>
      <guid>https://dev.to/ayomidejhay/react-vs-xss-where-the-guardrails-end-6p2</guid>
      <description>&lt;p&gt;React is often described as “secure by default” because it automatically escapes values inserted into JSX. However, this creates a dangerous misconception: React reduces XSS risk, but it does not eliminate it.&lt;br&gt;
Cross-Site Scripting (XSS) attack is a type of injection in which malicious scripts are injected into trusted websites. XSS attacks occur when an attacker uses a web application to send malicious code mostly in the form of a browser side script. This attack can be executed when data enters a web application through an untrusted source, mostly a web request and the data is then included in dynamic content that is sent to a web user without being validated for malicious content.&lt;br&gt;
An attacker can use XSS to send a malicious script to an unsuspecting user. The end user’s browser, not knowing the script cannot be trusted, can execute the script, causing the malicious script to gain access to cookies, session tokens or other sensitive information retained by the browser and used with that site.&lt;br&gt;
In 2019, a reflected XSS vulnerability was discovered on the PayPal login page. Attackers could manipulate URL parameters to inject malcious code into the project. When unsuspecting users clicked the malicious links sent via phishing emails, the script executed, potentially allowing attackers to steal session tokens.&lt;br&gt;
There are three main types of XSS attacks:&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%2F3pa26a8em2a1ys239bcy.jpg" 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%2F3pa26a8em2a1ys239bcy.jpg" alt="Image showing types of xss attacks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reflected XSS Attacks&lt;/strong&gt;: Reflected XSS attacks occur when malicious scripts submitted by an attacker are immediately returned by a web server in its response, such as within error messages, search results, or other content that includes user input. These attacks are typically delivered through external channels like emails, social media messages, or malicious websites. When a victim clicks a crafted link, submits a manipulated form, or visits a malicious page, the harmful code is sent to the vulnerable website and reflected back in the server’s response. Because the response appears to come from a trusted website, the victim’s browser executes the script, potentially allowing the attacker to steal sensitive information or perform unauthorized actions on behalf of the user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stored XSS Attacks&lt;/strong&gt;: Stored XSS attacks occur when malicious scripts are permanently saved on a target server, typically within databases, discussion forums, comment sections, visitor logs, or other data storage locations. Unlike reflected attacks, the malicious code remains on the server and is automatically delivered to users whenever they access the affected content. As a result, victims unknowingly load and execute the harmful script in their browsers while viewing legitimate web pages. Because the attack persists on the server until it is removed, Stored XSS can affect multiple users over an extended period. This type of attack is also known as Persistent XSS or Type-II XSS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DOM Based XSS Attacks&lt;/strong&gt;: Sometimes referred to as Type-0 XSS, occurs when malicious code is executed due to changes made to the Document Object Model (DOM) within the user's browser. In this type of attack, the original web page sent by the server remains unchanged. Instead, the attacker manipulates data in the browser environment such as URL parameters, fragments, or client side inputs, causing the page’s JavaScript code to behave in unintended ways. As a result, the malicious script is executed entirely on the client side without requiring the server to modify its response. This differs from Stored XSS and Reflected XSS, where the attack payload is injected into the server-generated response due to vulnerabilities on the server side.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Since React is described as “secure by default” against XSS Attacks,what exactly does React protect you from ?&lt;/p&gt;

&lt;p&gt;Now, React includes several built-in protections that reduce the risk of XSS attacks. The built-in protection includes: &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%2Fgm7ei7eft3d1clq0hf4j.jpg" 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%2Fgm7ei7eft3d1clq0hf4j.jpg" alt="Image showing react built-in protection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;a. &lt;strong&gt;Automatic Escaping of JSX Content&lt;/strong&gt; :&lt;br&gt;
When rendering user input inside JSX, React automatically escapes dangerous HTML characters&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="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;JavaScript&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;XSS&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&amp;gt;”&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of executing the script, React displays it as plain text. React, through this prevents basic script injection, stops attackers from injecting executable HTML through JSX expressions.&lt;/p&gt;

&lt;p&gt;b. &lt;strong&gt;Safe Rendering Model&lt;/strong&gt; :&lt;br&gt;
React encourages developers to describe the UI declaratively rather than manually manipulating the DOM.&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="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;JavaScript&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;userComment&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since React controls how content is rendered, it applies escaping automatically. This gives less reliance on dangerous DOM APIs.&lt;/p&gt;

&lt;p&gt;c. &lt;strong&gt;Reduced Need for Direct DOM Manipulation&lt;/strong&gt; :&lt;br&gt;
Since React manages updates through it’s virtual DOM, it typically avoid direct interaction with methods such as &lt;em&gt;document.write(), innerHTML, outerHTML&lt;/em&gt;. Through this, React eliminates many common sources of DOM-based XSS.&lt;/p&gt;

&lt;p&gt;Despite these built-in protections that reduce the risk of XSS attacks, React still gives developers escape hatches that can reintroduce XSS. React cannot protect applications when developers bypass its safety mechanisms. Ways by which developers bypass these safety mechanisms include: &lt;/p&gt;

&lt;p&gt;a. &lt;strong&gt;dangerouslySetInnerHTML&lt;/strong&gt; :&lt;br&gt;
This is React’s most obvious escape hatch.&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="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;JavaScript&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;dangerouslySetInnerHTML&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;&lt;span class="na"&gt;__html&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React inserts the HTML exactly as provided. If “content” contains malicious code, it may execute in the browser. The recommended solution to this is to sanitize content first.&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&amp;gt; JavaScrip&lt;/span&gt;&lt;span class="err"&gt;t
&lt;/span&gt;&lt;span class="nx"&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="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b. &lt;strong&gt;Direct DOM Manipulation&lt;/strong&gt; :&lt;br&gt;
Using browser APIs directly bypasses React's escaping protections.&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&amp;gt; JavaScrip&lt;/span&gt;&lt;span class="err"&gt;t
&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userInput&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User Input can  become executable code.&lt;/p&gt;

&lt;p&gt;c. &lt;strong&gt;Rendering HTML from External Sources&lt;/strong&gt; :&lt;br&gt;
Reacts assumes incoming data is already trusted. Example of these data can be CMS content, API responses, User generated content, Markdown renderers.If malicious HTML is rendered without sanitization, XSS becomes possible.&lt;/p&gt;

&lt;p&gt;d. &lt;strong&gt;Third Party Libraries&lt;/strong&gt; :&lt;br&gt;
Many libraries inject HTML into the DOM like Markdown parsers, Analytics widgets, Chat widgets. A vulnerable package can bypass React’s protections entirely.&lt;/p&gt;

&lt;p&gt;While React offers incredible built-in protection against XSS, security is ultimately a shared responsibility. Bypassing React's guardrails without proper sanitization opens the door to vulnerabilities.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>react</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
