<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Suvechhya Banerjee on Medium]]></title>
        <description><![CDATA[Stories by Suvechhya Banerjee on Medium]]></description>
        <link>https://medium.com/@suvechhyabanerjee92?source=rss-38ed745dfed3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*bX9rmj1mgahtmJqR.jpg</url>
            <title>Stories by Suvechhya Banerjee on Medium</title>
            <link>https://medium.com/@suvechhyabanerjee92?source=rss-38ed745dfed3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 04:08:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suvechhyabanerjee92/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React Doesn’t Prevent XSS — Developers Do]]></title>
            <link>https://medium.com/@suvechhyabanerjee92/react-doesnt-prevent-xss-developers-do-ce3b226778dd?source=rss-38ed745dfed3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce3b226778dd</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[software-security]]></category>
            <dc:creator><![CDATA[Suvechhya Banerjee]]></dc:creator>
            <pubDate>Fri, 19 Jun 2026 16:41:44 GMT</pubDate>
            <atom:updated>2026-06-19T16:41:44.369Z</atom:updated>
            <content:encoded><![CDATA[<p>React has a reputation for being secure against Cross-Site Scripting (XSS), and for good reason. By default, React escapes user-controlled content before rendering it to the DOM.</p><p>However, “React protects against XSS” is only half the story.</p><p>Modern React applications frequently integrate rich text editors, Markdown renderers, CMS content, third-party widgets, analytics tools, and AI-generated content. In these situations, developers often bypass React’s built-in protections and unintentionally reintroduce XSS vulnerabilities.</p><p>In this article, we’ll explore how XSS works in React, where the real risks lie today, and how to defend against them.</p><h3>Why React Is Safer by Default</h3><p>Consider the following component:</p><pre>function Profile({ username }) {<br>  return &lt;div&gt;{username}&lt;/div&gt;;<br>}</pre><p>If an attacker provides:</p><pre>&lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt;</pre><p>React automatically escapes the content before inserting it into the DOM.</p><p>The browser receives something equivalent to:</p><pre>&lt;div&gt;&amp;lt;script&amp;gt;alert(&#39;XSS&#39;)&amp;lt;/script&amp;gt;&lt;/div&gt;</pre><p>The script is displayed as text rather than executed.</p><p>This built-in escaping eliminates many traditional reflected and stored XSS attacks.</p><h3>The Moment You Lose React’s Protection</h3><p>Problems begin when developers intentionally render raw HTML.</p><p>React provides:</p><pre>&lt;div dangerouslySetInnerHTML={{ __html: content }} /&gt;</pre><p>The name is not accidental.</p><p>Imagine a blog platform where article content is stored in a database:</p><pre>&lt;div dangerouslySetInnerHTML={{ __html: article.content }} /&gt;</pre><p>If an attacker manages to store:</p><pre>&lt;img src=x onerror=&quot;alert(&#39;XSS&#39;)&quot; /&gt;</pre><p>the browser executes the malicious JavaScript.</p><p>At this point React is no longer escaping anything — it is trusting the HTML completely.</p><h3>Real-World Example: CMS and Rich Text Editors</h3><p>A common architecture looks like this:</p><pre>Editor → Database → API → React Frontend</pre><p>Teams often assume that content coming from their own backend is safe.</p><p>But content can originate from:</p><ul><li>User-generated posts</li><li>Admin panels</li><li>Imported documents</li><li>Third-party integrations</li><li>AI-generated content</li></ul><p>If malicious HTML enters the system anywhere along this pipeline, it can eventually reach:</p><pre>dangerouslySetInnerHTML</pre><p>and become executable code.</p><h3>Markdown Isn’t Automatically Safe</h3><p>Many developers switch to Markdown thinking it eliminates XSS.</p><p>Consider:</p><pre># Hello</pre><pre>&lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt;</pre><p>Whether this becomes dangerous depends entirely on the Markdown renderer configuration.</p><p>Some libraries allow embedded HTML by default.</p><p>For example:</p><pre>&lt;ReactMarkdown&gt;{content}&lt;/ReactMarkdown&gt;</pre><p>may be safe depending on configuration, but adding plugins that support raw HTML can introduce risk.</p><p>Always review:</p><ul><li>HTML rendering support</li><li>Plugin behavior</li><li>Sanitization strategy</li></ul><p>Never assume Markdown equals security.</p><h3>The Hidden Danger of Third-Party Components</h3><p>Modern React applications rely heavily on external packages.</p><p>Examples include:</p><ul><li>Chat widgets</li><li>Analytics dashboards</li><li>WYSIWYG editors</li><li>Visualization libraries</li><li>Marketing integrations</li></ul><p>Some libraries internally perform:</p><pre>element.innerHTML = data;</pre><p>or similar DOM operations.</p><p>Even if your React code is secure, a vulnerable dependency can create an XSS sink.</p><p>Security reviews should include dependency audits, not just application code.</p><h3>DOM-Based XSS in React</h3><p>Not all XSS originates from backend data.</p><p>Client-side logic can introduce DOM-based XSS.</p><p>Example:</p><pre>const search = new URLSearchParams(window.location.search);<br>const query = search.get(&quot;q&quot;);</pre><p>A developer later writes:</p><pre>document.getElementById(&quot;results&quot;).innerHTML = query;</pre><p>An attacker can craft:</p><pre>https://example.com?q=&lt;img src=x onerror=alert(1)&gt;</pre><p>The attack executes entirely in the browser.</p><p>React applications are not immune to DOM-based XSS simply because they use React.</p><h3>Modern Threat: AI-Generated Content</h3><p>This is becoming increasingly relevant.</p><p>Applications now render:</p><ul><li>AI-generated blog posts</li><li>Chat responses</li><li>User prompts</li><li>Knowledge-base articles</li></ul><p>Developers often trust AI output because it originates from their own system.</p><p>But if user input influences the generated content, malicious HTML can be produced and rendered.</p><p>For example:</p><pre>&lt;div dangerouslySetInnerHTML={{ __html: aiResponse }} /&gt;</pre><p>Without sanitization, AI-generated content can become an attack vector.</p><p>Treat AI output as untrusted input.</p><h3>Defending against XSS in React</h3><h3>1. Avoid dangerouslySetInnerHTML whenever possible</h3><p>Prefer:</p><pre>&lt;div&gt;{content}&lt;/div&gt;</pre><p>instead of:</p><pre>&lt;div dangerouslySetInnerHTML={{ __html: content }} /&gt;</pre><h3>2. Sanitize HTML Before Rendering</h3><p>A common approach uses DOMPurify:</p><pre>import DOMPurify from &#39;dompurify&#39;;</pre><pre>const clean = DOMPurify.sanitize(content);</pre><p>Then:</p><pre>&lt;div dangerouslySetInnerHTML={{ __html: clean }} /&gt;</pre><h3>3. Implement Content Security Policy (CSP)</h3><p>A strong CSP can significantly reduce the impact of XSS attacks.</p><p>Example:</p><pre>Content-Security-Policy:<br>default-src &#39;self&#39;;<br>script-src &#39;self&#39;;<br>object-src &#39;none&#39;;</pre><p>CSP should be considered a second layer of defense, not a replacement for sanitization.</p><h3>4. Audit Third-Party Dependencies</h3><p>Review packages that:</p><ul><li>Render HTML</li><li>Parse Markdown</li><li>Manipulate the DOM</li><li>Inject scripts</li></ul><p>The weakest dependency can become your application’s XSS entry point.</p><h3>5. Treat Every External Source as Untrusted</h3><p>This includes:</p><ul><li>APIs</li><li>Databases</li><li>User input</li><li>CMS content</li><li>AI output</li><li>Third-party integrations</li></ul><p>Trust boundaries should be explicit and documented.</p><h3>Final Thoughts</h3><p>React dramatically reduces the likelihood of traditional XSS vulnerabilities through automatic escaping. But modern applications frequently bypass those protections through raw HTML rendering, third-party libraries, Markdown processing, and AI-generated content.</p><p>The key lesson is simple:</p><p><strong>React protects text. It does not protect HTML you choose to trust.</strong></p><p>The most dangerous XSS vulnerabilities in modern React applications appear precisely where developers assume React is handling security for them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce3b226778dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your GraphQL API is slower than you think — Here’s how I fixed mine using DataLoaders]]></title>
            <link>https://medium.com/@suvechhyabanerjee92/your-graphql-api-is-slower-than-you-think-heres-how-i-fixed-mine-using-dataloaders-c28bd0e1c29f?source=rss-38ed745dfed3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c28bd0e1c29f</guid>
            <dc:creator><![CDATA[Suvechhya Banerjee]]></dc:creator>
            <pubDate>Wed, 19 Nov 2025 12:26:43 GMT</pubDate>
            <atom:updated>2025-11-19T12:26:43.808Z</atom:updated>
            <content:encoded><![CDATA[<h3>Your GraphQL API is slower than you think — here’s how I fixed mine using DataLoaders</h3><p>GraphQL is a fairly simple framework that helps make life easier for a lot of engineers, but comes with its fair set of challenges. Our application requires real-time data updates for which we use the GraphQL subscriptions using web-sockets to always show the latest data on the screen. Things were going well until our pages started becoming slower and we figured that there were too many DB hits.<br>GraphQL’s power comes from resolving fields independently — but that also means a single query can explode into dozens (or hundreds) of database round-trips if you’re not careful. And yes, like many teams, we hit the classic <strong>N+1 query problem</strong>.<br>Thanks, to DataLoaders, we were able to optimize our solution and in this article I will explain how!</p><h3><strong>The N+1 Problem</strong></h3><p>If the client requested something like</p><pre><br>{<br> employees {<br>   id<br>   name<br>   department {<br>     name<br>   }<br> }<br>}</pre><p>The resolver would look like:</p><pre>const resolvers = {<br>  Query: {<br>    employees: () =&gt; prisma.employee.findMany(),<br>  },<br>  Employee: {<br>    department: (parent) =&gt; prisma.department.findUnique({<br>      where: { id: parent.departmentId },<br>    })<br>  }<br>};</pre><p>If the system returns as many as a 100 employees, we end up running:</p><ol><li>1 query to fetch all 100 employees</li></ol><p>2. 100 queries to fetch their respective department details</p><p>For nested and deeply joined schemas, the latency started creeping up and this problem is popularly known as the N+1 problem.</p><h3>The Solution: Introducing DataLoaders</h3><p>DataLoader batches and caches requests. Instead of firing 100 queries to fetch the department details for the 100 employees separately, it collects all the request IDs and combines it into one query like this:</p><pre>SELECT * FROM department WHERE id IN (...)</pre><h3>Implementation</h3><ol><li>Creating the dataLoader:</li></ol><pre>import DataLoader from &#39;dataloader&#39;;<br>import { prisma } from &#39;../prisma&#39;;<br><br>export const departmentLoader = new DataLoader(async (ids: readonly string[]) =&gt; {<br>  const departments = await prisma.department.findMany({<br>    where: { id: { in: ids as string[] } }<br>  });<br><br>  const departmentMap = new Map(<br>    departments.map((dept) =&gt; [dept.id, dept])<br>  );<br><br>  return ids.map((id) =&gt; departmentMap.get(id));<br>});</pre><p>This will batch all requests for department during a single GraphQL request.</p><p>2. Injecting the dataLoader into the context:</p><pre>import { departmentLoader } from &#39;./loaders/departmentLoader&#39;;<br><br>const server = new ApolloServer({<br>  schema,<br>  context: async () =&gt; ({<br>    loaders: {<br>      department: departmentLoader<br>    }<br>  })<br>});</pre><p>Note: In case of subscriptions, the loaders need to be injected into the context of the web socket server.</p><p>3. Update the resolver to use it</p><pre>Employee: {<br>  department: (parent, _, { loaders }) =&gt;<br>    loaders.department.load(parent.departmentId)<br>}</pre><p>Now we can get the same set of results in:</p><ol><li>1 query to get the details of the 100 employees</li><li>1 query to get the details of their respective departments</li></ol><h3>Things to keep in mind</h3><ol><li><strong>DataLoaders are not a replacement of good old joins</strong>: SQL joins or prisma includes might still be required to join tables based on complex business requirements. Its a better practice to separate the core logic from the enrichments. The core logic can be accomplished through SQL joins while the enrichments could be offloaded to the dataloader through the resolvers.</li><li><strong>Create Loader per entity not per query</strong>: Avoid writing “ad-hoc” specialized loaders. Keeps it predictable. For eg EmployeeLoader caters to employee enrichments throughout the application.</li><li><strong>Always match ordering in return:</strong> DataLoader requires returning results in the same order as input keys. Using Map ensures this is easy.</li><li><strong>Avoid Recreating Loaders Per Field</strong>: Loaders should be created once per <strong>request</strong>, not per resolver call. This avoids memory leaks + multiplies batching gains.</li></ol><h3>Conclusion</h3><p>GraphQL is powerful, but without thoughtful backend architecture, it can easily become inefficient. DataLoader fixed one of the biggest performance issues we faced — the N+1 problem — and improved both <strong>latency</strong> and <strong>scalability</strong> of our API.</p><p>If your GraphQL API is slowing down as your schema grows, introducing DataLoaders is one of the highest-impact, lowest-effort optimizations you can make.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c28bd0e1c29f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Watch an object for changes in Vanilla JavaScript]]></title>
            <link>https://medium.com/@suvechhyabanerjee92/watch-an-object-for-changes-in-vanilla-javascript-a5f1322a4ca5?source=rss-38ed745dfed3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5f1322a4ca5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[observe]]></category>
            <category><![CDATA[polling]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[watches]]></category>
            <dc:creator><![CDATA[Suvechhya Banerjee]]></dc:creator>
            <pubDate>Tue, 07 Apr 2020 10:53:15 GMT</pubDate>
            <atom:updated>2020-04-07T10:53:15.522Z</atom:updated>
            <content:encoded><![CDATA[<p>A Javascript object often needs to be watched for changes. Depending on such changes we might be looking to fire certain events. Sometimes, we would need to observe an object for debugging purpose as well.</p><p>Any change to an object that is not caused by a DOM event cannot be caught by any event listener. Hence, there needs to be a way to observe an object for changes, be able to access the changed values, and fire events based on any such change.</p><p>Over the period of evolution of Javascript, there has been many ways by which the above can be achieved. In this article we will be discussing some of the most popular ways of watching an object over the times. Some of these functions have been deprecated over time while some of them are still used.</p><p><strong>Method 1: Polling</strong></p><p>The first and most crude way of watching a Javascript object, or any variable is by polling. Javascript offers the functions setInterval and setTimeout that can be used to check the values of any number of variables. However, in order for the watch to become accurate, the polling needs to happen very frequently, ie ideally every millisecond or every 10ms. Running a piece of code that frequently is extremely expensive in terms of compiler cost, and hence polling is hardly ever used to watch a variable. Polling however, can be used only in case that we know that the value of the variable will change at regular and big intervals, say every minute.</p><pre>const obj = {</pre><pre>   foo: “bar”</pre><pre>};</pre><pre>function repeatChecking(oldValue) {</pre><pre>  if(oldValue) {</pre><pre>    setInterval(() =&gt; {</pre><pre>     if(obj.foo !== oldValue) {</pre><pre>      console.log(`Value of ${oldValue} to ${obj.foo}`);</pre><pre>      oldValue = obj.foo;</pre><pre>      }</pre><pre>    }, 10);</pre><pre>  }</pre><pre>}</pre><pre>repeatChecking(obj.foo);</pre><pre>obj.foo = “I have changed.”;</pre><pre>setTimeout(()=&gt; {</pre><pre>  obj.foo = “I have changed again.”;</pre><pre>}, 1000);</pre><p>In order to clear the setInterval, assign it to a variable and clear the interval using clearInterval() function.</p><p><strong>Method 2: Object.prototype.watch()</strong></p><p>The watch function watches any property of an object for changes. This also includes the first assignment of value to the property.</p><p>The watch function includes a handler which has access to the old value and the new value of the watched property of the object.</p><pre>obj.watch(“foo”, function (oldValue, newValue) {</pre><pre>console.log(`Value of foo changed from ${oldValue} to ${newValue}`);</pre><pre>});</pre><p>If the given property, on which the watcher is set, is deleted, the watch doesn’t disappear, rather it remains intact. If the property is recreated in the future, the watch continues functioning in the same way. In order to remove the watcher, one has to call the unwatch() function.</p><pre>obj.watch(“foo”, function (oldValue, newValue) {</pre><pre>console.log(`Value of foo changed from ${oldValue} to ${newValue}`);</pre><pre>});</pre><pre>obj.foo = “I have changed.”;</pre><pre>obj.foo = “I have changed again.”;</pre><pre>delete obj.foo;</pre><pre>obj.foo = “I am back from dead!”;</pre><pre>obj.unwatch(‘foo’);</pre><pre>obj.foo = “Finally, I am no one.”</pre><p>The watch function is only supported on Firefox browsers, and have been currently deprecated there as well. It was never advisable to use the watch function except for debugging purposes alone.</p><p><strong>Method 3: Object.observe()</strong></p><p>This function was also used to asynchronously observe the changes occurring in an object. In this function, the handler function can filter out the types of changes it is looking to observe. The handler also gets access to information like what type of change has occurred and not just the changed value.</p><p>For eg.</p><pre>var obj = {<br>  foo: &quot;Initial Value&quot;<br>};<br><br>Object.observe(obj, function(changes) {<br>  console.log(changes);<br>});</pre><p>On adding a new property to the object, updating an existing property and deleting a property:</p><pre>obj.newProp = &quot;I am new Property&quot;;<br>// [{name: &#39;newProp&#39;, object: &lt;obj&gt;, type: &#39;add&#39;}]</pre><pre>obj.foo = &#39;New Value of Foo&#39;;<br>// [{name: &#39;foo&#39;, object: &lt;obj&gt;, type: &#39;update&#39;, oldValue: &#39;Initial Value&#39;}]</pre><pre>delete obj.newProp;<br>// [{name: &#39;newProp&#39;, object: &lt;obj&gt;, type: &#39;delete&#39;, oldValue: &#39;I am new Property&#39;}]</pre><p>Object.observe() function, too, has been deprecated and removed from all current browsers.</p><p><strong>Method 4: Register a custom listener to the object utilizing the getter and setter methods.</strong></p><p>If we define our object to set value to properties through setters, then we can also create a listener as one of the properties. A custom function can be assigned as the listener defined within the object. This custom listener can be utilized to listen to value changes to the properties of the object.</p><pre>const obj = {</pre><pre>  fooValue: “bar”,</pre><pre>  get foo() {</pre><pre>    return this.fooValue;</pre><pre>  },</pre><pre>  set foo(val) {</pre><pre>    this.fooValue = val;</pre><pre>    this.fooListener(val);</pre><pre>  },</pre><pre>  fooListener: function (val) {},</pre><pre>  registerNewListener: function (externalListenerFunction) {</pre><pre>    this.fooListener = externalListenerFunction;</pre><pre>  },</pre><pre>};</pre><pre>obj.registerNewListener((val) =&gt; console.log(`New Value: ${val}`));</pre><p>This listener successfully listens to changes happening to the property, because the listener is triggered from the setter function, every time a new value is assigned to the given property. However, if we use delete to delete the property of the object, it deleted the getter and setter as well. So, if the property is re-added, the listener cannot listen to the new property created.</p><pre>obj.foo = “I have changed.”;</pre><pre>obj.foo = “I have changed again.”;</pre><pre>delete obj.foo;</pre><pre>obj.foo = “I am back from dead!”;</pre><p>The output comes something like this:</p><pre>New Value: I have changed.<br>New Value: I have changed again.<br></pre><p><strong>Method 5: Using the Proxy Object</strong></p><p>A Proxy object is used to define custom behavior on fundamental operations. A Proxy virtualizes an object and customizes its fundamental methods which includes the getters and setters. By using a proxy, we can make sure that we do not make any changes to the core structure of the original object, yet customize its method to trigger a custom event every time a change occurs.</p><pre>const obj = {</pre><pre>  foo: “bar”,</pre><pre>};</pre><pre>const objProxy = new Proxy(obj, {</pre><pre>  set: function (target, key, value) {</pre><pre>   console.log(`${key} set from ${obj.foo} to ${value}`);</pre><pre>   target[key] = value;</pre><pre>   return true;</pre><pre> },</pre><pre>});</pre><p>A proxy, however, has varied applications and can be used for many things in Javascript. For a more detailed study on proxies, visit: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5f1322a4ca5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>