<?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 Carlos Ruana on Medium]]></title>
        <description><![CDATA[Stories by Carlos Ruana on Medium]]></description>
        <link>https://medium.com/@carlosruana?source=rss-ccb1bed74a57------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*SGL6JpfTuk1d3-SF9rY2dQ.jpeg</url>
            <title>Stories by Carlos Ruana on Medium</title>
            <link>https://medium.com/@carlosruana?source=rss-ccb1bed74a57------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:32:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@carlosruana/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[Reduce boilerplate with Redux Toolkit]]></title>
            <link>https://medium.com/strands-tech-corner/reduce-boilerplate-with-redux-toolkit-d56047455d63?source=rss-ccb1bed74a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/d56047455d63</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Carlos Ruana]]></dc:creator>
            <pubDate>Tue, 10 May 2022 16:00:40 GMT</pubDate>
            <atom:updated>2022-05-10T16:05:17.680Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will try to convince you why using Redux Toolkit library is a <strong>must</strong> if you plan to use Redux or you are already using it.</p><p>This article does <strong>not</strong> discuss whether you should use Redux vs React context or any of the multiple other alternatives available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*DVO5iVIcJnbzmrHvXgeEhQ.png" /></figure><p>TL;DR This is why:</p><ul><li>You will have to write a lot less boilerplate code.</li><li>Writing actions and reducers way more easy.</li><li>Avoid adding many other libraries for immutability, entities and collection management, etc</li></ul><p>The fist thing you need to know about Redux Toolkit is that is a just a wrapper on top of Redux that does not change any of the logic for creating and maintaining you application state. It adds some utilities to make you live much more easy.</p><h3>configureStore</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*PR8Ge_3A2mBeawuy3itiqA.png" /></figure><p>Although it is not the main star feature, configuring the store with Redux Toolkit it is also easier. Those are the main benefits:</p><ul><li>Automatically adds redux-thunk middleware to the store</li><li>Redux DevTools Extension is already turned on</li></ul><h3>createSlice</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*nriHKLMqCOQhN1DVCwsY2w.png" /></figure><p>This is where the magic starts, and now writing Redux logic is all about configuration. Give it a <strong>name</strong>, an <strong>initialState</strong> and your <strong>reducers</strong> logic and Redux Toolkit already provides you with:</p><ul><li>createSlice uses the <strong>key</strong> of the reducers object (on the above example: <em>increment</em>, <em>decrement</em>, <em>incrementbyAmount</em>) to automatically generate <strong>action creators</strong> and <strong>action types</strong> with the same string name, which you are ready to export for dispatching from you application, so no more manually creating and maintaining constants on other files or writing complex action creators.</li><li>Those reducers are passed to createReducer() which provides immutable logic to update the state.</li></ul><h3>createReducer</h3><p>It provides with some logic to avoid mutating the state by accident (uses Immer library internally) although it allows you to write the code as you were really mutating the state.</p><p>Lets see what that means with an easy example. First <strong>without using</strong> createReducer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*lh5whXNBLisl98cVo_UFyg.png" /></figure><p>And now <strong>using</strong> it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*z0SjPSVXfattJW3Rbxmzrg.png" /></figure><p>Although at first sight it seems anti-pattern assigning the new value directly to any part of the sate (at least it did to me), it is obvious how it avoids the mess of creating a copy of the previous state in a very nested object when you only want to do a single update.</p><p>Once more Redux Toolkit does the work for you and creates a copy of the new state object before merging it into the store.</p><p>In my team to <strong>get rid of Immutable.js</strong> was necessary as the performance benefits it provides were not worth the difficulties using the library API and some of the times we end up converting Immutable objects to regular objects to work with in the views, loosing all the performance benefits anyway. So Immer bundle size is lighter than Immutable one and together with the other Redux toolkit utilities, it provides everything we need. I would recommend using <strong>Immer</strong> with Redux even if you decide not to use Redux Toolkit.</p><h3>createAction</h3><p>Let’s see that one also better with an example on how normally <em>action creator </em>functions are build:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*esuhD88Hcrdp53z3OGX12A.png" /></figure><p>And how we can do it with just one line with Redux Toolkit library:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*JnHSbYZbhBMv0CRlOM5bdQ.png" /></figure><p>There are several things to notice here:</p><ul><li>createAction returns the <strong>action creator</strong> you can export and then dispatch from within your application.</li><li>When you call that action creator with arguments this becomes automatically the <strong>action.payload </strong>object.</li><li>The string you pass to createAction (<em>counter/increment</em> in the example) becomes the <strong>action type</strong> you then can use in your reducer. See example below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*U1m1JENh2xdiOqxapDWFVA.png" /></figure><h3>createAsyncThunk</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*_sNeJpIVo5DKi75GAix73A.png" /></figure><p>Very similar to createAction but for the case of dispatching async actions. Also notice:</p><ul><li>createAsyncThunk returns the <strong>thunk action creator</strong> you can export and then dispatch from within your application.</li><li>First parameter is the Redux <strong>action type</strong>, but in that case the string is not generating any reducer functions automatically as it does not know the details of your implementation. You should implement that instead on the extraReducers functions. In the example you can see the case of <em>fetchUserbyId.fullfilled</em> but createAsyncThunk will also generate <em>fetchUserbyId.pending and fetchUserbyId.rejected </em><strong><em>action creators</em></strong><em> w</em>here you can add you loading logic or error handling.</li><li>Second parameter is the callback where you implement the <strong>async behavior</strong> (such as doing ajax calls) and should return a Promise.</li></ul><h3><strong>createEntityAdapter</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*q4RM9SrhsHPxB40-3FxdMw.png" /></figure><p>I really like that one, you can normalize (efficiently way of organizing data) your data entities, also with just one line.</p><p>On the example above you just need selectId if you collection of data does not have an “id” attribute or is named different, such as “bookId”. Also you can skip the sortComparer if the collection to normalize has already the order you need.</p><p>This is the most important functionality it provides:</p><ul><li>It creates an easy to access structure for each collection { ids: [], entities: {} }. Very similar to what <strong>normalizr</strong> library provides. And although you can still use normalizer with createEntityAdapter our team decided the library was no longer needed for the needs of our applications.</li><li>Provides with plenty of <strong>CRUD functions</strong> to update your collection within your reducers. Take a look at the above example how easy is to add a new book to the collection by just using <em>booksAdapter.addOne()</em> or replace a full collection with <em>booksAdpater.setAll(). </em>We use it all the time on the <em>fullfilled</em> reducers when doing ajax calls, to update the state with its set of generated reducer functions for adding, updating, and removing entity instances from an entity state object.</li><li>More magic still!!! It contains a <strong>getSelectors() </strong>function which provides a set of very useful selectors (selectIds, selectEntities, selectAll, selectTotal, selectById) you can export. Those are the most used ones and Redux Toolkit includes them so you just have import them in your views and use the regular useSelector hook to get and work with your entities.</li></ul><p>If you want to learn more the official site has plenty of nice examples and tutorials:</p><p><a href="https://redux-toolkit.js.org/tutorials/overview#redux-essentials-a-real-world-example">https://redux-toolkit.js.org/tutorials/overview#redux-essentials-a-real-world-example</a></p><h3>Conclusion</h3><p>This is a glimpse at the Redux Toolkit library. Each of the methods above provide with much more functionality and it includes many other utilities, but hopefully you got an idea of how it helps fast development on your Redux Store by reducing the common boilerplate and making all the required steps much easier.</p><p>Our team reduced so much the boilerplate that rather than having several files for our state management (actions, reducers, schemas, selectors) we can fit each of our reducers now into a single (not too long) <strong>slice</strong> file.</p><p>It is a light library and the learning curve is very low if you already know Redux. Even if people joining your team knows nothing about Redux they will learn faster to create a store with Redux Toolkit rather that without it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d56047455d63" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strands-tech-corner/reduce-boilerplate-with-redux-toolkit-d56047455d63">Reduce boilerplate with Redux Toolkit</a> was originally published in <a href="https://medium.com/strands-tech-corner">Strands Tech Corner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend Application Security: How We Protect Sensitive User Data]]></title>
            <link>https://medium.com/strands-tech-corner/frontend-application-security-b1ea9999cd02?source=rss-ccb1bed74a57------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1ea9999cd02</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[owasp]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Carlos Ruana]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 09:25:18 GMT</pubDate>
            <atom:updated>2020-01-09T09:47:54.229Z</atom:updated>
            <content:encoded><![CDATA[<p>This article outlines <a href="https://medium.com/u/7224dddc5f8e">Strands</a>’ web application security practices from a frontend point of view. Given that most risks are controlled by our solid restful API, the aim here is not to give an in-depth description of the <a href="https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project">top 10 OWASP security risks</a>, but to explain how we deal with some of them from our frontend.</p><figure><img alt="Image shows a wasp, which actually is the logo of the OWASP organization." src="https://cdn-images-1.medium.com/max/438/1*vOURjp2Y1Ec-D7nORA_YGg.png" /></figure><h3>Avoiding <strong>Injection</strong> Attacks</h3><p>Injection attacks, particularly SQL Injection and XSS (Cross-site-scripting) are currently considered the most dangerous vulnerabilities when developing web applications. Working with frameworks such as <a href="https://angularjs.org/">Angular</a>, <a href="https://reactjs.org/">React</a>, <a href="https://vuejs.org/">Vue.js</a> or <a href="https://rubyonrails.org/">Ruby on Rails</a> helps frontend developers dealwith most of the injection risks, as all of them implement default escaping mechanisms to avoid attacks. However, you should understand the particularities of each of them to be fully covered.</p><p><a href="https://reactjs.org/docs/introducing-jsx.html#jsx-prevents-injection-attacks">React JSX</a> escapes variables before adding them to the DOM, meaning all values are converted to String before being rendered, avoiding malicious users injecting code.</p><p>Despite this, you should have some special cases in mind:</p><ul><li>React ONLY escapes children elements as texts but not props. As a result, code could end up placed in some HTML properties, where malicious code could be executed. Most of these cases occur when handling users&#39; data <strong>from input fields or from the URL</strong>, when receiving <strong>users’ input data already stored in the DB</strong>, or even when rendering components <strong>from a JSON or XML markup</strong> that has not been sanitized before parsing it to JS. The solution when receiving untrusted data from those channels is manual sanitization (that is, escaping control characters) before being placed on those props/attributes, also in script tags, URL locations, event handlers or CSS style tags.</li></ul><p>You definitely want to avoid these examples without proper sanitation:</p><pre>// Do not use not trusted data on href</pre><pre>const urlParam = window.location.search.substring(1);</pre><pre>function HelloWorldComponent() {<br>  return &lt;a href={urlParams}&gt;Click me!&lt;/div&gt;;<br>}</pre><p>User could change your URL from:</p><p>http://myurl/listdogs?page=1</p><p>to some random script which will be executed:</p><p>http://myurl/listdogs?javascript:alert(1);</p><pre>// Do not use not trusted data on style tags you can also end up with some random script</pre><pre>function HelloWorldComponent() {<br>  return &lt;a style=&quot;-o-link:&#39;javascript:alert(1)&#39;;&quot;&gt;Hi!&lt;/a&gt;;<br>}</pre><ul><li>The use of <a href="https://www.w3schools.com/jsref/jsref_eval.asp">eval</a> or <a href="https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml">dangerouslySetInnerHTML</a> could also be potentially risky when applied with users’ input data or a compromised DB/API. Employing these methods is strongly discouraged and that’s why we have rules set in our <a href="https://www.sonarqube.org/">Sonar</a> configuration to prevent developers from using them, except on very rare cases where its application is justified. Instead of eval you should use JSON.toJSON() and JSON.parse() and, if you really need to use dangerouslySetInnerHTML, you should escape control characters manually.</li></ul><p>If you are using some of the previous examples, there are several libraries out there that will sanitize your texts for you. Using your own regular expressions for sanitizing can be quite dangerous if you are not really experienced with XSS attacks.</p><p><a href="https://github.com/cure53/DOMPurify">GitHub - cure53/DOMPurify: DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo:</a></p><p>Also, if you are not using React DOM to escape values into your JSX or any other similar library, you may want to follow the steps on those cheat sheets to avoid vulnerabilities:</p><ul><li><a href="https://cheatsheetseries.owasp.org/cheatsheets/DOM_based_XSS_Prevention_Cheat_Sheet.html">DOM based XSS Prevention - OWASP Cheat Sheet Series</a></li><li><a href="https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html">Cross Site Scripting Prevention - OWASP Cheat Sheet Series</a></li></ul><h3>Third-party libraries risks</h3><p>Even when you think you have covered all the risks in your application, you can be surprised to discover a vulnerability in some code your team has not even written. Although making sure that the external libraries you are using are 100% free of risk is close to impossible, there are several tricks you can do to mitigate that chance.</p><p>Using open versions of libraries that your developers will be pulling every time they do npm/yarn install is not a good idea, not only because it is unclear which bugs you are also importing each time, but for the risk it implies. Vulnerabilities on libraries with lots of downloads are often quickly fixed, but those libraries are also the most targeted by hackers. It is always better to choose a closed version of those libraries and check regularly for vulnerabilities and fixes.</p><p>Even a library initially free of vulnerabilities can be hacked (updated o replaced) with a version with intentionally malicious changed code. The best way to mitigate this is by having your own npm repository (acting as a cache) and enabling a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP">Content Security Policy (CSP)</a> to avoid importing compromised files from outside your company. In fact, good management of your CSP can avoid multiple XSS attacks.</p><p><a href="https://www.html5rocks.com/en/tutorials/security/content-security-policy/">Content Security Policy | Web Fundamentals | Google Developers</a></p><p>Also, if you are using Jenkins Pipelines or any other CI tool, you may set up some automatic scans on those libraries using <a href="https://docs.npmjs.com/cli/audit">npm/yarn audit</a> and report those vulnerabilities.</p><p><a href="https://www.npmjs.com/package/yarn-audit-html">yarn-audit-html</a></p><h3>Preventing sensitive data exposure</h3><p>In our money-management applications, we often handle very sensitive user data. Our backend team deals with mechanisms such as password encryption and session management,<em> </em>but most requests revolve around how personal data is managed in the frontend. The best way of avoiding exposing this data is to never store it in the frontend. That is why we totally discourage using localStorage and sessionStorage in our application (other than for storing “silly” data, if needed.)</p><p>HTML5 Web Storage has no data protection and is considered unsafe as hackers could use XSS attacks to read from it.</p><p>Additionally, logging out users after their session has expired might be a good idea to clear all data stored in the DOM, always depending on the level of importance your application gives to your users’ data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ITdIrRHAclF41DkDZcI2TA.jpeg" /></figure><h3>Broken access control</h3><p>Authentication, authorization and business logic controls should never be implemented on the client-side functionality, that is why ––for better user experience–– we only implement routing in React.</p><p>This relates to the previous topic of sensitive-data exposure. By limiting backend access, we avoid users without authorization reaching sensitive data.</p><p>Given the fact that is possible that different users might access our applications through the same computer, we should avoid caching any data in the browser by adding HTTP Cache-control headers and meta tags.</p><h3>Security misconfiguration</h3><p>In the frontend, a bad configuration when creating a production version of an application usually does not create a vulnerability. However, this can lead to code not being completely abstract or with a wrong source map, which could help hackers to find your vulnerabilities faster.</p><p>A good idea is having different webpack configurations for development and production, and let automatic processes (as Jenkins CI) create the production build for you.</p><h3>Conclusion</h3><p>Security in Web apps is not a one-time effort, there is a routine that you have to follow while your application in on production.</p><ul><li>Check for new vulnerabilities and follow security organizations such as OWASP and their recommendations.</li><li>Review your third-party inventory regularly and update it if needed.</li><li>Use specialized tools or manually scan your logs for signs of malicious activity.</li><li>Take Pull Request very seriously, check for best practices violation and remind your team of the most dangerous current vulnerabilities.</li><li>Use automatic mechanisms to set Static Code Analysis Rules using a security tool such as <a href="https://www.sonarqube.org/">SonarQube</a>. Even if you have manually checked that your code is 100% bulletproof maybe someone else (not you, of course) will introduce a new vulnerability, probably when you are on holiday and you cannot decline the Pull Request!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1ea9999cd02" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strands-tech-corner/frontend-application-security-b1ea9999cd02">Frontend Application Security: How We Protect Sensitive User Data</a> was originally published in <a href="https://medium.com/strands-tech-corner">Strands Tech Corner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>